diff --git a/src/Form/SearchForm.php b/src/Form/SearchForm.php
index 5a6ada7..eef065c 100644
--- a/src/Form/SearchForm.php
+++ b/src/Form/SearchForm.php
@@ -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('This block is required to enable searching all fields for the Advanced Search.
+ To proceed, please enable the Search All fields in
+ Advanced Seach Configuration.'),
+ ];
}
- $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;
}
diff --git a/src/Plugin/Block/SearchBlock.php b/src/Plugin/Block/SearchBlock.php
index a31e034..c56377e 100644
--- a/src/Plugin/Block/SearchBlock.php
+++ b/src/Plugin/Block/SearchBlock.php
@@ -4,6 +4,7 @@ namespace Drupal\advanced_search\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;
+use Drupal\advanced_search\Form\SettingsForm;
/**
* Provides a 'SearchBlock' block.
@@ -27,46 +28,58 @@ class SearchBlock extends BlockBase {
* {@inheritdoc}
*/
public function blockForm($form, FormStateInterface $form_state) {
+ $config = \Drupal::config(SettingsForm::CONFIG_NAME);
$form['search-attributes'] = [
'#type' => 'fieldset',
'#title' => $this->t('Configure Search Block'),
];
- $views = \Drupal::EntityTypeManager()->getStorage('view')->loadMultiple();
- $options = [];
- foreach ($views as $view_name => $view) {
- $displays = $view->get("display");
- foreach ($displays as $display) {
- if ($display['display_plugin'] === "page") {
- $options["view.$view_name". "." . $display['id']] = "view.$view_name". "." . $display['id'];
- }
- }
+
+ if (!$config->get(SettingsForm::SEARCH_ALL_FIELDS_FLAG)) {
+ $form['search-attributes'][SettingsForm::SEARCH_ALL_FIELDS_FLAG] = [
+ '#markup' => $this
+ ->t('This block is required to enable searching all fields for the Advanced Search.
+ To proceed, please enable the Search All fields in
+ Advanced Seach Configuration.'),
+ ];
}
- $form['search-attributes']['view_machine_name'] = [
- '#type' => 'select',
- '#title' => $this->t('Select Search Results Page\'s Machine Name:'),
- '#default_value' => $this->configuration['search_view_machine_name'],
- '#options' => $options
- ];
- $form['search-attributes']['search_textfield'] = [
- '#type' => 'textfield',
- '#title' => $this->t('Search Keyword Textfield Label:'),
- '#default_value' => $this->configuration['search_textfield_label'],
- '#maxlength' => 255,
- ];
- $form['search-attributes']['search_placeholder_textfield'] = [
- '#type' => 'textfield',
- '#title' => $this->t('Search Keyword Textfield Placeholder:'),
- '#default_value' => $this->configuration['search_placeholder'],
- '#maxlength' => 255,
- ];
-
- $form['search-attributes']['search_submit'] = [
- '#type' => 'textfield',
- '#title' => $this->t('Search Button Label:'),
- '#default_value' => $this->configuration['search_submit_label'],
- '#maxlength' => 255,
- ];
+ else {
+ $views = \Drupal::EntityTypeManager()->getStorage('view')->loadMultiple();
+ $options = [];
+ foreach ($views as $view_name => $view) {
+ $displays = $view->get("display");
+ foreach ($displays as $display) {
+ if ($display['display_plugin'] === "page") {
+ $options["view.$view_name". "." . $display['id']] = "view.$view_name". "." . $display['id'];
+ }
+ }
+ }
+ $form['search-attributes']['view_machine_name'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Select Search Results Page\'s Machine Name:'),
+ '#default_value' => $this->configuration['search_view_machine_name'],
+ '#options' => $options
+ ];
+ $form['search-attributes']['search_textfield'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Search Keyword Textfield Label:'),
+ '#default_value' => $this->configuration['search_textfield_label'],
+ '#maxlength' => 255,
+ ];
+ $form['search-attributes']['search_placeholder_textfield'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Search Keyword Textfield Placeholder:'),
+ '#default_value' => $this->configuration['search_placeholder'],
+ '#maxlength' => 255,
+ ];
+ $form['search-attributes']['search_submit'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Search Button Label:'),
+ '#default_value' => $this->configuration['search_submit_label'],
+ '#maxlength' => 255,
+ ];
+ }
+
return $form;
}