Score:1

Fill multi-value field from comma separated values in a field

kr flag

I have data in xml which I want to import into drupal. Which works fine. But one field in the xml is filled with a comma separated list of terms. There is a target field in drupal which is a multi-valued field. I do not need those as a taxonomy, just as multi-value for solr search. I just want to expand the one,fourty,flower,... values to fill the multiple-value field.

It absolutely will not work. Any help?

Here is the latest iteration (I tried a lot in the last two days) which fails spectacularly with an error like so:

Error: Unsupported operand types in /var/www/dev.diercke.com/web/core/modules/migrate/src/Plugin/migrate/process/SubProcess.php on line 206 #0 /var/www/dev.diercke.com/web/core/modules/migrate/src/MigrateExecutable.php(399): Drupal\migrate\Plugin\migrate\process\SubProcess->transform(Array, Object(Drupal\migrate_tools\MigrateExecutable), Object(Drupal\migrate\Row), 'field_stichwort...')
#1 /var/www/dev.diercke.com/web/core/modules/migrate/src/MigrateExecutable.php(205): Drupal\migrate\MigrateExecutable->processRow(Object(Drupal\migrate\Row))
#2 /var/www/dev.diercke.com/vendor/drush/drush/includes/drush.inc(206): Drupal\migrate\MigrateExecutable->import()
#3 /var/www/dev.diercke.com/vendor/drush/drush/includes/drush.inc(197): drush_call_user_func_array(Array, Array)
#4 /var/www/dev.diercke.com/web/modules/contrib/migrate_tools/src/Commands/MigrateToolsCommands.php(958): drush_op(Array)
#5 [internal function]: Drupal\migrate_tools\Commands\MigrateToolsCommands->executeMigration(Object(Drupal\migrate\Plugin\Migration), 'karte', Array)
#6 /var/www/dev.diercke.com/web/modules/contrib/migrate_tools/src/Commands/MigrateToolsCommands.php(418): array_walk(Array, Array, Array)
#7 [internal function]: Drupal\migrate_tools\Commands\MigrateToolsCommands->import('karte', Array)
#8 /var/www/dev.diercke.com/vendor/consolidation/annotated-command/src/CommandProcessor.php(257): call_user_func_array(Array, Array)
#9 /var/www/dev.diercke.com/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#10 /var/www/dev.diercke.com/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#11 /var/www/dev.diercke.com/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(311): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#12 /var/www/dev.diercke.com/vendor/symfony/console/Command/Command.php(255): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /var/www/dev.diercke.com/vendor/symfony/console/Application.php(1027): Symfony\Component\Console\Command\Command->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /var/www/dev.diercke.com/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /var/www/dev.diercke.com/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /var/www/dev.diercke.com/vendor/drush/drush/src/Runtime/Runtime.php(118): Symfony\Component\Console\Application->run(Object(Drush\Symfony\DrushArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /var/www/dev.diercke.com/vendor/drush/drush/src/Runtime/Runtime.php(48): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 /var/www/dev.diercke.com/vendor/drush/drush/drush.php(72): Drush\Runtime\Runtime->run(Array)
#19 /var/www/dev.diercke.com/vendor/drush/drush/drush(4): require('/var/www/dev.di...')
#20 {main}
Error: Unsupported operand types in Drupal\migrate\Plugin\migrate\process\SubProcess->transform() (line 206 of /var/www/dev.diercke.com/web/core/modules/migrate/src/Plugin/migrate/process/SubProcess.php).
 [warning] Drush command terminated abnormally.
...
process:
...
  field_stichworte: tags
  field_stichworte_einzeln:
    - plugin: explode
      source: tags
      limit: 10000
      delimiter: ,
    - plugin: deepen
    - plugin: sub_process
      process:
        field_stichworte_einzeln:
          - plugin: extract
            index:
              - 0
...
Score:2
kr flag

I found a solution:

fields:
    ...
    -
    name: keywords_with_comma
    label: 'keywords'
    selector: keywords
    ...
process:
    ...
    field_keywords_multi:
        - plugin: explode
          delimiter: ','
          source: keywords_with_comma
        - plugin: single_value
        - plugin: multiple_values
    ...
jp flag
Perfect, thx a lot!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.