class SiteNameProperty in Search API Field Map 4.x
Same name and namespace in other branches
- 8.3 src/Plugin/search_api/processor/Property/SiteNameProperty.php \Drupal\search_api_field_map\Plugin\search_api\processor\Property\SiteNameProperty
- 8 src/Plugin/search_api/processor/Property/SiteNameProperty.php \Drupal\search_api_field_map\Plugin\search_api\processor\Property\SiteNameProperty
- 8.2 src/Plugin/search_api/processor/Property/SiteNameProperty.php \Drupal\search_api_field_map\Plugin\search_api\processor\Property\SiteNameProperty
Defines a "site name" property.
Hierarchy
- class \Drupal\search_api_field_map\Plugin\search_api\processor\Property\SiteNameProperty extends \Drupal\search_api\Processor\ConfigurablePropertyBase uses StringTranslationTrait
Expanded class hierarchy of SiteNameProperty
See also
\Drupal\search_api\Plugin\search_api\processor\SiteName
1 file declares its use of SiteNameProperty
- SiteName.php in src/
Plugin/ search_api/ processor/ SiteName.php
File
- src/
Plugin/ search_api/ processor/ Property/ SiteNameProperty.php, line 15
Namespace
Drupal\search_api_field_map\Plugin\search_api\processor\PropertyView source
class SiteNameProperty extends ConfigurablePropertyBase {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'site_name' => [
\Drupal::config('system.site')
->get('name'),
],
];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(FieldInterface $field, array $form, FormStateInterface $form_state) {
$configuration = $field
->getConfiguration();
$form['#attached']['library'][] = 'search_api/drupal.search_api.admin_css';
$form['site_name'] = [
'#type' => 'textfield',
'#title' => $this
->t('Site Name'),
'#description' => $this
->t('The name of the site from which this content originated. This can be useful if indexing multiple sites with a single search index.'),
'#default_value' => $configuration['site_name'],
'#required' => TRUE,
];
if ($this
->useDomain()) {
$form['#tree'] = TRUE;
$form['domain'] = [
'#type' => 'container',
];
$storage = \Drupal::service('entity_type.manager')
->getStorage('domain');
$domains = $storage
->loadMultiple();
foreach ($domains as $domain) {
$form['domain'][$domain
->id()] = [
'#type' => 'textfield',
'#title' => $this
->t('%domain Domain Label', [
'%domain' => $domain
->label(),
]),
'#description' => t('Map the Domain to a custom label for search.'),
'#default_value' => !empty($configuration['domain'][$domain
->id()]) ? $configuration['domain'][$domain
->id()] : $domain
->label(),
'#required' => FALSE,
];
}
$form['site_name']['#title'] = $this
->t('Default site name');
}
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(FieldInterface $field, array &$form, FormStateInterface $form_state) {
$values = [
'site_name' => $form_state
->getValue('site_name'),
];
if ($domains = $form_state
->getValue('domain')) {
foreach ($domains as $id => $value) {
$values['domain'][$id] = $value;
}
}
$field
->setConfiguration($values);
}
/**
* Whether to use the values from Domain.
*
* @return bool
*/
protected function useDomain() {
return defined('DOMAIN_ADMIN_FIELD');
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SiteNameProperty:: |
public | function | ||
SiteNameProperty:: |
public | function | ||
SiteNameProperty:: |
public | function | ||
SiteNameProperty:: |
protected | function | Whether to use the values from Domain. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |