Added a check for Simple Search block to work only if "Enable Search Fields" is enable.
This commit is contained in:
parent
2f3826fac1
commit
b1b0065c2a
2 changed files with 76 additions and 50 deletions
|
|
@ -23,6 +23,17 @@ class SearchForm extends FormBase
|
||||||
*/
|
*/
|
||||||
public function buildForm(array $form, FormStateInterface $form_state)
|
public function buildForm(array $form, FormStateInterface $form_state)
|
||||||
{
|
{
|
||||||
|
$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>.'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
else {
|
||||||
$block = \Drupal\block\Entity\Block::load("search");
|
$block = \Drupal\block\Entity\Block::load("search");
|
||||||
|
|
||||||
if ($block) {
|
if ($block) {
|
||||||
|
|
@ -42,6 +53,8 @@ class SearchForm extends FormBase
|
||||||
'#value' => (!empty($settings['search_submit_label']) ? $settings['search_submit_label'] : 'Search'),
|
'#value' => (!empty($settings['search_submit_label']) ? $settings['search_submit_label'] : 'Search'),
|
||||||
'#button_type' => 'primary',
|
'#button_type' => 'primary',
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace Drupal\advanced_search\Plugin\Block;
|
||||||
|
|
||||||
use Drupal\Core\Block\BlockBase;
|
use Drupal\Core\Block\BlockBase;
|
||||||
use Drupal\Core\Form\FormStateInterface;
|
use Drupal\Core\Form\FormStateInterface;
|
||||||
|
use Drupal\advanced_search\Form\SettingsForm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a 'SearchBlock' block.
|
* Provides a 'SearchBlock' block.
|
||||||
|
|
@ -27,10 +28,21 @@ class SearchBlock extends BlockBase {
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function blockForm($form, FormStateInterface $form_state) {
|
public function blockForm($form, FormStateInterface $form_state) {
|
||||||
|
$config = \Drupal::config(SettingsForm::CONFIG_NAME);
|
||||||
$form['search-attributes'] = [
|
$form['search-attributes'] = [
|
||||||
'#type' => 'fieldset',
|
'#type' => 'fieldset',
|
||||||
'#title' => $this->t('Configure Search Block'),
|
'#title' => $this->t('Configure Search Block'),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
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>.'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
else {
|
||||||
$views = \Drupal::EntityTypeManager()->getStorage('view')->loadMultiple();
|
$views = \Drupal::EntityTypeManager()->getStorage('view')->loadMultiple();
|
||||||
$options = [];
|
$options = [];
|
||||||
foreach ($views as $view_name => $view) {
|
foreach ($views as $view_name => $view) {
|
||||||
|
|
@ -66,6 +78,7 @@ class SearchBlock extends BlockBase {
|
||||||
'#default_value' => $this->configuration['search_submit_label'],
|
'#default_value' => $this->configuration['search_submit_label'],
|
||||||
'#maxlength' => 255,
|
'#maxlength' => 255,
|
||||||
];
|
];
|
||||||
|
}
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue