0

I am trying to meet the following requirement:

I want to create a node (custom content type) that contains only a paragraph reference.

I have the following paragraphs in my node

  • Billboard (large image + Caption)
  • Testmonial (slideshow sentences)
  • Body
  • Here i want to display a view that contains news articles (nodes from the custom news content type)
  • Call to action

But i can't seem to do this properly?

I can create a block display for my view and attach it to the page by path, but then the view is located below my paragraphs, where I want the view to be one of the paragraphs, since there is a call to action that needs to be located below the view.

Anyone ever tried this?

All suggestions welcome!

If you have a solution that does not use paragraphs, I am also happy to hear!

Many thanks in advance

EDIT: After some additional searching, it seems that for D7, this module seems to be capable of doing this: https://www.drupal.org/project/entityreference_views_formatter more information can be found here: https://www.drupal.org/node/2756315

Still no solution for D8 though...

3

Using hook_entity_view, you can insert the view into the field's build array.

function mymodule_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {

  if ($entity->getEntityType()->id() == 'node' && $entity->bundle() == 'example_content_type' && $view_mode == 'full') {
    $node_id = \Drupal::routeMatch()->getRawParameter('node');
    $index = 0;
    foreach($build['field_paragraph_field'] as $key => $value) {

      if (is_numeric($key) && $value['#paragraph']->bundle() == 'body') {
        $news_view = [
          '#type' => 'view',
          '#name' => 'my_news_feed',
          '#display_id' => 'block_1',
          '#arguments' => [$node_id],
        ];

        array_splice($build['field_paragraph_field'], $index + 1, 0, [$news_view]);

      }
      $index++;
    }
  }

}
1

Check out the Views Reference Field module. This module provides a new field type that allows you to reference a view display similar to an entity reference field. After installing the module create a new paragraph type with a viewsreference field. You now have a paragraph type that displays a view.

0

You should be able to acheive this with any module that can add a view as a field. Currently for D8:

  • Display Suite
  • Entity views attachment
  • Viewfield
  • Display fields
0

I did this by adding a paragraph type that is one Entity reference field.

There is a tutorial here: https://www.mediacurrent.com/blog/drupal-8-how-reference-views-block-display-field/

It works great and takes paragraphs to the next level.

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.