From d1692db53ab0577c8686c1daa89460a57097e16f Mon Sep 17 00:00:00 2001 From: Kyle Huynh Date: Wed, 7 Jun 2023 01:35:02 -0400 Subject: [PATCH] Fixes for the error which phpcbf can't fix --- src/AdvancedSearchQuery.php | 16 +++++--- src/AdvancedSearchQueryTerm.php | 5 +-- src/Form/AdvancedSearchForm.php | 6 ++- src/Form/SearchForm.php | 41 +++++++++++++------ .../Block/SearchApiDisplayBlockDeriver.php | 4 +- src/Plugin/Block/SearchBlock.php | 8 ++-- src/Plugin/Block/SearchResultsPagerBlock.php | 12 ++++-- 7 files changed, 57 insertions(+), 35 deletions(-) diff --git a/src/AdvancedSearchQuery.php b/src/AdvancedSearchQuery.php index 597936e..4d6c494 100644 --- a/src/AdvancedSearchQuery.php +++ b/src/AdvancedSearchQuery.php @@ -199,7 +199,7 @@ class AdvancedSearchQuery { if ($isDismax) { if ((strpos($q, "*") !== FALSE || strpos($q, "?") !== FALSE)) { - // If the query string contain '*', '?', OR is a single world, enable wildcard. + // If the query string contain '*','?',a single world,enable wildcard. $tmp = str_replace('"', "", trim($q)); $query_fields = []; @@ -207,9 +207,13 @@ class AdvancedSearchQuery { foreach ($field_mapping as $key => $field) { foreach ($field as $f => $item) { // bs_ are boolean fields, do not work well with text search. - if (substr($item, 0, 3) !== "bs_" && !in_array($item, ['score', 'random', 'boost_document']) - && ((strpos($item, "sm_") === 0) || (strpos($item, "tm_") === 0) || (strpos($item, "sort_ss_") === 0) || (strpos($item, "ts_") === 0) - || (strpos($item, "ss_") === 0) + if (substr($item, 0, 3) !== "bs_" + && !in_array($item, ['score', 'random', 'boost_document']) + && ((strpos($item, "sm_") === 0) + || (strpos($item, "tm_") === 0) + || (strpos($item, "sort_ss_") === 0) + || (strpos($item, "ts_") === 0) + || (strpos($item, "ss_") === 0) )) { array_push($query_fields, '(' . $item . ':' . $tmp . ')'); } @@ -370,9 +374,9 @@ class AdvancedSearchQuery { /** * Sets the highlighting parameters. * - * @param \Solarium\QueryType\Select\Query\Query $solarium_query + * @param \Solarium\Core\Query\QueryInterface $solarium_query * The Solarium select query object. - * @param \Drupal\search_api\Query\QueryInterface $query + * @param \Drupal\search_api\Query\QueryInterface $search_api_query * The query object. * @param array $highlighted_fields * (optional) The solr fields to be highlighted. diff --git a/src/AdvancedSearchQueryTerm.php b/src/AdvancedSearchQueryTerm.php index 2932172..17bb2c0 100644 --- a/src/AdvancedSearchQueryTerm.php +++ b/src/AdvancedSearchQueryTerm.php @@ -329,10 +329,7 @@ class AdvancedSearchQueryTerm { if (strpos($field, "fulltext_title") !== FALSE) { $isTitleSearch = TRUE; if (strpos(trim($value), " AND ") !== FALSE) { - // When you type 'Orientation AND games' into the title search, you get one result. - // When you do the same search but add a search box, you get a lot more results. - // (Recreation: Add a search box, set both search criteria to 'Title' and keep the operator to 'and'. - // Type 'orientation' in one box and 'games' in the second box and click seach.) + // Handle keyword with 'Orientation AND games'. $keyword = str_replace('"', '', $value); $keys = explode(" AND ", $keyword); $str = "("; diff --git a/src/Form/AdvancedSearchForm.php b/src/Form/AdvancedSearchForm.php index 2a621a8..587df40 100644 --- a/src/Form/AdvancedSearchForm.php +++ b/src/Form/AdvancedSearchForm.php @@ -104,9 +104,10 @@ class AdvancedSearchForm extends FormBase { } /** - * Get if Edismax Search checkbox is enabled or disable. + * Get if Search All Fields checkbox is enabled or disable. * * @return bool + * the enable or disable for Search All Fields checkbox */ public static function getSearchAllFields() { return self::getConfig(SettingsForm::SEARCH_ALL_FIELDS_FLAG, 0); @@ -116,6 +117,7 @@ class AdvancedSearchForm extends FormBase { * Get if Edismax Search checkbox is enabled or disable. * * @return bool + * the enable or disable for Edismax Search checkbox */ public static function getEdismaxSearch() { return self::getConfig(SettingsForm::EDISMAX_SEARCH_FLAG, 0); @@ -271,7 +273,7 @@ class AdvancedSearchForm extends FormBase { ], ]; - $options = (self::getEdismaxSearch() && self::getSearchAllFields()) ? ["all" => $this->t(self::getEdismaxSearchLabel())] + $this->fieldOptions($fields) : $this->fieldOptions($fields); + $options = (self::getEdismaxSearch() && self::getSearchAllFields()) ? ["all" => $this->t("@", self::getEdismaxSearchLabel())] + $this->fieldOptions($fields) : $this->fieldOptions($fields); $term_default_values = $this->defaultTermValues($options); [$recursive, $term_values] = $this->processInput($form_state, $term_default_values); $i = 0; diff --git a/src/Form/SearchForm.php b/src/Form/SearchForm.php index 0e57e55..d1a547f 100644 --- a/src/Form/SearchForm.php +++ b/src/Form/SearchForm.php @@ -8,30 +8,45 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** - * + * Form for building and Simple Search. */ class SearchForm extends FormBase { - protected $block_id; /** - * @param $block_id + * The Block ID. + * + * @var string + */ + protected $blockId; + + /** + * The constructor. + * + * @param string $block_id + * Passing the block_id. */ public function __construct($block_id) { - $this->block_id = $block_id; + $this->blockId = $block_id; } /** + * Get Block Id. + * * @return mixed + * Return the Block ID */ public function getBlockId() { - return $this->block_id; + return $this->blockId; } /** - * @param mixed $block_id + * Set Block ID. + * + * @param mixed $blockId + * Set the block ID. */ - public function setBlockId($block_id): void { - $this->block_id = $block_id; + public function setBlockId($blockId): void { + $this->blockId = $blockId; } /** @@ -51,12 +66,12 @@ class SearchForm extends FormBase { $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 + To proceed, please enable the Search All fields in Advanced Seach Configuration.'), ]; } else { - $block = Block::load($this->block_id); + $block = Block::load($this->blockId); if ($block) { $settings = $block->get('settings'); @@ -67,8 +82,8 @@ class SearchForm extends FormBase { '#type' => 'textfield', '#title' => (!empty($settings['search_textfield_label']) ? $settings['search_textfield_label'] : ''), '#attributes' => [ - 'placeholder' => isset($settings['search_placeholder']) ? $this->t($settings['search_placeholder']) : $this->t("Search collections"), - 'aria-label' => (isset($settings['search_textfield_label']) ? $this->t($settings['search_textfield_label']) : $this->t('Enter Keyword')), + 'placeholder' => isset($settings['search_placeholder']) ? $this->t("@", $settings['search_placeholder']) : $this->t("Search collections"), + 'aria-label' => (isset($settings['search_textfield_label']) ? $this->t("@", $settings['search_textfield_label']) : $this->t('Enter Keyword')), ], '#theme_wrappers' => [], ]; @@ -88,7 +103,7 @@ class SearchForm extends FormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $block = Block::load($this->block_id); + $block = Block::load($this->blockId); if ($block) { $settings = $block->get('settings'); $view_machine_name = $settings['search_view_machine_name']; diff --git a/src/Plugin/Block/SearchApiDisplayBlockDeriver.php b/src/Plugin/Block/SearchApiDisplayBlockDeriver.php index 6b66b1f..49d7cba 100644 --- a/src/Plugin/Block/SearchApiDisplayBlockDeriver.php +++ b/src/Plugin/Block/SearchApiDisplayBlockDeriver.php @@ -41,8 +41,8 @@ abstract class SearchApiDisplayBlockDeriver implements ContainerDeriverInterface abstract protected function label(); /** - * - */ + * The constructor. + */ final public function __construct(ContainerInterface $container, $base_plugin_id) {} /** diff --git a/src/Plugin/Block/SearchBlock.php b/src/Plugin/Block/SearchBlock.php index 1cf0c13..3c49edd 100644 --- a/src/Plugin/Block/SearchBlock.php +++ b/src/Plugin/Block/SearchBlock.php @@ -38,7 +38,7 @@ class SearchBlock extends BlockBase { $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 "Enable searching all fields" in + To proceed, please enable "Enable searching all fields" in Advanced Seach Configuration.'), ]; } @@ -55,19 +55,19 @@ class SearchBlock extends BlockBase { } $form['search-attributes']['view_machine_name'] = [ '#type' => 'select', - '#title' => $this->t('Select Search Results Page\'s Machine Name:'), + '#title' => $this->t('Select the machine name of Search Results Page:'), '#default_value' => $this->configuration['search_view_machine_name'], '#options' => $options, ]; $form['search-attributes']['search_textfield'] = [ '#type' => 'textfield', - '#title' => $this->t('Search Keyword Textfield Label:'), + '#title' => $this->t('Search Keyword Text field 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:'), + '#title' => $this->t('Search Keyword text field placeholder:'), '#default_value' => $this->configuration['search_placeholder'], '#maxlength' => 255, ]; diff --git a/src/Plugin/Block/SearchResultsPagerBlock.php b/src/Plugin/Block/SearchResultsPagerBlock.php index c360646..caa8626 100644 --- a/src/Plugin/Block/SearchResultsPagerBlock.php +++ b/src/Plugin/Block/SearchResultsPagerBlock.php @@ -186,8 +186,10 @@ class SearchResultsPagerBlock extends BlockBase implements ContainerFactoryPlugi '#url' => $url, '#title' => $items_per_page, '#attributes' => [ - 'aria-label' => $this->t($items_per_page . " items per page"), - 'class' => $active ? ['pager__link', 'pager__link--is-active', 'pager__itemsperpage'] : ['pager__link', 'pager__itemsperpage'], + 'aria-label' => $this->t("@ items per page", $items_per_page), + 'class' => $active ? + ['pager__link', 'pager__link--is-active', 'pager__itemsperpage'] : + ['pager__link', 'pager__itemsperpage'], ], '#wrapper_attributes' => [ 'class' => $active ? ['pager__item', 'is-active'] : ['pager__item'], @@ -245,8 +247,10 @@ class SearchResultsPagerBlock extends BlockBase implements ContainerFactoryPlugi '#url' => $url, '#title' => Markup::create($text), '#attributes' => [ - 'class' => $active ? ['pager__link', 'pager__link--is-active', 'pager__display'] : ['pager__link', 'pager__display'], - 'aria-label' => $this->t("Display as " . Markup::create($text)), + 'class' => $active ? + ['pager__link', 'pager__link--is-active', 'pager__display'] : + ['pager__link', 'pager__display'], + 'aria-label' => $this->t("Display as @", Markup::create($text)), ], '#wrapper_attributes' => [ 'class' => $active ? ['pager__item', 'is-active'] : ['pager__item'],