Account created on 13 September 2024, 16 days ago
#

Recent comments

Hi,
I want to get the filename for my XML to set the name of the block content based on the file name.
I tried the above solutions. However, it skips the first URL and repeats the last one. Any suggestions how you fixed the issue

namespace Drupal\teamsite_migration\Plugin\migrate_plus\data_parser;

use Drupal\migrate_plus\Plugin\migrate_plus\data_parser\Xml;

/**
 * Obtain XML data for migration.
 *
 * @DataParser(
 *   id = "custom_xml",
 * )
 */
class CustomXML extends Xml {
  
  /**
   * {@inheritdoc}
   */
  protected function fetchNextRow(): void {
    parent::fetchNextRow();

    // Inject file metadata.
    if ($this->valid()) {
      $current_file_url = $this->currentUrl();
      $this->currentItem['active_source_url'] = $current_file_url;
      $filename = basename($current_file_url);
      $this->currentItem['current_filename']= pathinfo($filename, PATHINFO_FILENAME);
    }
  }
}

and using it like below:

source:
  plugin: url_with_active_source_url
  data_fetcher_plugin: file
  data_parser_plugin: custom_xml
  urls:
    - modules/custom/teamsite_migration/data/Accordion/default.xml
    - modules/custom/teamsite_migration/data/Accordion/default-skin-thumbnail.xml
    - modules/custom/teamsite_migration/data/Accordion/default-skin-enhanced.xml
    - modules/custom/teamsite_migration/data/Accordion/default-skin-enhanced-large.xml
  item_selector: /accordion
  
  # defined source fields from XML
  fields:
    - name: title
      label: 'Title'
      selector: 'title'
    - name: description
      label: 'Description'
      selector: 'description'
    - name: disclaimer
      label: 'Disclaimer'
      selector: 'disclaimer'
    - name: accItems
      label: 'Accordion Items'
      selector: 'items'
      
  
  ids:
    title:
      type: string

process:
  type:
    plugin: default_value
    default_value: accordion_block_type

  # Modify the info field to use the filename without extension
  info: current_filename

It was an issue with the field itself. It was set to have just 1 item as a reference to the paragraph.

Did you resolve the issue? I am trying to do the similar migration and facing the same issue.

Production build 0.71.5 2024