Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / taxonomy / src / VocabularyListBuilder.php
index e7c021b4d70aebcad7277d32b5c1444b3927e6ae..b6f6921db43633e2324d9ce8ebecd0b25e07d282 100644 (file)
@@ -7,6 +7,7 @@ use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Messenger\MessengerInterface;
 use Drupal\Core\Render\RendererInterface;
 use Drupal\Core\Session\AccountInterface;
 use Drupal\Core\Url;
@@ -45,6 +46,13 @@ class VocabularyListBuilder extends DraggableListBuilder {
    */
   protected $renderer;
 
+  /**
+   * The messenger.
+   *
+   * @var \Drupal\Core\Messenger\MessengerInterface
+   */
+  protected $messenger;
+
   /**
    * Constructs a new VocabularyListBuilder object.
    *
@@ -56,13 +64,20 @@ class VocabularyListBuilder extends DraggableListBuilder {
    *   The entity manager service.
    * @param \Drupal\Core\Render\RendererInterface $renderer
    *   The renderer service.
+   * @param \Drupal\Core\Messenger\MessengerInterface $messenger
+   *   The messenger.
    */
-  public function __construct(EntityTypeInterface $entity_type, AccountInterface $current_user, EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer = NULL) {
+  public function __construct(EntityTypeInterface $entity_type,
+                              AccountInterface $current_user,
+                              EntityTypeManagerInterface $entity_type_manager,
+                              RendererInterface $renderer = NULL,
+                              MessengerInterface $messenger) {
     parent::__construct($entity_type, $entity_type_manager->getStorage($entity_type->id()));
 
     $this->currentUser = $current_user;
     $this->entityTypeManager = $entity_type_manager;
     $this->renderer = $renderer;
+    $this->messenger = $messenger;
   }
 
   /**
@@ -73,7 +88,8 @@ class VocabularyListBuilder extends DraggableListBuilder {
       $entity_type,
       $container->get('current_user'),
       $container->get('entity_type.manager'),
-      $container->get('renderer')
+      $container->get('renderer'),
+      $container->get('messenger')
     );
   }
 
@@ -123,7 +139,7 @@ class VocabularyListBuilder extends DraggableListBuilder {
     $header['label'] = t('Vocabulary name');
     $header['description'] = t('Description');
 
-    if ($this->currentUser->hasPermission('administer vocabularies')) {
+    if ($this->currentUser->hasPermission('administer vocabularies') && !empty($this->weightKey)) {
       $header['weight'] = t('Weight');
     }
 
@@ -161,7 +177,7 @@ class VocabularyListBuilder extends DraggableListBuilder {
       $this->renderer->addCacheableDependency($build['table'], $create_access);
       if ($create_access->isAllowed()) {
         $build['table']['#empty'] = t('No vocabularies available. <a href=":link">Add vocabulary</a>.', [
-          ':link' => Url::fromRoute('entity.taxonomy_vocabulary.add_form')->toString()
+          ':link' => Url::fromRoute('entity.taxonomy_vocabulary.add_form')->toString(),
         ]);
       }
       else {
@@ -189,7 +205,7 @@ class VocabularyListBuilder extends DraggableListBuilder {
   public function submitForm(array &$form, FormStateInterface $form_state) {
     parent::submitForm($form, $form_state);
 
-    drupal_set_message(t('The configuration options have been saved.'));
+    $this->messenger->addStatus($this->t('The configuration options have been saved.'));
   }
 
 }