You are here

public function CustomLanguageForm::form in Custom Language field 8

Gets the actual form array to be built.

Overrides EntityForm::form

See also

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

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

File

src/Form/CustomLanguageForm.php, line 20

Class

CustomLanguageForm
Form controller for the CustomLanguage entity edit forms.

Namespace

Drupal\languagefield\Form

Code

public function form(array $form, FormStateInterface $form_state) {

  /** @var \Drupal\languagefield\Entity\CustomLanguageInterface $entity */
  $entity = $this->entity;
  if ($entity
    ->isNew()) {
    $form['langcode'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Language code'),
      '#default_value' => '',
      '#size' => 10,
      '#required' => TRUE,
      '#maxlength' => 10,
      '#description' => $this
        ->t('Use language codes as <a href=":w3ctags">defined by the W3C</a> for interoperability. <em>Examples: "en", "en-gb" and "zh-hant".</em>', [
        ':w3ctags' => 'http://www.w3.org/International/articles/language-tags/',
      ]),
    ];
  }
  else {
    $form['langcode_view'] = [
      '#type' => 'item',
      '#title' => $this
        ->t('Language code'),
      '#markup' => $entity
        ->id(),
    ];
    $form['langcode'] = [
      '#type' => 'value',
      '#value' => $entity
        ->id(),
    ];
  }
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Language name'),
    '#default_value' => $entity
      ->label(),
    '#size' => 30,
    '#required' => TRUE,
    '#maxlength' => 64,
  ];
  $form['native_name'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Native Name'),
    '#default_value' => $entity
      ->getNativeName(),
    '#size' => 30,
    '#required' => TRUE,
    '#maxlength' => 64,
  ];
  return parent::form($form, $form_state);
}