Commit 7a10472a authored by Munavijayalakshmi's avatar Munavijayalakshmi Committed by borisson_

Issue #2880301 by Munavijayalakshmi: Convert module to use short array syntax (new coding standard)

parent 637550f4
......@@ -51,11 +51,11 @@ function core_search_facets_form_facet_source_edit_form_alter(&$form, FormStateI
$request = \Drupal::requestStack()->getMasterRequest();
$facet_source_id = str_replace(":", "__", $request->attributes->get('facets_facet_source'));
if (strpos($facet_source_id, 'core_node_search') !== FALSE) {
$form['advanced_filters'] = array(
$form['advanced_filters'] = [
'#type' => 'checkbox',
'#title' => t('Show Advanced Filters.'),
'#default_value' => \Drupal::config("facets.facet_source.{$facet_source_id}")->get('third_party_settings.core_search_facets.advanced_filters'),
);
];
$form['#entity_builders'][] = 'core_search_facets_facet_source_form_form_builder';
}
}
......
......@@ -74,7 +74,7 @@ class FacetsQuery extends SearchQuery {
->groupBy('value')
->groupBy('i.type')
->groupBy('i.sid')
->having('COUNT(*) >= :matches', array(':matches' => $this->matches));
->having('COUNT(*) >= :matches', [':matches' => $this->matches]);
// For complex search queries, add the LIKE conditions.
/*if (!$this->simple) {
......@@ -93,7 +93,7 @@ class FacetsQuery extends SearchQuery {
// Adds subquery to group the results in the r table.
$subquery = \Drupal::database()->select($this->query, 'r')
->fields('r', array('value'))
->fields('r', ['value'])
->groupBy('r.value');
// Adds COUNT() expression to get facet counts.
......
......@@ -19,110 +19,110 @@ class NodeSearchFacets extends NodeSearch {
$keys = $this->getKeywords();
$used_advanced = !empty($parameters[self::ADVANCED_FORM]);
if ($used_advanced) {
$f = isset($parameters['f']) ? (array) $parameters['f'] : array();
$f = isset($parameters['f']) ? (array) $parameters['f'] : [];
$defaults = $this->parseAdvancedDefaults($f, $keys);
}
else {
$defaults = array('keys' => $keys);
$defaults = ['keys' => $keys];
}
$form['basic']['keys']['#default_value'] = $defaults['keys'];
// Add advanced search keyword-related boxes.
$form['advanced'] = array(
$form['advanced'] = [
'#type' => 'details',
'#title' => t('Advanced search'),
'#attributes' => array('class' => array('search-advanced')),
'#attributes' => ['class' => ['search-advanced']],
'#access' => $this->account && $this->account->hasPermission('use advanced search'),
'#open' => $used_advanced,
);
];
$form['advanced']['keywords-fieldset'] = array(
$form['advanced']['keywords-fieldset'] = [
'#type' => 'fieldset',
'#title' => t('Keywords'),
);
];
$form['advanced']['keywords'] = array(
$form['advanced']['keywords'] = [
'#prefix' => '<div class="criterion">',
'#suffix' => '</div>',
);
];
$form['advanced']['keywords-fieldset']['keywords']['or'] = array(
$form['advanced']['keywords-fieldset']['keywords']['or'] = [
'#type' => 'textfield',
'#title' => t('Containing any of the words'),
'#size' => 30,
'#maxlength' => 255,
'#default_value' => isset($defaults['or']) ? $defaults['or'] : '',
);
];
$form['advanced']['keywords-fieldset']['keywords']['phrase'] = array(
$form['advanced']['keywords-fieldset']['keywords']['phrase'] = [
'#type' => 'textfield',
'#title' => t('Containing the phrase'),
'#size' => 30,
'#maxlength' => 255,
'#default_value' => isset($defaults['phrase']) ? $defaults['phrase'] : '',
);
];
$form['advanced']['keywords-fieldset']['keywords']['negative'] = array(
$form['advanced']['keywords-fieldset']['keywords']['negative'] = [
'#type' => 'textfield',
'#title' => t('Containing none of the words'),
'#size' => 30,
'#maxlength' => 255,
'#default_value' => isset($defaults['negative']) ? $defaults['negative'] : '',
);
];
$form['advanced']['submit'] = array(
$form['advanced']['submit'] = [
'#type' => 'submit',
'#value' => t('Advanced search'),
'#prefix' => '<div class="action">',
'#suffix' => '</div>',
'#weight' => 100,
);
];
if (\Drupal::config("facets.facet_source.core_node_search__{$this->searchPageId}")->get('third_party_settings.core_search_facets.advanced_filters')) {
// Add node types.
$types = array_map(array('\Drupal\Component\Utility\Html', 'escape'), node_type_get_names());
$form['advanced']['types-fieldset'] = array(
$types = array_map(['\Drupal\Component\Utility\Html', 'escape'], node_type_get_names());
$form['advanced']['types-fieldset'] = [
'#type' => 'fieldset',
'#title' => t('Types'),
);
$form['advanced']['types-fieldset']['type'] = array(
];
$form['advanced']['types-fieldset']['type'] = [
'#type' => 'checkboxes',
'#title' => t('Only of the type(s)'),
'#prefix' => '<div class="criterion">',
'#suffix' => '</div>',
'#options' => $types,
'#default_value' => isset($defaults['type']) ? $defaults['type'] : array(),
);
'#default_value' => isset($defaults['type']) ? $defaults['type'] : [],
];
$form['advanced']['submit'] = array(
$form['advanced']['submit'] = [
'#type' => 'submit',
'#value' => t('Advanced search'),
'#prefix' => '<div class="action">',
'#suffix' => '</div>',
'#weight' => 100,
);
];
// Add languages.
$language_options = array();
$language_options = [];
$language_list = $this->languageManager->getLanguages(LanguageInterface::STATE_ALL);
foreach ($language_list as $langcode => $language) {
// Make locked languages appear special in the list.
$language_options[$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->getName())) : $language->getName();
$language_options[$langcode] = $language->isLocked() ? t('- @name -', ['@name' => $language->getName()]) : $language->getName();
}
if (count($language_options) > 1) {
$form['advanced']['lang-fieldset'] = array(
$form['advanced']['lang-fieldset'] = [
'#type' => 'fieldset',
'#title' => t('Languages'),
);
$form['advanced']['lang-fieldset']['language'] = array(
];
$form['advanced']['lang-fieldset']['language'] = [
'#type' => 'checkboxes',
'#title' => t('Languages'),
'#prefix' => '<div class="criterion">',
'#suffix' => '</div>',
'#options' => $language_options,
'#default_value' => isset($defaults['language']) ? $defaults['language'] : array(),
);
'#default_value' => isset($defaults['language']) ? $defaults['language'] : [],
];
}
}
}
......
......@@ -143,10 +143,10 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
*/
public function fillFacetsWithResults(array $facets) {
foreach ($facets as $facet) {
$configuration = array(
$configuration = [
'query' => NULL,
'facet' => $facet,
);
];
// Get the Facet Specific Query Type so we can process the results
// using the build() function of the query type.
......@@ -240,7 +240,7 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
$facet_fields = $this->getDefaultFields();
// Get the allowed field types.
$allowed_field_types = $this->moduleHandler->invokeAll('facets_core_allowed_field_types', array($field_types = []));
$allowed_field_types = $this->moduleHandler->invokeAll('facets_core_allowed_field_types', [$field_types = []]);
// Get the current field instances and detect if the field type is allowed.
$fields = FieldConfig::loadMultiple();
......@@ -283,7 +283,7 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
public function getFacetQueryExtender() {
if (!$this->facetQueryExtender) {
$this->facetQueryExtender = $this->database
->select('search_index', 'i', array('target' => 'replica'))
->select('search_index', 'i', ['target' => 'replica'])
->extend('Drupal\core_search_facets\FacetsQuery');
$this->facetQueryExtender->join('node_field_data', 'n', 'n.nid = i.sid AND n.langcode = i.langcode');
$this->facetQueryExtender
......@@ -332,19 +332,19 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
$column = $facet->getFieldIdentifier() . '_value';
}
$query_info['fields'][$field_name . '.' . $column] = array(
$query_info['fields'][$field_name . '.' . $column] = [
'table_alias' => $table,
'field' => $column,
);
];
// Adds the join on the node table.
$query_info['joins'] = array(
$table => array(
$query_info['joins'] = [
$table => [
'table' => $table,
'alias' => $table,
'condition' => "n.vid = $table.revision_id AND i.langcode = $table.langcode",
),
);
],
];
}
// Returns query info, makes sure all keys are present.
......
......@@ -30,7 +30,7 @@ class RangeSliderProcessor extends SliderProcessor implements PreQueryProcessorI
array_walk($active_items, function (&$item) {
if (preg_match('/\(min:((?:-)?[\d\.]+),max:((?:-)?[\d\.]+)\)/i', $item, $matches)) {
$item = array($matches[1], $matches[2]);
$item = [$matches[1], $matches[2]];
}
else {
$item = NULL;
......
......@@ -193,10 +193,10 @@ class FacetsSummary extends ConfigEntityBase implements FacetsSummaryInterface {
}
elseif (!class_exists($processor_definition['class'])) {
\Drupal::logger('facets_summary')
->warning('Processor @id specifies a non-existing @class.', array(
->warning('Processor @id specifies a non-existing @class.', [
'@id' => $name,
'@class' => $processor_definition['class'],
));
]);
}
}
}
......@@ -232,7 +232,7 @@ class FacetsSummary extends ConfigEntityBase implements FacetsSummaryInterface {
public function getProcessorsByStage($stage, $only_enabled = TRUE) {
$processors = $this->getProcessors($only_enabled);
$processor_settings = $this->getProcessorConfigs();
$processor_weights = array();
$processor_weights = [];
// Get a list of all processors for given stage.
foreach ($processors as $name => $processor) {
......@@ -249,7 +249,7 @@ class FacetsSummary extends ConfigEntityBase implements FacetsSummaryInterface {
// Sort requested processors by weight.
asort($processor_weights);
$return_processors = array();
$return_processors = [];
foreach ($processor_weights as $name => $weight) {
$return_processors[$name] = $processors[$name];
}
......
......@@ -108,12 +108,12 @@ class DefaultFacetsSummaryManager {
$this->facetManager->build($facet);
}
$build = array(
$build = [
'#theme' => 'facets_summary_item_list',
'#attributes' => array(
'#attributes' => [
'data-drupal-facets-summary-id' => $facets_summary->id(),
),
);
],
];
$results = [];
......
......@@ -15,7 +15,7 @@ class FacetsSummaryDeleteConfirmForm extends EntityConfirmFormBase {
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete the facet summary %name?', array('%name' => $this->entity->label()));
return $this->t('Are you sure you want to delete the facet summary %name?', ['%name' => $this->entity->label()]);
}
/**
......@@ -44,7 +44,7 @@ class FacetsSummaryDeleteConfirmForm extends EntityConfirmFormBase {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity->delete();
drupal_set_message($this->t('The facet summary %name has been deleted.', array('%name' => $this->entity->label())));
drupal_set_message($this->t('The facet summary %name has been deleted.', ['%name' => $this->entity->label()]));
$form_state->setRedirect('facets.overview');
}
......
......@@ -117,7 +117,7 @@ class FacetsSummaryForm extends EntityForm {
$form['#tree'] = TRUE;
$form['#attached']['library'][] = 'facets/drupal.facets.index-active-formatters';
$form['#title'] = $this->t('Edit %label facets summary', array('%label' => $facets_summary->label()));
$form['#title'] = $this->t('Edit %label facets summary', ['%label' => $facets_summary->label()]);
$form['facets'] = [
'#type' => 'table',
......@@ -200,68 +200,68 @@ class FacetsSummaryForm extends EntityForm {
$enabled_processors = $facets_summary->getProcessors(TRUE);
$stages = $this->processorPluginManager->getProcessingStages();
$processors_by_stage = array();
$processors_by_stage = [];
foreach ($stages as $stage => $definition) {
$processors_by_stage[$stage] = $facets_summary->getProcessorsByStage($stage, FALSE);
}
// Add the list of all other processors with checkboxes to enable/disable
// them.
$form['facets_summary_settings'] = array(
$form['facets_summary_settings'] = [
'#type' => 'fieldset',
'#title' => $this->t('Facets Summary settings'),
'#attributes' => array(
'class' => array(
'#attributes' => [
'class' => [
'search-api-status-wrapper',
),
),
);
],
],
];
foreach ($all_processors as $processor_id => $processor) {
$clean_css_id = Html::cleanCssIdentifier($processor_id);
$form['facets_summary_settings'][$processor_id]['status'] = array(
$form['facets_summary_settings'][$processor_id]['status'] = [
'#type' => 'checkbox',
'#title' => (string) $processor->getPluginDefinition()['label'],
'#default_value' => !empty($enabled_processors[$processor_id]),
'#description' => $processor->getDescription(),
'#attributes' => array(
'class' => array(
'#attributes' => [
'class' => [
'search-api-processor-status-' . $clean_css_id,
),
],
'data-id' => $clean_css_id,
),
);
],
];
$form['facets_summary_settings'][$processor_id]['settings'] = [];
$processor_form_state = SubformState::createForSubform($form['facets_summary_settings'][$processor_id]['settings'], $form, $form_state);
$processor_form = $processor->buildConfigurationForm($form, $processor_form_state, $facets_summary);
if ($processor_form) {
$form['facets_summary_settings'][$processor_id]['settings'] = array(
$form['facets_summary_settings'][$processor_id]['settings'] = [
'#type' => 'details',
'#title' => $this->t('%processor settings', ['%processor' => (string) $processor->getPluginDefinition()['label']]),
'#open' => TRUE,
'#attributes' => array(
'class' => array(
'#attributes' => [
'class' => [
'facets-processor-settings-' . Html::cleanCssIdentifier($processor_id),
'facets-processor-settings-facet',
'facets-processor-settings',
),
),
'#states' => array(
'visible' => array(
':input[name="facets_summary_settings[' . $processor_id . '][status]"]' => array('checked' => TRUE),
),
),
);
],
],
'#states' => [
'visible' => [
':input[name="facets_summary_settings[' . $processor_id . '][status]"]' => ['checked' => TRUE],
],
],
];
$form['facets_summary_settings'][$processor_id]['settings'] += $processor_form;
}
}
$form['weights'] = array(
$form['weights'] = [
'#type' => 'details',
'#title' => $this->t('Advanced settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
];
$form['weights']['order'] = [
'#prefix' => '<h3>',
......@@ -272,24 +272,24 @@ class FacetsSummaryForm extends EntityForm {
// Order enabled processors per stage, create all the containers for the
// different stages.
foreach ($stages as $stage => $description) {
$form['weights'][$stage] = array(
$form['weights'][$stage] = [
'#type' => 'fieldset',
'#title' => $description['label'],
'#attributes' => array(
'class' => array(
'#attributes' => [
'class' => [
'search-api-stage-wrapper',
'search-api-stage-wrapper-' . Html::cleanCssIdentifier($stage),
),
),
);
$form['weights'][$stage]['order'] = array(
],
],
];
$form['weights'][$stage]['order'] = [
'#type' => 'table',
);
$form['weights'][$stage]['order']['#tabledrag'][] = array(
];
$form['weights'][$stage]['order']['#tabledrag'][] = [
'action' => 'order',
'relationship' => 'sibling',
'group' => 'search-api-processor-weight-' . Html::cleanCssIdentifier($stage),
);
];
}
$processor_settings = $facets_summary->getProcessorConfigs();
......@@ -303,38 +303,38 @@ class FacetsSummaryForm extends EntityForm {
? $processor_settings[$processor_id]['weights'][$stage]
: $processor->getDefaultWeight($stage);
if ($processor->isHidden()) {
$form['processors'][$processor_id]['weights'][$stage] = array(
$form['processors'][$processor_id]['weights'][$stage] = [
'#type' => 'value',
'#value' => $weight,
);
];
continue;
}
$form['weights'][$stage]['order'][$processor_id]['#attributes']['class'][] = 'draggable';
$form['weights'][$stage]['order'][$processor_id]['#attributes']['class'][] = 'search-api-processor-weight--' . Html::cleanCssIdentifier($processor_id);
$form['weights'][$stage]['order'][$processor_id]['#weight'] = $weight;
$form['weights'][$stage]['order'][$processor_id]['label']['#plain_text'] = (string) $processor->getPluginDefinition()['label'];
$form['weights'][$stage]['order'][$processor_id]['weight'] = array(
$form['weights'][$stage]['order'][$processor_id]['weight'] = [
'#type' => 'weight',
'#title' => $this->t('Weight for processor %title', array('%title' => (string) $processor->getPluginDefinition()['label'])),
'#title' => $this->t('Weight for processor %title', ['%title' => (string) $processor->getPluginDefinition()['label']]),
'#title_display' => 'invisible',
'#default_value' => $weight,
'#parents' => array('processors', $processor_id, 'weights', $stage),
'#attributes' => array(
'class' => array(
'#parents' => ['processors', $processor_id, 'weights', $stage],
'#attributes' => [
'class' => [
'search-api-processor-weight-' . Html::cleanCssIdentifier($stage),
),
),
);
],
],
];
}
}
// Add vertical tabs containing the settings for the processors. Tabs for
// disabled processors are hidden with JS magic, but need to be included in
// case the processor is enabled.
$form['processor_settings'] = array(
$form['processor_settings'] = [
'#title' => $this->t('Processor settings'),
'#type' => 'vertical_tabs',
);
];
return $form;
}
......@@ -383,11 +383,11 @@ class FacetsSummaryForm extends EntityForm {
continue;
}
$new_settings = array(
$new_settings = [
'processor_id' => $processor_id,
'weights' => array(),
'settings' => array(),
);
'weights' => [],
'settings' => [],
];
if (!empty($values['processors'][$processor_id]['weights'])) {
$new_settings['weights'] = $values['processors'][$processor_id]['weights'];
......
......@@ -65,12 +65,12 @@ class ShowTextWhenEmptyProcessor extends ProcessorPluginBase implements BuildPro
* {@inheritdoc}
*/
public function defaultConfiguration() {
return array(
'text' => array(
return [
'text' => [
'format' => 'plain_text',
'value' => $this->t('There is no current search in progress.'),
),
);
],
];
}
/**
......
......@@ -42,11 +42,11 @@ class ProcessorPluginManager extends DefaultPluginManager {
* - label: The translated label for this stage.
*/
public function getProcessingStages() {
return array(
ProcessorInterface::STAGE_BUILD => array(
return [
ProcessorInterface::STAGE_BUILD => [
'label' => $this->t('Build stage'),
),
);
],
];
}
}
......@@ -45,11 +45,11 @@ class RestIntegrationTest extends FacetsTestBase {
// and thus removed from the test index. (We can't do it in setUp(), before
// calling the parent method, since the container isn't set up at that
// point.)
$bundles = array(
'entity_test_mulrev_changed' => array('label' => 'Entity Test Bundle'),
'item' => array('label' => 'item'),
'article' => array('label' => 'article'),
);
$bundles = [
'entity_test_mulrev_changed' => ['label' => 'Entity Test Bundle'],
'item' => ['label' => 'item'],
'article' => ['label' => 'article'],
];
\Drupal::state()->set('entity_test_mulrev_changed.bundles', $bundles);
parent::installModulesFromClassProperty($container);
......
......@@ -35,7 +35,7 @@ class FacetController extends ControllerBase {
* The page title.
*/
public function pageTitle(FacetInterface $facet) {
return new FormattableMarkup('@title', array('@title' => $facet->label()));
return new FormattableMarkup('@title', ['@title' => $facet->label()]);
}
}
......@@ -422,10 +422,10 @@ class Facet extends ConfigEntityBase implements FacetInterface {
}
elseif (!class_exists($processor_definition['class'])) {
\Drupal::logger('facets')
->warning('Processor @id specifies a non-existing @class.', array(