How to get a reference of which block entity this current view exposed form block belongs to in hook_form_views_exposed_form_alter().

$form_state->getFormObject() returns an object of Drupal\views\Form\ViewsExposedForm. This object doesn't have any reference to the $block.

I can get the block entity correctly inside hook_form_block_form_alter() by something like this:

$block = $form_state->getFormObject()->getEntity();

I wanted to modify the views exposed form based on a 3rd party value set on the block entity. But unable to do so, because I need to dynamically get the block id and not hardcode.

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.