Fixes for the error which phpcbf can't fix

This commit is contained in:
Kyle Huynh 2023-06-07 01:35:02 -04:00
parent 0940670323
commit d1692db53a
7 changed files with 57 additions and 35 deletions

View file

@ -199,7 +199,7 @@ class AdvancedSearchQuery {
if ($isDismax) { if ($isDismax) {
if ((strpos($q, "*") !== FALSE || strpos($q, "?") !== FALSE)) { 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)); $tmp = str_replace('"', "", trim($q));
$query_fields = []; $query_fields = [];
@ -207,9 +207,13 @@ class AdvancedSearchQuery {
foreach ($field_mapping as $key => $field) { foreach ($field_mapping as $key => $field) {
foreach ($field as $f => $item) { foreach ($field as $f => $item) {
// bs_ are boolean fields, do not work well with text search. // bs_ are boolean fields, do not work well with text search.
if (substr($item, 0, 3) !== "bs_" && !in_array($item, ['score', 'random', 'boost_document']) if (substr($item, 0, 3) !== "bs_"
&& ((strpos($item, "sm_") === 0) || (strpos($item, "tm_") === 0) || (strpos($item, "sort_ss_") === 0) || (strpos($item, "ts_") === 0) && !in_array($item, ['score', 'random', 'boost_document'])
|| (strpos($item, "ss_") === 0) && ((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 . ')'); array_push($query_fields, '(' . $item . ':' . $tmp . ')');
} }
@ -370,9 +374,9 @@ class AdvancedSearchQuery {
/** /**
* Sets the highlighting parameters. * Sets the highlighting parameters.
* *
* @param \Solarium\QueryType\Select\Query\Query $solarium_query * @param \Solarium\Core\Query\QueryInterface $solarium_query
* The Solarium select query object. * The Solarium select query object.
* @param \Drupal\search_api\Query\QueryInterface $query * @param \Drupal\search_api\Query\QueryInterface $search_api_query
* The query object. * The query object.
* @param array $highlighted_fields * @param array $highlighted_fields
* (optional) The solr fields to be highlighted. * (optional) The solr fields to be highlighted.

View file

@ -329,10 +329,7 @@ class AdvancedSearchQueryTerm {
if (strpos($field, "fulltext_title") !== FALSE) { if (strpos($field, "fulltext_title") !== FALSE) {
$isTitleSearch = TRUE; $isTitleSearch = TRUE;
if (strpos(trim($value), " AND ") !== FALSE) { if (strpos(trim($value), " AND ") !== FALSE) {
// When you type 'Orientation AND games' into the title search, you get one result. // Handle keyword with 'Orientation AND games'.
// 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.)
$keyword = str_replace('"', '', $value); $keyword = str_replace('"', '', $value);
$keys = explode(" AND ", $keyword); $keys = explode(" AND ", $keyword);
$str = "("; $str = "(";

View file

@ -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 * @return bool
* the enable or disable for Search All Fields checkbox
*/ */
public static function getSearchAllFields() { public static function getSearchAllFields() {
return self::getConfig(SettingsForm::SEARCH_ALL_FIELDS_FLAG, 0); 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. * Get if Edismax Search checkbox is enabled or disable.
* *
* @return bool * @return bool
* the enable or disable for Edismax Search checkbox
*/ */
public static function getEdismaxSearch() { public static function getEdismaxSearch() {
return self::getConfig(SettingsForm::EDISMAX_SEARCH_FLAG, 0); 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); $term_default_values = $this->defaultTermValues($options);
[$recursive, $term_values] = $this->processInput($form_state, $term_default_values); [$recursive, $term_values] = $this->processInput($form_state, $term_default_values);
$i = 0; $i = 0;

View file

@ -8,30 +8,45 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url; use Drupal\Core\Url;
/** /**
* * Form for building and Simple Search.
*/ */
class SearchForm extends FormBase { 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) { public function __construct($block_id) {
$this->block_id = $block_id; $this->blockId = $block_id;
} }
/** /**
* Get Block Id.
*
* @return mixed * @return mixed
* Return the Block ID
*/ */
public function getBlockId() { 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 { public function setBlockId($blockId): void {
$this->block_id = $block_id; $this->blockId = $blockId;
} }
/** /**
@ -51,12 +66,12 @@ class SearchForm extends FormBase {
$form['search-attributes'][SettingsForm::SEARCH_ALL_FIELDS_FLAG] = [ $form['search-attributes'][SettingsForm::SEARCH_ALL_FIELDS_FLAG] = [
'#markup' => $this '#markup' => $this
->t('<strong>This block is required to enable searching all fields for the Advanced Search. ->t('<strong>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
<a href="/admin/config/search/advanced" target="_blank">Advanced Seach Configuration</a></strong>.'), <a href="/admin/config/search/advanced" target="_blank">Advanced Seach Configuration</a></strong>.'),
]; ];
} }
else { else {
$block = Block::load($this->block_id); $block = Block::load($this->blockId);
if ($block) { if ($block) {
$settings = $block->get('settings'); $settings = $block->get('settings');
@ -67,8 +82,8 @@ class SearchForm extends FormBase {
'#type' => 'textfield', '#type' => 'textfield',
'#title' => (!empty($settings['search_textfield_label']) ? $settings['search_textfield_label'] : ''), '#title' => (!empty($settings['search_textfield_label']) ? $settings['search_textfield_label'] : ''),
'#attributes' => [ '#attributes' => [
'placeholder' => isset($settings['search_placeholder']) ? $this->t($settings['search_placeholder']) : $this->t("Search collections"), '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')), 'aria-label' => (isset($settings['search_textfield_label']) ? $this->t("@", $settings['search_textfield_label']) : $this->t('Enter Keyword')),
], ],
'#theme_wrappers' => [], '#theme_wrappers' => [],
]; ];
@ -88,7 +103,7 @@ class SearchForm extends FormBase {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function submitForm(array &$form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state) {
$block = Block::load($this->block_id); $block = Block::load($this->blockId);
if ($block) { if ($block) {
$settings = $block->get('settings'); $settings = $block->get('settings');
$view_machine_name = $settings['search_view_machine_name']; $view_machine_name = $settings['search_view_machine_name'];

View file

@ -41,8 +41,8 @@ abstract class SearchApiDisplayBlockDeriver implements ContainerDeriverInterface
abstract protected function label(); abstract protected function label();
/** /**
* * The constructor.
*/ */
final public function __construct(ContainerInterface $container, $base_plugin_id) {} final public function __construct(ContainerInterface $container, $base_plugin_id) {}
/** /**

View file

@ -38,7 +38,7 @@ class SearchBlock extends BlockBase {
$form['search-attributes'][SettingsForm::SEARCH_ALL_FIELDS_FLAG] = [ $form['search-attributes'][SettingsForm::SEARCH_ALL_FIELDS_FLAG] = [
'#markup' => $this '#markup' => $this
->t('<strong>This block is required to enable searching all fields for the Advanced Search. ->t('<strong>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
<a href="/admin/config/search/advanced" target="_blank">Advanced Seach Configuration</a></strong>.'), <a href="/admin/config/search/advanced" target="_blank">Advanced Seach Configuration</a></strong>.'),
]; ];
} }
@ -55,19 +55,19 @@ class SearchBlock extends BlockBase {
} }
$form['search-attributes']['view_machine_name'] = [ $form['search-attributes']['view_machine_name'] = [
'#type' => 'select', '#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'], '#default_value' => $this->configuration['search_view_machine_name'],
'#options' => $options, '#options' => $options,
]; ];
$form['search-attributes']['search_textfield'] = [ $form['search-attributes']['search_textfield'] = [
'#type' => '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'], '#default_value' => $this->configuration['search_textfield_label'],
'#maxlength' => 255, '#maxlength' => 255,
]; ];
$form['search-attributes']['search_placeholder_textfield'] = [ $form['search-attributes']['search_placeholder_textfield'] = [
'#type' => 'textfield', '#type' => 'textfield',
'#title' => $this->t('Search Keyword Textfield Placeholder:'), '#title' => $this->t('Search Keyword text field placeholder:'),
'#default_value' => $this->configuration['search_placeholder'], '#default_value' => $this->configuration['search_placeholder'],
'#maxlength' => 255, '#maxlength' => 255,
]; ];

View file

@ -186,8 +186,10 @@ class SearchResultsPagerBlock extends BlockBase implements ContainerFactoryPlugi
'#url' => $url, '#url' => $url,
'#title' => $items_per_page, '#title' => $items_per_page,
'#attributes' => [ '#attributes' => [
'aria-label' => $this->t($items_per_page . " items per page"), 'aria-label' => $this->t("@ items per page", $items_per_page),
'class' => $active ? ['pager__link', 'pager__link--is-active', 'pager__itemsperpage'] : ['pager__link', 'pager__itemsperpage'], 'class' => $active ?
['pager__link', 'pager__link--is-active', 'pager__itemsperpage'] :
['pager__link', 'pager__itemsperpage'],
], ],
'#wrapper_attributes' => [ '#wrapper_attributes' => [
'class' => $active ? ['pager__item', 'is-active'] : ['pager__item'], 'class' => $active ? ['pager__item', 'is-active'] : ['pager__item'],
@ -245,8 +247,10 @@ class SearchResultsPagerBlock extends BlockBase implements ContainerFactoryPlugi
'#url' => $url, '#url' => $url,
'#title' => Markup::create($text), '#title' => Markup::create($text),
'#attributes' => [ '#attributes' => [
'class' => $active ? ['pager__link', 'pager__link--is-active', 'pager__display'] : ['pager__link', 'pager__display'], 'class' => $active ?
'aria-label' => $this->t("Display as " . Markup::create($text)), ['pager__link', 'pager__link--is-active', 'pager__display'] :
['pager__link', 'pager__display'],
'aria-label' => $this->t("Display as @", Markup::create($text)),
], ],
'#wrapper_attributes' => [ '#wrapper_attributes' => [
'class' => $active ? ['pager__item', 'is-active'] : ['pager__item'], 'class' => $active ? ['pager__item', 'is-active'] : ['pager__item'],