Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291300

Media::getSource() should check that $this->bundle->entity is not NULL

$
0
0

Problem/Motivation

It is easy to create a Media entity with a non-existent type (see below). I came across this when defining a migration, when I used the incorrect bundle name.

In this case, $this->bundle->entity is NULL. Since Media::getSource() is simply

  public function getSource() {
    return $this->bundle->entity->getSource();
  }

$entity->getSource() leads to an error something like this:

Call to a member function getSource() on null in Drupal\media\Entity\Media->getSource() (line 137 of /var/www/html/web/core/modules/media/src/Entity/Media.php)

Steps to reproduce

$entity = \Drupal::entityTypeManager()
  ->getStorage('media')
  ->create(['name' => 'foo', 'bundle' => 'does_not_exist']);
$entity->save();

Proposed resolution

Check that $this->bundle->entity is not empty before trying to access its getSource() method.

Remaining tasks

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

N/A


Viewing all articles
Browse latest Browse all 291300

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>