0

Is there any example code for creating a new paragraph object with a viewsreference field and setting a view on the viewsreference field with its "type" and other display options set?

Can't really figure out how to do it using this discussion: https://www.drupal.org/project/viewsreference/issues/2885859

sudo code:

$dynamicContentParagraph = Paragraph::create([
  'type' => 'my_paragraph_machine_name',
  'field_p_title' => "Show all the things",
 ]);

// Get the view object.
$theView = Views::getView('my_view_machine_name');

if (is_object($theView)) {
   $theView->setDisplay('teaser');
   $theView->save();
   $input = [$theView];

   $dynamicContentParagraph->get('node_with_paragraphs_that_refrence_views')->appendItem($input);

   $dynamicContentParagraph->save();
   $nodeParagraphContainer->appendItem($dynamicContentParagraph);     
   $node->save();
}

I get the paragraph saved, but the view isn't getting its default display type set or saved.

Your Answer

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

Browse other questions tagged or ask your own question.