public function ConfigSourcePluginUi::overviewSearchFormPart

Builds search form for entity sources overview.

Parameters

array $form: Drupal form array.

FormStateInterface $form_state: Drupal form_state array.

string $type: Entity type.

Return value

array Drupal form array.

Overrides SourcePluginUiBase::overviewSearchFormPart

File

sources/tmgmt_config/src/ConfigSourcePluginUi.php, line 31

Class

ConfigSourcePluginUi
Config source plugin UI.

Namespace

Drupal\tmgmt_config

Code

public function overviewSearchFormPart(array $form, FormStateInterface $form_state, $type) {
  $form = parent::overviewSearchFormPart($form, $form_state, $type);
  if ($type == ConfigSource::SIMPLE_CONFIG) {
    $label_key = 'name';
    $label = t('Simple configuration');
  }
  else {
    $entity_type = \Drupal::entityTypeManager()
      ->getDefinition($type);
    $label_key = $entity_type
      ->getKey('label');
    $label = $entity_type
      ->getLabel();
  }
  if (!empty($label_key)) {
    $form['search_wrapper']['search'][$label_key] = array(
      '#type' => 'textfield',
      '#title' => t('@entity_name title', array(
        '@entity_name' => $label,
      )),
      '#size' => 25,
      '#default_value' => isset($_GET[$label_key]) ? $_GET[$label_key] : NULL,
    );
  }
  $form['search_wrapper']['search']['langcode'] = array(
    '#type' => 'language_select',
    '#title' => t('Source Language'),
    '#empty_option' => t('- Any -'),
    '#default_value' => isset($_GET['langcode']) ? $_GET['langcode'] : NULL,
  );
  $form['search_wrapper']['search']['target_language'] = array(
    '#type' => 'language_select',
    '#title' => $this
      ->t('Target language'),
    '#empty_option' => $this
      ->t('- Any -'),
    '#default_value' => isset($_GET['target_language']) ? $_GET['target_language'] : NULL,
  );
  $form['search_wrapper']['search']['target_status'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Target status'),
    '#options' => array(
      'untranslated' => $this
        ->t('Untranslated'),
      'translated' => $this
        ->t('Translated'),
    ),
    '#default_value' => isset($_GET['target_status']) ? $_GET['target_status'] : NULL,
    '#states' => array(
      'invisible' => array(
        ':input[name="search[target_language]"]' => array(
          'value' => '',
        ),
      ),
    ),
  );
  return $form;
}