Loading core/modules/media/src/Entity/Media.php +4 −0 Original line number Diff line number Diff line Loading @@ -297,6 +297,10 @@ protected function shouldUpdateThumbnail($is_new = FALSE) { public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); if (!$this->getOwner()) { $this->setOwnerId(0); } // If no thumbnail has been explicitly set, use the default thumbnail. if ($this->get('thumbnail')->isEmpty()) { $this->thumbnail->target_id = $this->loadThumbnail()->id(); Loading core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php +15 −0 Original line number Diff line number Diff line Loading @@ -92,6 +92,21 @@ public function testMediaWithOnlyOneMediaType() { ->loadUnchanged($media_id); $this->assertSame($media->getName(), $media_name2); // Change the authored by field to an empty string, which should assign // authorship to the anonymous user (uid 0). $this->drupalGet('media/' . $media_id . '/edit'); $edit['uid[0][target_id]'] = ''; $this->submitForm($edit, 'Save'); /** @var \Drupal\media\MediaInterface $media */ $media = $this->container->get('entity_type.manager') ->getStorage('media') ->loadUnchanged($media_id); $uid = $media->getOwnerId(); // Most SQL database drivers stringify fetches but entities are not // necessarily stored in a SQL database. At the same time, NULL/FALSE/"" // won't do. $this->assertTrue($uid === 0 || $uid === '0', 'Media authored by anonymous user.'); // Test that there is no empty vertical tabs element, if the container is // empty (see #2750697). // Make the "Publisher ID" and "Created" fields hidden. Loading Loading
core/modules/media/src/Entity/Media.php +4 −0 Original line number Diff line number Diff line Loading @@ -297,6 +297,10 @@ protected function shouldUpdateThumbnail($is_new = FALSE) { public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); if (!$this->getOwner()) { $this->setOwnerId(0); } // If no thumbnail has been explicitly set, use the default thumbnail. if ($this->get('thumbnail')->isEmpty()) { $this->thumbnail->target_id = $this->loadThumbnail()->id(); Loading
core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php +15 −0 Original line number Diff line number Diff line Loading @@ -92,6 +92,21 @@ public function testMediaWithOnlyOneMediaType() { ->loadUnchanged($media_id); $this->assertSame($media->getName(), $media_name2); // Change the authored by field to an empty string, which should assign // authorship to the anonymous user (uid 0). $this->drupalGet('media/' . $media_id . '/edit'); $edit['uid[0][target_id]'] = ''; $this->submitForm($edit, 'Save'); /** @var \Drupal\media\MediaInterface $media */ $media = $this->container->get('entity_type.manager') ->getStorage('media') ->loadUnchanged($media_id); $uid = $media->getOwnerId(); // Most SQL database drivers stringify fetches but entities are not // necessarily stored in a SQL database. At the same time, NULL/FALSE/"" // won't do. $this->assertTrue($uid === 0 || $uid === '0', 'Media authored by anonymous user.'); // Test that there is no empty vertical tabs element, if the container is // empty (see #2750697). // Make the "Publisher ID" and "Created" fields hidden. Loading