You are here

class SiteNameProperty in Search API Field Map 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/search_api/processor/Property/SiteNameProperty.php \Drupal\search_api_field_map\Plugin\search_api\processor\Property\SiteNameProperty
  2. 8 src/Plugin/search_api/processor/Property/SiteNameProperty.php \Drupal\search_api_field_map\Plugin\search_api\processor\Property\SiteNameProperty
  3. 4.x 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

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 17

Namespace

Drupal\search_api_field_map\Plugin\search_api\processor\Property
View 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();

    // Create a link to the Basic Site Settings Page from route.
    $options = [
      'attributes' => [
        'target' => '_blank',
      ],
    ];
    $basic_site_settings_page_url = Url::fromRoute('system.site_information_settings', [], $options);
    $basic_site_settings_page_link = Link::fromTextAndUrl('Basic Site settings page', $basic_site_settings_page_url)
      ->toString();
    $form['#attached']['library'][] = 'search_api/drupal.search_api.admin_css';
    $form['#tree'] = TRUE;
    $form['site_name_group'] = [
      '#type' => 'fieldset',
      '#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.'),
    ];
    $form['site_name_group']['use_system_site_name'] = [
      '#type' => 'checkbox',
      '#title' => '<b>' . $this
        ->t('Use the site name from ' . $basic_site_settings_page_link . ' > Site Details > Site Name') . '</b>',
      '#default_value' => isset($configuration['use_system_site_name']) ? $configuration['use_system_site_name'] : 0,
      '#description' => $this
        ->t('This option is recommended for multisite installations that share config across sites.'),
      '#attributes' => [
        'data-use-system-site-name' => TRUE,
      ],
    ];
    $form['site_name_group']['site_name'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Site Name'),
      '#description' => $this
        ->t('Create a Site Name.'),
      '#default_value' => isset($configuration['site_name']) ? $configuration['site_name'] : '',
      '#states' => [
        'visible' => [
          ':input[data-use-system-site-name]' => [
            'checked' => FALSE,
          ],
        ],
      ],
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateConfigurationForm(FieldInterface $field, array &$form, FormStateInterface $form_state) {

    // Confirm that at least one field is populated.
    if (!$form_state
      ->getValue([
      'site_name_group',
      'use_system_site_name',
    ]) && !strlen($form_state
      ->getValue([
      'site_name_group',
      'site_name',
    ]))) {
      $form_state
        ->setError($form['site_name_group'], $this
        ->t('Please either select the option to use the system site name or enter a site name.'));
    }
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(FieldInterface $field, array &$form, FormStateInterface $form_state) {
    $values = [
      'use_system_site_name' => $form_state
        ->getValue([
        'site_name_group',
        'use_system_site_name',
      ]),
      'site_name' => $form_state
        ->getValue([
        'site_name_group',
        'site_name',
      ]),
    ];
    $field
      ->setConfiguration($values);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigurablePropertyBase::getFieldDescription public function Retrieves the description for a field based on this property. Overrides ConfigurablePropertyInterface::getFieldDescription 1
DataDefinition::$definition protected property The array holding values for all definition keys.
DataDefinition::addConstraint public function Adds a validation constraint. Overrides DataDefinitionInterface::addConstraint
DataDefinition::create public static function Creates a new data definition. 5
DataDefinition::createFromDataType public static function Creates a new data definition object. Overrides DataDefinitionInterface::createFromDataType 5
DataDefinition::getClass public function Returns the class used for creating the typed data object. Overrides DataDefinitionInterface::getClass 1
DataDefinition::getConstraint public function Returns a validation constraint. Overrides DataDefinitionInterface::getConstraint
DataDefinition::getConstraints public function Returns an array of validation constraints. Overrides DataDefinitionInterface::getConstraints 1
DataDefinition::getDataType public function Returns the data type of the data. Overrides DataDefinitionInterface::getDataType 2
DataDefinition::getDescription public function Returns a human readable description. Overrides DataDefinitionInterface::getDescription
DataDefinition::getLabel public function Returns a human readable label. Overrides DataDefinitionInterface::getLabel
DataDefinition::getSetting public function Returns the value of a given setting. Overrides DataDefinitionInterface::getSetting 2
DataDefinition::getSettings public function Returns the array of settings, as required by the used class. Overrides DataDefinitionInterface::getSettings 2
DataDefinition::isComputed public function Determines whether the data value is computed. Overrides DataDefinitionInterface::isComputed
DataDefinition::isInternal public function Determines whether the data value is internal. Overrides DataDefinitionInterface::isInternal 1
DataDefinition::isReadOnly public function Determines whether the data is read-only. Overrides DataDefinitionInterface::isReadOnly
DataDefinition::isRequired public function Determines whether a data value is required. Overrides DataDefinitionInterface::isRequired
DataDefinition::offsetExists public function This is for BC support only. @todo: Remove in https://www.drupal.org/node/1928868.
DataDefinition::offsetGet public function This is for BC support only. @todo: Remove in https://www.drupal.org/node/1928868.
DataDefinition::offsetSet public function This is for BC support only. @todo: Remove in https://www.drupal.org/node/1928868.
DataDefinition::offsetUnset public function This is for BC support only. @todo: Remove in https://www.drupal.org/node/1928868.
DataDefinition::setClass public function Sets the class used for creating the typed data object.
DataDefinition::setComputed public function Sets whether the data is computed.
DataDefinition::setConstraints public function Sets an array of validation constraints.
DataDefinition::setDataType public function Sets the data type. 1
DataDefinition::setDescription public function Sets the human-readable description.
DataDefinition::setInternal public function Sets the whether the data value should be internal.
DataDefinition::setLabel public function Sets the human-readable label.
DataDefinition::setReadOnly public function Sets whether the data is read-only.
DataDefinition::setRequired public function Sets whether the data is required.
DataDefinition::setSetting public function Sets a definition setting. 2
DataDefinition::setSettings public function Sets the array of settings, as required by the used class. 2
DataDefinition::toArray public function Returns all definition values as array.
DataDefinition::__construct public function Constructs a new data definition object. 1
DataDefinition::__sleep public function 2
ProcessorProperty::getProcessorId public function Retrieves the ID of the processor which defines this property. Overrides ProcessorPropertyInterface::getProcessorId
ProcessorProperty::isHidden public function Determines whether this property should be hidden from the UI. Overrides ProcessorPropertyInterface::isHidden
ProcessorProperty::isList public function Returns whether the data is multi-valued, i.e. a list of data items. Overrides DataDefinition::isList
SiteNameProperty::buildConfigurationForm public function Constructs a configuration form for a field based on this property. Overrides ConfigurablePropertyInterface::buildConfigurationForm
SiteNameProperty::defaultConfiguration public function Gets the default configuration for this property. Overrides ConfigurablePropertyBase::defaultConfiguration
SiteNameProperty::submitConfigurationForm public function Submits a configuration form for a field based on this property. Overrides ConfigurablePropertyBase::submitConfigurationForm
SiteNameProperty::validateConfigurationForm public function Validates a configuration form for a field based on this property. Overrides ConfigurablePropertyBase::validateConfigurationForm
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
TypedDataTrait::$typedDataManager protected property The typed data manager used for creating the data types.
TypedDataTrait::getTypedDataManager public function Gets the typed data manager. 2
TypedDataTrait::setTypedDataManager public function Sets the typed data manager. 2