LanguageListController.php 2.55 KB
Newer Older
1 2 3 4 5 6 7 8
<?php
/**
 * @file
 * Contains \Drupal\language\Form\LanguageListController.
 */

namespace Drupal\language;

9
use Drupal\Core\Config\Entity\DraggableListController;
10 11 12 13 14
use Drupal\Core\Entity\EntityInterface;

/**
 * User interface for the language overview screen.
 */
15 16 17 18 19 20
class LanguageListController extends DraggableListController {

  /**
   * {@inheritdoc}
   */
  protected $entitiesKey = 'languages';
21 22 23 24 25

  /**
   * {@inheritdoc}
   */
  public function load() {
26
    $entities = $this->storage->loadByProperties(array('locked' => FALSE));
27 28 29

    // Sort the entities using the entity class's sort() method.
    // See \Drupal\Core\Config\Entity\ConfigEntityBase::sort().
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
    uasort($entities, array($this->entityInfo['class'], 'sort'));
    return $entities;
  }

  /**
   * {@inheritdoc}
   */
  public function getFormID() {
    return 'language_admin_overview_form';
  }

  /**
   * {@inheritdoc}
   */
  public function getOperations(EntityInterface $entity) {
    $operations = parent::getOperations($entity);
    $default = language_default();

    // Edit and delete path for Languages entities have a different pattern
    // than other config entities.
    $path = 'admin/config/regional/language';
    if (isset($operations['edit'])) {
      $operations['edit']['href'] = $path . '/edit/' . $entity->id();
    }
    if (isset($operations['delete'])) {
      $operations['delete']['href'] = $path . '/delete/' . $entity->id();
    }

    // Deleting the site default language is not allowed.
    if ($entity->id() == $default->id) {
      unset($operations['delete']);
    }

    return $operations;
  }

  /**
   * {@inheritdoc}
   */
  public function buildHeader() {
70 71
    $header['label'] = t('Name');
    return $header + parent::buildHeader();
72 73 74 75 76 77
  }

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {
78
    $row['label'] = $this->getLabel($entity);
79
    return $row + parent::buildRow($entity);
80 81 82 83 84 85
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, array &$form_state) {
86 87 88
    $form = parent::buildForm($form, $form_state);
    $form[$this->entitiesKey]['#languages'] = $this->entities;
    $form['actions']['submit']['#value'] = t('Save configuration');
89 90 91 92 93 94 95
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, array &$form_state) {
96
    parent::submitForm($form, $form_state);
97 98 99 100 101 102 103 104 105 106 107

    // Kill the static cache in language_list().
    drupal_static_reset('language_list');

    // Update weight of locked system languages.
    language_update_locked_weights();

    drupal_set_message(t('Configuration saved.'));
  }

}