0

I try to import CSV files into a Drupal 8 installation but I can't manage to make the relationship to paragraphs appear. I followed the steps of this tutorial but can't figure out how to make it work. I created a simple test case to find the error:

I extended the regular article content type with a paragraphs field called field_persons for linking each article to a list of persons with roles. This paragraphs entity has to fields called field_name (for now only text) and field_role (taxonomy_term).

The yaml file for paragraphs migration looks like that and import processes without error:

id: article_persons
label: Import persons for articles

source:
  plugin: csv
  delimiter: '|'
  enclosure: '"'
  path: article_persons.csv
  header_row_count: 1
  keys:
    - id
  column_names:
    0:
      id: 'ID'
    1:
      name: 'Name'
    2:
      rol: 'Role'

process:
  field_nombre: name
  field_para_rol: 
    plugin: entity_generate
    source: role
    value_key: name
    bundle_key: vid
    bundle: rol
    entity_type: taxonomy_term
    ignore_case: true

destination:
  plugin: 'entity_reference_revisions:paragraph'
  default_bundle: article_persons

The yaml file for article migration looks like that and import processes without error:

id: article
label: Import articles

source:
  plugin: csv
  delimiter: '|'
  enclosure: '"'
  path: articles.csv
  header_row_count: 1
  keys:
    - id
  column_names:
    0:
      id: 'ID'
    1:
      title: 'Title'
    2:
      person: 'Persons'

process:
  title: title
  type:
    plugin: default_value
    default_value: article
  field_person/target_id: 
    -
      plugin: migration_lookup
      migration: article_persons
      no_stub: true
      source: id
    -
      plugin: extract
      index:
        - '0'
  field_person/target_revision_id: 
    -
      plugin: migration_lookup
      migration: article_persons
      no_stub: true
      source: id
    -
      plugin: extract
      index:
        - 1

destination:
  plugin: 'entity:node'
migration_dependencies:
  required: 
    - article_persons
  optional: { }

But when I try to access the node I get an "unexpected error" with a huge log message:

Error: Call to a member function getEnabledBehaviorPlugins() on null en Drupal\paragraphs\ParagraphViewBuilder->buildMultiple() (línea 37 de /var/www/html/sites/all/modules/paragraphs/src/ParagraphViewBuilder.php)
#0 /var/www/html/core/lib/Drupal/Core/Entity/EntityViewBuilder.php(220): Drupal\paragraphs\ParagraphViewBuilder->buildMultiple(Array)
#1 [internal function]: Drupal\Core\Entity\EntityViewBuilder->build(Array)
#2 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(378): call_user_func(Array, Array)
#3 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, false)
#4 /var/www/html/core/lib/Drupal/Core/Template/TwigExtension.php(490): Drupal\Core\Render\Renderer->render(Array)
#5 /var/www/html/sites/default/files/php/twig/5a008e9488529_field.html.twig_9MJB5waMfG4Lcal_NDL6EY6rM/NRByUw7bYmwhNIE9WTZfCRjJ3XUAFBB122RdQTC3JsI.php(128): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true)
#6 /var/www/html/vendor/twig/twig/lib/Twig/Template.php(432): __TwigTemplate_85d8aba47ed6496a0f2e8e6407c9fc1802c03e707a72d9d0c1465c62e125a308->doDisplay(Array, Array)
#7 /var/www/html/vendor/twig/twig/lib/Twig/Template.php(403): Twig_Template->displayWithErrorHandling(Array, Array)
#8 /var/www/html/vendor/twig/twig/lib/Twig/Template.php(411): Twig_Template->display(Array)
#9 /var/www/html/core/themes/engines/twig/twig.engine(64): Twig_Template->render(Array)
#10 /var/www/html/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template('sites/all/theme...', Array)
#11 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(437): Drupal\Core\Theme\ThemeManager->render('field', Array)
#12 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(450): Drupal\Core\Render\Renderer->doRender(Array)
#13 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, false)
#14 /var/www/html/core/lib/Drupal/Core/Template/TwigExtension.php(490): Drupal\Core\Render\Renderer->render(Array)
#15 /var/www/html/sites/default/files/php/twig/5a008e9488529_node.html.twig_fOU7Z1faeO15YpZRrtd-F9Ksv/yHD4dpGBMlI8SMMqQ5z-QVQGNcCrpCuzsSt1E4ShcEU.php(111): Drupal\Core\Template\TwigExtension->escapeFilter(Object(Drupal\Core\Template\TwigEnvironment), Array, 'html', NULL, true)
#16 /var/www/html/vendor/twig/twig/lib/Twig/Template.php(432): __TwigTemplate_38fa5b6b1f6bdfd56bb4dba5e7d13d0f61126e79c913612089235f94cf12db1f->doDisplay(Array, Array)
#17 /var/www/html/vendor/twig/twig/lib/Twig/Template.php(403): Twig_Template->displayWithErrorHandling(Array, Array)
#18 /var/www/html/vendor/twig/twig/lib/Twig/Template.php(411): Twig_Template->display(Array)
#19 /var/www/html/core/themes/engines/twig/twig.engine(64): Twig_Template->render(Array)
#20 /var/www/html/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template('sites/all/theme...', Array)
#21 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(437): Drupal\Core\Theme\ThemeManager->render('node', Array)
#22 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, false)
#23 /var/www/html/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(226): Drupal\Core\Render\Renderer->render(Array, false)
#24 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(576): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
#25 /var/www/html/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(227): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#26 /var/www/html/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(117): Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch))
#27 /var/www/html/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\CurrentRouteMatch))
#28 /var/www/html/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(108): Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent), 'kernel.view', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#29 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(158): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object(Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent))
#30 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#31 /var/www/html/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#32 /var/www/html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#33 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#34 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#35 /var/www/html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#36 /var/www/html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(50): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#37 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#38 /var/www/html/core/lib/Drupal/Core/DrupalKernel.php(657): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#39 /var/www/html/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#40 {main}.

This bug report seems to indicate that the paragraphs which is referenced doesn't exist. So it seems to have to do something with the ids, but I can't figure out what.

0

Finally I could make it working fixing two things in my code:

First. Adding the paragraph machine name as type to process statement:

process:
  type:
    plugin: default_value
    default_value: persona

Second. Changing the source parameter to the column which contains the id of the related paragraph.

After reading the Drupal issue list for Entity Reference Revisions I learned that now there is a more simple way to specify the target_id and target_revision_id. With the help from this thread I ended up using this process code for node import of field_person:

  field_person:
    -
      plugin: skip_on_empty
      method: process
      source: person
    -
      plugin: explode
      delimiter: ,
    -
      plugin: migration_lookup
      migration: article_persons
      no_stub: true
    -
      plugin: iterator
      process:
        target_id: '0'
        target_revision_id: '1'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.