You are here

public function SiteNameProperty::buildConfigurationForm in Search API Field Map 8

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::buildConfigurationForm()
  2. 8.2 src/Plugin/search_api/processor/Property/SiteNameProperty.php \Drupal\search_api_field_map\Plugin\search_api\processor\Property\SiteNameProperty::buildConfigurationForm()
  3. 4.x src/Plugin/search_api/processor/Property/SiteNameProperty.php \Drupal\search_api_field_map\Plugin\search_api\processor\Property\SiteNameProperty::buildConfigurationForm()

Constructs a configuration form for a field based on this property.

Parameters

\Drupal\search_api\Item\FieldInterface $field: The field for which the configuration form is constructed.

array $form: An associative array containing the initial structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the complete form.

Return value

array The form structure.

Overrides ConfigurablePropertyInterface::buildConfigurationForm

File

src/Plugin/search_api/processor/Property/SiteNameProperty.php, line 31

Class

SiteNameProperty
Defines a "site name" property.

Namespace

Drupal\search_api_field_map\Plugin\search_api\processor\Property

Code

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;
}