public function CustomSearchBlock::defaultConfiguration in Custom Search 8
Overrides BlockPluginTrait::defaultConfiguration
File
- src/
Plugin/ Block/ CustomSearchBlock.php, line 87
Class
- CustomSearchBlock
- Provides a 'Custom Search form' block.
Namespace
Drupal\custom_search\Plugin\BlockCode
public function defaultConfiguration() {
$defaults = [
'search_box' => [
'label_visibility' => FALSE,
'label' => $this
->t('Search this site'),
'placeholder' => '',
'title' => $this
->t('Enter the terms you wish to search for.'),
'size' => 15,
'max_length' => 128,
'weight' => -9,
'region' => 'block',
],
'submit' => [
'text' => $this
->t('Search'),
'image_path' => '',
'weight' => 9,
'region' => 'block',
],
'content' => [
'types' => [],
'other' => [],
'selector' => [
'type' => 'select',
'label_visibility' => TRUE,
'label' => $this
->t('Search for'),
],
'any' => [
'text' => $this
->t('- Any -'),
'restricts' => FALSE,
'force' => FALSE,
],
'excluded' => [],
'weight' => -8,
'region' => 'block',
],
'criteria' => [
'or' => [
'display' => FALSE,
'label' => $this
->t('Containing any of the words'),
'weight' => 4,
'region' => 'block',
],
'phrase' => [
'display' => FALSE,
'label' => $this
->t('Containing the phrase'),
'weight' => 5,
'region' => 'block',
],
'negative' => [
'display' => FALSE,
'label' => $this
->t('Containing none of the words'),
'weight' => 6,
'region' => 'block',
],
],
'languages' => [
'languages' => [],
'selector' => [
'type' => 'select',
'label_visibility' => TRUE,
'label' => $this
->t('Languages'),
],
'any' => [
'text' => $this
->t('- Any -'),
'restricts' => FALSE,
'force' => FALSE,
],
'weight' => 7,
'region' => 'block',
],
'paths' => [
'list' => '',
'selector' => [
'type' => 'select',
'label_visibility' => TRUE,
'label' => $this
->t('Customize your search'),
],
'separator' => '+',
'weight' => 8,
'region' => 'block',
],
];
$search_pages = \Drupal::entityTypeManager()
->getStorage('search_page')
->loadMultiple();
foreach ($search_pages as $page) {
if ($page
->getPlugin()
->getPluginId() == 'node_search' && $page
->isDefaultSearch()) {
$defaults['content']['page'] = $page
->id();
break;
}
}
$vocabularies = \Drupal::entityTypeManager()
->getStorage('search_page')
->loadMultiple();
$vocWeight = -7;
foreach ($vocabularies as $voc) {
$vocId = $voc
->id();
$defaults['taxonomy'][$vocId]['type'] = 'disabled';
$defaults['taxonomy'][$vocId]['depth'] = 0;
$defaults['taxonomy'][$vocId]['label_visibility'] = TRUE;
$defaults['taxonomy'][$vocId]['label'] = $voc
->label();
$defaults['taxonomy'][$vocId]['all_text'] = t('- Any -');
$defaults['taxonomy'][$vocId]['region'] = 'block';
$defaults['taxonomy'][$vocId]['weight'] = $vocWeight;
$vocWeight++;
}
return $defaults;
}