Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / lib / Drupal / Core / TypedData / ListDataDefinition.php
index 3109cd2115678dd37f4b520930e1c83b12715fd8..001c58b28759548fdaccec663e12e838d1998931 100644 (file)
@@ -72,20 +72,18 @@ class ListDataDefinition extends DataDefinition implements ListDataDefinitionInt
    * {@inheritdoc}
    */
   public function getClass() {
-    $class = isset($this->definition['class']) ? $this->definition['class'] : NULL;
-    if (!empty($class)) {
-      return $class;
+    if (!empty($this->definition['class'])) {
+      return $this->definition['class'];
     }
-    else {
-      // If a list definition is used but no class has been specified, derive
-      // the default list class from the item type.
-      $item_type_definition = \Drupal::typedDataManager()
-        ->getDefinition($this->getItemDefinition()->getDataType());
-      if (!$item_type_definition) {
-        throw new \LogicException("An invalid data type '{$this->getItemDefinition()->getDataType()}' has been specified for list items");
-      }
-      return $item_type_definition['list_class'];
+
+    // If a list definition is used but no class has been specified, derive the
+    // default list class from the item type.
+    $item_type_definition = \Drupal::typedDataManager()
+      ->getDefinition($this->getItemDefinition()->getDataType());
+    if (!$item_type_definition) {
+      throw new \LogicException("An invalid data type '{$this->getItemDefinition()->getDataType()}' has been specified for list items");
     }
+    return $item_type_definition['list_class'];
   }
 
   /**
@@ -108,4 +106,13 @@ class ListDataDefinition extends DataDefinition implements ListDataDefinitionInt
     return $this;
   }
 
+  /**
+   * Magic method: Implements a deep clone.
+   */
+  public function __clone() {
+    // Ensure the itemDefinition property is actually cloned by overwriting the
+    // original reference.
+    $this->itemDefinition = clone $this->itemDefinition;
+  }
+
 }