You are here

public function SearchApiAlterAddViewedEntity::configurationForm in Search API 7

Implements SearchApiAlterCallbackInterface::configurationForm().

Overrides SearchApiAbstractAlterCallback::configurationForm

File

includes/callback_add_viewed_entity.inc, line 22
Contains SearchApiAlterAddViewedEntity.

Class

SearchApiAlterAddViewedEntity
Search API data alteration callback that adds an URL field for all items.

Code

public function configurationForm() {
  $view_modes = array();
  if ($entity_type = $this->index
    ->getEntityType()) {
    $info = entity_get_info($entity_type);
    foreach ($info['view modes'] as $key => $mode) {
      $view_modes[$key] = $mode['label'];
    }
  }
  $this->options += array(
    'mode' => reset($view_modes),
    // Backward compatible definition - if this is an existing config the
    // language processing is disabled by default.
    'global_language_switch' => !isset($this->options['mode']),
  );
  if (count($view_modes) > 1) {
    $form['mode'] = array(
      '#type' => 'select',
      '#title' => t('View mode'),
      '#options' => $view_modes,
      '#default_value' => $this->options['mode'],
    );
  }
  else {
    $form['mode'] = array(
      '#type' => 'value',
      '#value' => $this->options['mode'],
    );
    if ($view_modes) {
      $form['note'] = array(
        '#markup' => '<p>' . t('Entities of type %type have only a single view mode. ' . 'Therefore, no selection needs to be made.', array(
          '%type' => $info['label'],
        )) . '</p>',
      );
    }
    else {
      $form['note'] = array(
        '#markup' => '<p>' . t('Entities of type %type have no defined view modes. ' . 'This might either mean that they are always displayed the same way, or that they cannot be processed by this alteration at all. ' . 'Please consider this when using this alteration.', array(
          '%type' => $info['label'],
        )) . '</p>',
      );
    }
  }
  $form['global_language_switch'] = array(
    '#type' => 'checkbox',
    '#title' => t('Adjust environment language when indexing'),
    '#description' => t('If enabled, the indexing process will not just set the language for the entity view but also the global environment. This can prevent wrong translations leaking into the indexed data on multi-lingual sites, but causes problems in rare cases. Unless you notice any problems in connection with this, the recommended setting is enabled.'),
    '#default_value' => !empty($this->options['global_language_switch']),
  );
  return $form;
}