If I have the id of an existing piece of media content, what can I do to update it (modify it)?
I know how to create a new piece of media , (with Media::create) , but not sure of the code to load and then updated an existing piece of Media.
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.Sign up to join this community
Media is like any other entity based on ContentEntityBase in Drupal.
// top of your file use Drupal\media_entity\Entity\Media; // in a function $media = Media::load($id); // do stuff with $media $media->save();
In a method of a class you would not want to use
Media:: but instead use
entityTypeManager service to load the entity:
$media = $this->entityTypeManager->getStorage('media')->load($id); where
entityTypeManager is injected to your class.