0

I have it working for nodes but i tried for paragraph view and it is not working Here is the code:

function hook_form_views_exposed_form_alter(&$form, FormStateInterface $form_state, $form_id) {

$storage = Drupal::getContainer()->get('entity_type.manager')->getStorage('paragraph');
$nids = $storage->getQuery();
$nids = $nids->condition('status', 1)
 ->execute();

if (!$nids) {
 return FALSE;
}


$options = [];
$nodes = $storage->loadMultiple($nids);


foreach ($nodes as $paragraph) {

    $value = $paragraph->field_pdf_title->value;
    $options[$value] = $value;

}


$form['field_pdf_title']['#type'] = 'select';
$form['field_pdf_title']['#options'] = $options;
$form['field_pdf_title']['#size'] = 1;
}
  • You should change $nids to $pids and $nodes to $pagaraphs. Anyhow, I think the culprit is this line $nids = $nids->condition('status', 1) as paragraphs don't have status, so get rid of this line. – No Sssweat Mar 1 at 22:57
  • I saw also that i have to enable ajax on the page otherwise the filter doesnt show up. But now i see all the title fields in the drop down not only the ones from the current node page (which were the only ones shown before adding the filter due to the contextual filter that I added) and when selecting any of them it always returns the fields from the "first paragraph" any idea why the filter is not working? – rebecca mantel Mar 2 at 21:24

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.