Added a check for Simple Search block to work only if "Enable Search Fields" is enable.

This commit is contained in:
Kyle Huynh 2023-02-07 10:21:42 -05:00
parent 2f3826fac1
commit b1b0065c2a
2 changed files with 76 additions and 50 deletions

View file

@ -23,25 +23,38 @@ class SearchForm extends FormBase
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$block = \Drupal\block\Entity\Block::load("search");
if ($block) {
$settings = $block->get('settings');
$view_machine_name = $settings['search_view_machine_name'];
$config = \Drupal::config(SettingsForm::CONFIG_NAME);
if (!$config->get(SettingsForm::SEARCH_ALL_FIELDS_FLAG)) {
$form['search-attributes'][SettingsForm::SEARCH_ALL_FIELDS_FLAG] = [
'#markup' => $this
->t('<strong>This block is required to enable searching all fields for the Advanced Search.
To proceed, please enable the Search All fields in
<a href="/admin/config/search/advanced" target="_blank">Advanced Seach Configuration</a></strong>.'),
];
}
$form['search-textfield'] = array(
'#type' => 'textfield',
'#title' => (!empty($settings['search_textfield_label']) ? $settings['search_textfield_label'] : ''),
'#attributes' => ['placeholder' => $settings['search_placeholder']]
);
else {
$block = \Drupal\block\Entity\Block::load("search");
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => (!empty($settings['search_submit_label']) ? $settings['search_submit_label'] : 'Search'),
'#button_type' => 'primary',
);
if ($block) {
$settings = $block->get('settings');
$view_machine_name = $settings['search_view_machine_name'];
}
$form['search-textfield'] = array(
'#type' => 'textfield',
'#title' => (!empty($settings['search_textfield_label']) ? $settings['search_textfield_label'] : ''),
'#attributes' => ['placeholder' => $settings['search_placeholder']]
);
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => (!empty($settings['search_submit_label']) ? $settings['search_submit_label'] : 'Search'),
'#button_type' => 'primary',
);
}
return $form;
}