Feeds

Author

Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough
Oct 05 2021
Oct 05

Pulling data from different sources to your Drupal CMS is what migration is all about. Your migration source can be anything – a database, another CMS, CSV, XML files. Drupal always gives you the flexibility to migrate data from anywhere into the CMS. We have written extensively on Drupal migrations before like migrating from a database source, migrating multilingual content from CSV, from an SQL source, a complete how-to-guide to migrations and more! If you are looking for a guide to migrating data from XML files to Drupal 8 or Drupal 9, you have arrived at the right place as that is what we are going to discuss about here!

If you’re looking to import external feeds to your Drupal 9 website using the Drupal Feeds module, check out this article.

XML to Drupal Migration

Drupal 8/9 Migration Modules

Here, we will be using the whole set of Drupal migrate modules

After installing these modules, you will need to create a custom module where you will write the script for migration. So first, create a custom module and then create an info.yml which will include the module’s details. Next, enable the module.

name: test migration
type: module
description: Migrating data from the csv files.
core_version_requirement: ^8 || ^9
package: Migration
dependencies:
 - drupal:migrate_source_csv
 - drupal:migrate_plus
 - drupal:migrate_tools
config_devel:
 install:
   - migrate_plus.migration_group.test_migration
   - migrate_plus.migration.test_migration_sessions
   - migrate_plus.migration.test_migration_paper
   - migrate_plus.migration.test_migration_user

Once the info.yml file is created, you need to create a migration group for this migration. You will need to create this migration group in the path: test_migration> config > install. These details are needed while running the migration:

id: test_migration
label: test Migration
description: Migrating xml data 

After creating the migration group, install this group in your info.yml file.

config_devel:
 install:
   - migrate_plus.migration_group.test_migration 

Now, you need to write a migration script for the content type. This script should be inside config > install and file name should be migrate_plus.migration.test_migration_paper.yml

id: test_migration_paper
label: 'Migrate Paper data from the xml file'
migration_group: test_migration
source:
 plugin: url
 # Full path to the file.
 data_fetcher_plugin: file
 data_parser_plugin: xml
 urls: private://xml/session.xml
 item_selector: /program/session/papers/paper
 fields:
   - name: title
     lable: 'Paper title'
     selector: papertitle
   - name: abstract
     lable: 'Paper abstract'
     selector: abstract
   - name: first_name
     label: 'Author first name'
     selector: authors/author/name/givenname
   - name: last_name
     label: 'Author last name'
     selector: authors/author/name/surname
   - name: paper_id
     label: 'Paper identifier'
     selector: paperid
   - name: session_id
     label: 'Session identifier'
     selector: sessionid
   - name: start_time
     label: 'Paper presentation start time'
     selector: starttime
   - name: end_time
     label: 'Paper presentation end time'
     selector: endtime
   - name: author_name
     label: 'Author name'
     selector: authors/author/name/fullname
   - name: session
     lable: 'Session name'
     selector: session
 ids:
   session_id:
     type: string
process:
 # Adding the mapping between the fields and the csv columns.
 title:
   - plugin: skip_on_empty
     method: process
     source: title
 field_abstract/value: abstract
 field_abstract/format:
   plugin: default_value
   default_value: "full_html"
 field_presentation_timing/value:
   plugin: format_date
   from_format: 'Y-m-d\TH:i:s'
   to_format: 'Y-m-d\TH:i:s'
   source: start_time
 field_presentation_timing/end_value:
   plugin: format_date
   from_format: 'Y-m-d\TH:i:s'
   to_format: 'Y-m-d\TH:i:s'
   source: end_time
 field_paper_identifier: paper_id
 field_session_identifier: session_id
 field_author:
   - plugin: skip_on_empty
     method: process
     source: author_name
   - plugin: paper_user_migration_import_process
     no_stub: true
 field_session:
   - plugin: skip_on_empty
     method: process
     source: session
   - plugin: node_migration_import_process
     no_stub: true
destination:
 plugin: 'entity:node'
 default_bundle: paper
migration_dependencies:
 required: { }
dependencies: { }
Ad Label
  • id: Will be unique for each yaml file and displayed in the migration list.
  • label: Will contain description for the migration.
  • migration_group: This is the main group that contains all the migrations.
  • source: Will contains all source details for this migration.
  • urls: Will contain the file for migration. In the above code, source is placed inside the private directory.
  • item_selector: Item selector is the path from which the entire set of data is taken. Basically inside this tag there should be one set of data.
  • fields: Here we are assigning tag values to some variables.
  • name: Which gives variable names.
  • label: A short description.
  • selector: In which we are telling which tag value should be assigned to the variable.
  • ids: Which should be unique for each content.
  • process: In which we are mapping variable and field machine names.
  • destination: In which we are mentioning the entity name to which data should be migrated.

Based on your data you can now write plugins for migration as well. The above code plugin is written for the field_author field.

After this go to Structure, there you will see Migration - click on that. You can now see all the migration groups.

Add Migration Group

Click on List migration. There you can see the list of migration yaml we have created.

Paper Data

Click on the Execute button. You can see the migrating options.

Import Operation

Here you can run any option you want:

  • Import: This will migrate the data.
  • Rollback: Will roll back all migrated data.
  • Stop: Will stop the migration in the middle of the process.
  • Reset: Will change the status to an idle state.

You can also migrate the contents through the terminal with these drush commands.

  • drush ms - Migration status
  • drush mim - Migration import
  • drush mr - Migration rollback
  • drush mrs - To make migration status idle.
Mar 23 2021
Mar 23

There maybe times when you do not want certain pages of your website to look like the rest. You might want a different theme, a unique menu or a distinct layout altogether. That’s when you will want to create Micro-sites. Micro-sites are small sites that can be subsets of your main site or have a completely different domain/subdomain. Mainly used for discrete marketing campaigns, events or products, micro-site marketing is a great tool to promote focused campaigns.

With Drupal 8 (and 9) you can build micro-sites within your existing setup using the Group module. You can have a separate set of users, permissions, and pages within that setup. Let’s learn more about this amazing module and how you can create micro-sites using the Group module.

Micro Sites in Drupal

Creating micro-sites using the Group module for Drupal

The latest version of the Group module was released in Drupal 8.8 and is compatible with Drupal 9 as well. It enables you to build discrete collections of content and users on your Drupal site. You can also setup access control for these collections. Group module is not only useful to create micro-sites but can be used whenever a site needs to create content that needs to be accessed only by certain user groups.

Installing the Group Module

Follow the below steps to install the Group module for Drupal 8 (or 9).

Step 1: Use this command to install the module

  
composer require 'drupal/group’ 

Step 2: Enable the Group and Group Node module

Working with the module

Once the module is installed you will see Groups in the administrative menu.

Groups

Under Groups, you need to create a Group type for your micro-sites. Group types are basically types of divisions for your website. In our case the group-type is a Micro-site.

Add Group Type

After adding the group type you can add fields to your micro-site. You will see 3 extra tabs in this group type - Content, Roles, Permissions.

Add Field

In the same above image, you can see a content tab where you can add content types to your micro-site (these are content types that we have created in our main site).

Configure Contents

Now, you can also create separate roles for the micro-sites.

Group Roles

After adding a separate role to the micro-site, you can add permissions to that particular role by clicking on Edit permissions. You can set the permissions as per your requirement.

Group Role Permissions

Next, you have a permission tab where you can add permissions to anonymous users and other micro site members. After configuring your group type, you can now add the group to that particular group type.

Group Type Permissions

Now while editing your group you will see many other tabs apart from View, Edit and Delete.

Edit Micro Sites

Now, go to the Members tab where you can add members to the group. These are the members who can perform actions on this particular group. (Note: by default, admin will be a member of the group. You can disable this functionality in the group type configuration.)

Micro Site Member

Go to the Nodes tab to add content to the group.

Micro Site Nodes

All entities: This lists all the nodes and users in that particular group.

Micro Site Entities

Adding menus to Micro-sites

Install Group Content Menu using this command then enable the module.

  
composer require 'drupal/group_content_menu'

After installing this module, you will see Group Content Menu types under Structure. Create a group content menu type for your micro site.

Group Menu Type

Place this menu type in the block layout where you want to display it.

Add Custom Block

Configure the block to display in the micro site.

Configure Block

Now in the group type content tab you will get the Group menu. Install that to display menus in your micro-site.

Group Menu

Now you should be able to see group menu in your groups.

Group Menus

In group menu you need to create a name for the Menu set.

Site Menu

After adding the menu set, you can now add menus.

Add LinkEdit Micro Sites

Now clear your cache and check the group. The menu will be displayed wherever you have placed it in your block layout.

Micro Site Description

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web