I created a block based on the view with machine name search_entity_product_block:
Then I created a custom form with method someMethod
which should render a block of the view below the search field:
class SearchFieldForm extends FormBase {
public function getFormId() {
return 'entity_product_admin_search_field';
}
public function someMethod($args) {
$view = [
'#type' => 'view',
'#name' => 'search_entity_product',
'#display_id' => 'search_entity_product_block',
'#arguments' => $args,
'#embed' => TRUE,
];
return $view;
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form['search_field'] = [
'#type' => 'textfield',
'#title' => $this->t('Search Product'),
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Save'),
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$args = $form_state->getValue('search_field');
$this->someMethod($args);
}
}
But the block didn't render.
submitForm()
; you'll need to refactor the code to render it somewhere else.buildForm()
, as 4uk4's answer says.