Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / entityqueue / src / Entity / EntitySubqueue.php
index 349ab962ee7ca60821e66f48d940a90362cb9ff8..ba7b5fdd97c38ae8ca6a6aaff9b6417f56cb1e7e 100644 (file)
@@ -5,6 +5,7 @@ namespace Drupal\entityqueue\Entity;
 use Drupal\Core\Cache\Cache;
 use Drupal\Core\Entity\ContentEntityBase;
 use Drupal\Core\Entity\EntityChangedTrait;
+use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Entity\EntityStorageInterface;
 use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Core\Field\BaseFieldDefinition;
@@ -168,15 +169,16 @@ class EntitySubqueue extends ContentEntityBase implements EntitySubqueueInterfac
       ->setLabel(t('Title'))
       ->setRequired(TRUE)
       ->setSetting('max_length', 191)
-      ->setDisplayOptions('view', array(
+      ->setDisplayOptions('view', [
         'label' => 'hidden',
         'type' => 'string',
         'weight' => -10,
-      ))
-      ->setDisplayOptions('form', array(
+      ])
+      ->setDisplayConfigurable('view', TRUE)
+      ->setDisplayOptions('form', [
         'type' => 'string_textfield',
         'weight' => -10,
-      ))
+      ])
       ->setDisplayConfigurable('form', TRUE);
 
     $fields['items'] = BaseFieldDefinition::create('entity_reference')
@@ -187,33 +189,33 @@ class EntitySubqueue extends ContentEntityBase implements EntitySubqueueInterfac
       // entity type that uses strings IDs, in order to allow both integers and
       // strings to be stored by the default entity reference field storage.
       ->setSetting('target_type', 'entity_subqueue')
-      ->setDisplayOptions('view', array(
+      ->setDisplayOptions('view', [
         'label' => 'hidden',
         'type' => 'entity_reference_label',
         'weight' => 0,
-      ))
-      ->setDisplayOptions('form', array(
+      ])
+      ->setDisplayOptions('form', [
         'type' => 'entity_reference_autocomplete',
         'weight' => 5,
-        'settings' => array(
+        'settings' => [
           'match_operator' => 'CONTAINS',
           'size' => '60',
           'placeholder' => '',
-        ),
-      ))
+        ],
+      ])
       ->setDisplayConfigurable('form', TRUE)
       ->setDisplayConfigurable('view', TRUE);
 
     $fields['langcode'] = BaseFieldDefinition::create('language')
       ->setLabel(t('Language'))
       ->setDescription(t('The subqueue language code.'))
-      ->setDisplayOptions('view', array(
+      ->setDisplayOptions('view', [
         'type' => 'hidden',
-      ))
-      ->setDisplayOptions('form', array(
+      ])
+      ->setDisplayOptions('form', [
         'type' => 'language_select',
         'weight' => 2,
-      ));
+      ]);
 
     $fields['uid'] = BaseFieldDefinition::create('entity_reference')
       ->setLabel(t('Authored by'))
@@ -277,6 +279,28 @@ class EntitySubqueue extends ContentEntityBase implements EntitySubqueueInterfac
     return $this;
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function addItem(EntityInterface $entity) {
+    $this->get('items')->appendItem($entity->id());
+    return $this;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function removeItem(EntityInterface $entity) {
+    $subqueue_items = $this->get('items')->getValue();
+    foreach ($subqueue_items as $key => $item) {
+      if ($item['target_id'] == $entity->id()) {
+        unset($subqueue_items[$key]);
+      }
+    }
+    $this->get('items')->setValue($subqueue_items);
+    return $this;
+  }
+
   /**
    * Default value callback for 'uid' base field definition.
    *
@@ -286,7 +310,7 @@ class EntitySubqueue extends ContentEntityBase implements EntitySubqueueInterfac
    *   An array of default values.
    */
   public static function getCurrentUserId() {
-    return array(\Drupal::currentUser()->id());
+    return [\Drupal::currentUser()->id()];
   }
 
   /**