You are here

public function SelectTranslation::buildOptionsForm in Select translation 8

Returns a form with configurable options.

Overrides FilterPluginBase::buildOptionsForm

File

src/Plugin/views/filter/SelectTranslation.php, line 63

Class

SelectTranslation
Views select translation filter handler.

Namespace

Drupal\select_translation\Plugin\views\filter

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $form['mode'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Select translation selection mode'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
  ];
  $form['value'] = [
    '#fieldset' => 'mode',
    '#type' => 'radios',
    '#options' => [
      'original' => $this
        ->t('Use the current interface language; if not available use the original node language'),
      'default' => $this
        ->t('Use the current interface language; if not available use the default site language; if not available use the original node language'),
      'list' => $this
        ->t('Custom language priorities'),
    ],
    '#default_value' => $this->value,
  ];
  $form['priorities'] = [
    '#fieldset' => 'mode',
    '#type' => 'textfield',
    '#title' => $this
      ->t('Language priorities'),
    '#description' => $this
      ->t('<p>If the selection mode is set to "Custom language priorities",
                           a comma separated list of language codes can be specified.<br/>
                           The filter will then return the node in the first available language
                           in that list; falling back to the original node language if no match was found.</p>
                           Some special values are recognized:
                           <ul>
                             <li>"<em>current</em>" will be replaced with the current interface language;</li>
                             <li>"<em>default</em>" will be replaced with the default site language;</li>
                             <li>"<em>original</em>" will be replaced with the original node language.</li>
                            </ul>
                           Example:<br/><em>en,fr,current,default,original</em><br/>
                           This will return:
                           <ol>
                             <li>the version in English, if available;</li>
                             <li>if not, then the version in French, if available;</li>
                             <li>if not, then the version in the current interface language, if available;</li>
                             <li>if not, then the version in the default site language, if available;</li>
                             <li>if none are available it will return the original node version.</li>
                          </ol>'),
    '#default_value' => !empty($this->options['priorities']) ? $this->options['priorities'] : '',
    '#states' => [
      'enabled' => [
        ':input[name="options[value]"]' => [
          'value' => 'list',
        ],
      ],
    ],
  ];
  $form['default_language_only'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display default language content *only*, if the currently selected user language is the default site language.'),
    '#description' => $this
      ->t("When you check this option, the order chosen above will be ignored when current language = site default language,\n        instead it will only show translations for the default language. "),
    '#default_value' => !empty($this->options['default_language_only']) ? $this->options['default_language_only'] : 0,
  ];
  $form['include_content_with_unpublished_translation'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Return content in the site default language when a translation for the current language *does* exist, but it is unpublished.'),
    '#description' => $this
      ->t('When you check this option, in addition to the order chosen above, content will be shown in the default site language in the event that the translation in the current language is unpublished.<br/>
      <strong>NOTE</strong>: This option assumes that the view is already filtering out unpublished content with the <code>Published (=Yes)</code> criterion, otherwise both the published and unpublished node will be displayed.'),
    '#default_value' => !empty($this->options['include_content_with_unpublished_translation']) ? $this->options['include_content_with_unpublished_translation'] : 0,
  ];
}