Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function buildRow(EntityInterface $entity)
 {
     /** @var FlagMapping $entity */
     $allLanguages = $this->languageManager->getAllDefinedLanguages();
     $id = $entity->getSource();
     $row['language'] = isset($allLanguages[$id]) ? $allLanguages[$id] : $id;
     $row['flag']['data'] = ['#theme' => 'flag', '#code' => strtolower($entity->getSource())];
     $row['info'] = $entity->getInfo();
     return $row + parent::buildRow($entity);
 }
Exemplo n.º 2
0
 /**
  * Overrides Drupal\Core\Entity\EntityFormController::form().
  *
  * Builds the entity add/edit form.
  *
  * @param array $form
  *   An associative array containing the structure of the form.
  * @param FormStateInterface $form_state
  *   An instance of FormStateInterface containing the current state of the form.
  *
  * @return array
  *   An associative array containing the FlagMapping add/edit form.
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     // Get anything we need from the base class.
     $form = parent::buildForm($form, $form_state);
     // Drupal provides the entity to us as a class variable. If this is an
     // existing entity, it will be populated with existing values as class
     // variables. If this is a new entity, it will be a new object with the
     // class of our entity. Drupal knows which class to call from the
     // annotation on our FlagMapping class.
     /** @var FlagMapping $mapping */
     $mapping = $this->entity;
     // Build the form.
     $form['info'] = ['#type' => 'textfield', '#title' => $this->t('Info'), '#maxlength' => 255, '#default_value' => $mapping->getInfo(), '#required' => TRUE];
     $form['source'] = ['#type' => 'select', '#title' => $this->t('Language'), '#default_value' => $mapping->getSource(), '#description' => $this->t('Select a source language.'), '#options' => $this->languageManager->getAllDefinedLanguages(), '#required' => TRUE];
     $countries = \Drupal::service('country_manager')->getList();
     $form['flag'] = ['#type' => 'select', '#title' => $this->t('Flag'), '#options' => $countries, '#empty_value' => '', '#default_value' => strtoupper($mapping->getFlag()), '#description' => $this->t('Select a target territory flag.'), '#required' => TRUE];
     // Return the form.
     return $form;
 }