-1

I have a content type with multiple field paragraph. I would like to get all the paragraphs from the current node in form_views_exposed_form_alter.

I tried

 $node = menu_get_object();
 $storage = Drupal::getContainer()->get('entity_type.manager')->getStorage('paragraph');
 $pids = $storage->getQuery(); 

which gets me all the paragraphs not only the ones of the current node. What am I missing?

1 Answer 1

0

I'm assuming that the paragraphs are attached to your node via field. Let's assume the field is called field_paragraphs. Try the following:

$node = \Drupal::routeMatch()->getParameter('node');
$paragraphs = $node->get('field_paragraphs')->getValue();

This works because Drupal's routing system utilizes upcasting to promote the nid to a fully loaded node reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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