LanguageAddForm::form

public LanguageAddForm::form(array $form, FormStateInterface $form_state)

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

core/modules/language/src/Form/LanguageAddForm.php, line 26

Class

LanguageAddForm
Controller for language addition forms.

Namespace

Drupal\language\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form['#title'] = $this->t('Add language');

  $predefined_languages = $this->languageManager->getStandardLanguageListWithoutConfigured();

  $predefined_languages['custom'] = $this->t('Custom language...');
  $predefined_default = $form_state->getValue('predefined_langcode', key($predefined_languages));
  $form['predefined_langcode'] = array(
    '#type' => 'select',
    '#title' => $this->t('Language name'),
    '#default_value' => $predefined_default,
    '#options' => $predefined_languages,
  );
  $form['predefined_submit'] = array(
    '#type' => 'submit',
    '#value' => $this->t('Add language'),
    '#name' => 'add_language',
    '#limit_validation_errors' => array(array('predefined_langcode'), array('predefined_submit')),
    '#states' => array(
      'invisible' => array(
        'select#edit-predefined-langcode' => array('value' => 'custom'),
      ),
    ),
    '#validate' => array('::validatePredefined'),
    '#submit' => array('::submitForm', '::save'),
    '#button_type' => 'primary',
  );

  $custom_language_states_conditions = array(
    'select#edit-predefined-langcode' => array('value' => 'custom'),
  );
  $form['custom_language'] = array(
    '#type' => 'container',
    '#states' => array(
      'visible' => $custom_language_states_conditions,
    ),
  );
  $this->commonForm($form['custom_language']);
  $form['custom_language']['langcode']['#states'] = array(
    'required' => $custom_language_states_conditions,
  );
  $form['custom_language']['label']['#states'] = array(
    'required' => $custom_language_states_conditions,
  );
  $form['custom_language']['submit'] = array(
    '#type' => 'submit',
    '#value' => $this->t('Add custom language'),
    '#name' => 'add_custom_language',
    '#validate' => array('::validateCustom'),
    '#submit' => array('::submitForm', '::save'),
  );

  return $form;
}
doc_Drupal
2016-10-29 09:22:03
Comments
Leave a Comment

Please login to continue.