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?


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.

| improve this answer | |

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.