You are here

function EntityFieldQuery::options_form in EntityFieldQuery Views Backend 8

Show field language settings if the entity type we are querying has field translation enabled. If we are querying multiple entity types, then the settings are shown if at least one entity type has field translation enabled.

File

src/Plugin/views/query/EntityFieldQuery.php, line 91

Class

EntityFieldQuery
Views query plugin for an SQL query.

Namespace

Drupal\efq_views\Plugin\views\query

Code

function options_form(&$form, &$form_state) {
  if (isset($this->entity_type)) {
    $entities = array();
    $entities[$this->entity_type] = entity_get_info($this->entity_type);
  }
  else {
    $entities = entity_get_info();
  }
  $has_translation_handlers = FALSE;
  foreach ($entities as $type => $entity_info) {
    if (!empty($entity_info['translation'])) {
      $has_translation_handlers = TRUE;
    }
  }
  if ($has_translation_handlers) {
    $languages = array(
      '***CURRENT_LANGUAGE***' => t("Current user's language"),
      '***DEFAULT_LANGUAGE***' => t("Default site language"),
      LANGUAGE_NONE => t('No language'),
    );
    $languages = array_merge($languages, locale_language_list());
    $form['field_language'] = array(
      '#type' => 'select',
      '#title' => t('Field Language'),
      '#description' => t('All fields which support translations will be displayed in the selected language.'),
      '#options' => $languages,
      '#default_value' => $this->options['field_language'],
    );
  }
  $form['query_tags'] = array(
    '#type' => 'textfield',
    '#title' => t('Query Tags'),
    '#description' => t('If set, these tags will be appended to the query and can be used to identify the query in a module. This can be helpful for altering queries.'),
    '#default_value' => implode(', ', $this->options['query_tags']),
    '#element_validate' => array(
      'views_element_validate_tags',
    ),
  );

  // The function views_element_validate_tags() is defined here.
  form_load_include($form_state, 'inc', 'views', 'plugins/views_plugin_query_default');
}