/**
  * @inheritDoc
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateForm($form, $form_state);
     // Check if config entity that's being created already exists.
     $id = 'flags_languages.flag_mapping.' . $form_state->getValue('source');
     if (!$this->config($id)->isNew()) {
         $form_state->setErrorByName('source', $this->t('Mapping for this language already exists.'));
     }
 }
 /**
  * @inheritDoc
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     /** @var FlagMapping $mapping */
     $mapping = $this->entity;
     $allLanguages = $this->languageManager->getAllDefinedLanguages();
     $id = $mapping->getSource();
     $form['title'] = ['#type' => 'item', '#markup' => isset($allLanguages[$id]) ? $allLanguages[$id] : $id];
     $form = parent::buildForm($form, $form_state);
     // We do not allow editing of source language which is entity's ID.
     $form['source'] = ['#type' => 'value', '#value' => $mapping->getSource()];
     return $form;
 }