Run phpcs and phpcbf

This commit is contained in:
Kyle Huynh 2023-06-07 00:59:16 -04:00
parent 9557ca17d5
commit 0940670323
13 changed files with 149 additions and 152 deletions

View file

@ -103,21 +103,19 @@ class AdvancedSearchForm extends FormBase {
return self::getConfig(SettingsForm::SEARCH_REMOVE_OPERATOR, self::DEFAULT_REMOVE_OP);
}
/**
* Get if Edismax Search checkbox is enabled or disable
*
* @return boolean
/**
* Get if Edismax Search checkbox is enabled or disable.
*
* @return bool
*/
public static function getSearchAllFields() {
return self::getConfig(SettingsForm::SEARCH_ALL_FIELDS_FLAG, 0);
}
/**
* Get if Edismax Search checkbox is enabled or disable
*
* @return boolean
* Get if Edismax Search checkbox is enabled or disable.
*
* @return bool
*/
public static function getEdismaxSearch() {
return self::getConfig(SettingsForm::EDISMAX_SEARCH_FLAG, 0);
@ -185,7 +183,7 @@ class AdvancedSearchForm extends FormBase {
*/
protected function processInput(FormStateInterface $form_state, array $term_default_values) {
$input = $form_state->getUserInput();
$recursive = isset($input['recursive']) ? $input['recursive'] : NULL;
$recursive = $input['recursive'] ?? NULL;
$term_values = isset($input['terms']) && is_array($input['terms']) ? $input['terms'] : [];
// Form was not submitted see if we can rebuild from query parameters.
$advanced_search_query = new AdvancedSearchQuery();
@ -273,9 +271,9 @@ 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);
list($recursive, $term_values) = $this->processInput($form_state, $term_default_values);
[$recursive, $term_values] = $this->processInput($form_state, $term_default_values);
$i = 0;
$term_elements = [];
$total_terms = count($term_values);
@ -284,20 +282,20 @@ class AdvancedSearchForm extends FormBase {
// Either specified by the user in the request or use the default.
$first = $i == 0;
$term_value = !empty($term_values) ? array_shift($term_values) : $term_default_values;
$conjunction = isset($term_value[self::CONJUNCTION_FORM_FIELD]) ? $term_value[self::CONJUNCTION_FORM_FIELD] : $term_default_values[self::CONJUNCTION_FORM_FIELD];
$conjunction = $term_value[self::CONJUNCTION_FORM_FIELD] ?? $term_default_values[self::CONJUNCTION_FORM_FIELD];
$term_elements[] = [
// Only show on terms after the first.
self::CONJUNCTION_FORM_FIELD => $first ? NULL : [
'#type' => 'select',
'#attributes' => [
'aria-label' => $this->t("Select search condition")
'aria-label' => $this->t("Select search condition"),
],
'#options' => [
self::AND_OP => $this->t('and'),
self::OR_OP => $this->t('or'),
],
'#default_value' => $conjunction,
'#theme_wrappers' => []
'#theme_wrappers' => [],
],
self::SEARCH_FORM_FIELD => [
'#type' => 'select',
@ -306,7 +304,7 @@ class AdvancedSearchForm extends FormBase {
],
'#options' => $options,
'#default_value' => $term_value[self::SEARCH_FORM_FIELD],
'#theme_wrappers' => []
'#theme_wrappers' => [],
],
self::INCLUDE_FORM_FIELD => [
'#type' => 'select',
@ -325,7 +323,7 @@ class AdvancedSearchForm extends FormBase {
':input[name="terms[' . $i . '][' . self::CONJUNCTION_FORM_FIELD . ']"]' => ['value' => self::AND_OP],
],
],
'#theme_wrappers' => []
'#theme_wrappers' => [],
],
// Just markup to show when 'include' is not alterable due to the
// selected 'conjunction'. Hide for the first term.
@ -340,15 +338,15 @@ class AdvancedSearchForm extends FormBase {
/*'content' => [
'#markup' => $this->t('is'),
],*/
'#theme_wrappers' => []
'#theme_wrappers' => [],
],
self::VALUE_FORM_FIELD => [
'#type' => 'textfield',
'#attributes' => [
'aria-label' => $this->t("Enter a search term")
'aria-label' => $this->t("Enter a search term"),
],
'#default_value' => $term_value[self::VALUE_FORM_FIELD],
'#theme_wrappers' => []
'#theme_wrappers' => [],
],
'actions' => [
'#type' => 'container',
@ -374,7 +372,7 @@ class AdvancedSearchForm extends FormBase {
'#name' => 'remove-term-' . $i,
'#term_index' => $i,
'#attributes' => [
'class' => [$block_class_prefix . '__remove', 'fa' ],
'class' => [$block_class_prefix . '__remove', 'fa'],
'aria-label' => $this->t("Remove"),
],
'#ajax' => [
@ -440,7 +438,7 @@ class AdvancedSearchForm extends FormBase {
$terms[] = AdvancedSearchQueryTerm::fromUserInput($term);
}
$terms = array_filter($terms);
$recurse = filter_var(isset($values['recursive']) ? $values['recursive'] : FALSE, FILTER_VALIDATE_BOOLEAN);
$recurse = filter_var($values['recursive'] ?? FALSE, FILTER_VALIDATE_BOOLEAN);
$route = $this->getRouteName($form_state);
$advanced_search_query = new AdvancedSearchQuery();
return $advanced_search_query->toUrl($this->request, $terms, $recurse, $route);

View file

@ -2,14 +2,15 @@
namespace Drupal\advanced_search\Form;
use Drupal\block\Entity\Block;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use \Drupal\Core\Url;
use Drupal\Core\Url;
class SearchForm extends FormBase
{
/**
*
*/
class SearchForm extends FormBase {
protected $block_id;
/**
@ -36,19 +37,17 @@ class SearchForm extends FormBase
/**
* {@inheritdoc}
*/
public function getFormId()
{
public function getFormId() {
return 'search_form';
}
/**
* {@inheritdoc}
*/
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)) {
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.
@ -57,40 +56,39 @@ class SearchForm extends FormBase
];
}
else {
$block = \Drupal\block\Entity\Block::load($this->block_id);
$block = Block::load($this->block_id);
if ($block) {
$settings = $block->get('settings');
$view_machine_name = $settings['search_view_machine_name'];
}
$form['search-textfield'] = array(
$form['search-textfield'] = [
'#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'))
'aria-label' => (isset($settings['search_textfield_label']) ? $this->t($settings['search_textfield_label']) : $this->t('Enter Keyword')),
],
'#theme_wrappers' => []
);
'#theme_wrappers' => [],
];
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => (!empty($settings['search_submit_label']) ? $settings['search_submit_label'] : 'Search'),
'#button_type' => 'primary',
);
];
}
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$block = \Drupal\block\Entity\Block::load($this->block_id);
public function submitForm(array &$form, FormStateInterface $form_state) {
$block = Block::load($this->block_id);
if ($block) {
$settings = $block->get('settings');
$view_machine_name = $settings['search_view_machine_name'];
@ -103,4 +101,5 @@ class SearchForm extends FormBase
]);
$form_state->setRedirectUrl($url);
}
}

View file

@ -28,7 +28,7 @@ class SettingsForm extends ConfigFormBase {
const DISPLAY_LIST_FLAG = 'list_on_off';
const DISPLAY_GRID_FLAG = 'grid_on_off';
const DISPLAY_DEFAULT = 'default-display-mode';
/**
* Constructs a \Drupal\system\ConfigFormBase object.
*
@ -91,7 +91,7 @@ class SettingsForm extends ConfigFormBase {
</ul>
</li>
</ul>'),
'#default_value' => isset($isEDismax) ? $isEDismax : 1,
'#default_value' => $isEDismax ?? 1,
];
$form['eDisMax']['textfields_container'] = [
@ -116,15 +116,14 @@ class SettingsForm extends ConfigFormBase {
'#default_value' => self::getConfig(self::EDISMAX_SEARCH_LABEL, "Keyword"),
];
$form['display-mode'] = [
$form['display-mode'] = [
'#type' => 'fieldset',
'#title' => $this->t("Pager Block"),
];
$form['display-mode']['pager-block-description'] = [
'#markup' => $this->t("Pager blocks are available in the Blocks interface for each Search API view. The following settings apply for all Pager blocks."),
];
$form['display-mode'][self::DISPLAY_LIST_FLAG] = [
'#type' => 'checkbox',
'#title' => $this
@ -145,7 +144,7 @@ class SettingsForm extends ConfigFormBase {
->t('Default view mode:'),
'#options' => [
'list' => 'List',
'grid' => 'Grid'
'grid' => 'Grid',
],
'#default_value' => self::getConfig(self::DISPLAY_DEFAULT, 'grid'),
];
@ -191,7 +190,6 @@ class SettingsForm extends ConfigFormBase {
],
],
];
return parent::buildForm($form, $form_state);
}