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 ((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.

View file

@ -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 = "(";

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
* 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;

View file

@ -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;
}
/**
@ -56,7 +71,7 @@ class SearchForm extends FormBase {
];
}
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'];

View file

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

View file

@ -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,
];

View file

@ -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'],