diff core/modules/media/src/MediaStorage.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/modules/media/src/MediaStorage.php	Thu Feb 28 13:11:55 2019 +0000
@@ -0,0 +1,32 @@
+<?php
+
+namespace Drupal\media;
+
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
+
+/**
+ * Defines the storage handler class for media.
+ *
+ * The default storage is overridden to handle metadata fetching outside of the
+ * database transaction.
+ */
+class MediaStorage extends SqlContentEntityStorage {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function save(EntityInterface $media) {
+    // For backwards compatibility, modules that override the Media entity
+    // class, are not required to implement the prepareSave() method.
+    // @todo For Drupal 8.7, consider throwing a deprecation notice if the
+    //   method doesn't exist. See
+    //   https://www.drupal.org/project/drupal/issues/2992426 for further
+    //   discussion.
+    if (method_exists($media, 'prepareSave')) {
+      $media->prepareSave();
+    }
+    return parent::save($media);
+  }
+
+}