If we want to load Media entity. we have to add library on the top of page. ( use Drupal\media\Entity\Media; )
Then its easy to load media entity by the syntax.
Syntax:
$media_detail = Media::load($mid); // here $mid is media entity id
now if we want to get image field data of media field then syntax is..
$media_img = file_create_url($media_detail->field_media_image->entity->getFileUri());
// here field_media_image is field name in media entity
now if we want to get any text field value then syntax will be..
$media_caption = $media_detail->get('field_capt2120')->getValue();
// here field_capt2120 is the machine name of caption field in media entity
foreach($m_caption as $mkey){
$capval = $mkey['value']; // here we will get the caption value
}
Note: If have any suggestions or issue regarding 'Programmatically Media load in drupal 8.' then you can ask by comments.
Then its easy to load media entity by the syntax.
Syntax:
$media_detail = Media::load($mid); // here $mid is media entity id
now if we want to get image field data of media field then syntax is..
$media_img = file_create_url($media_detail->field_media_image->entity->getFileUri());
// here field_media_image is field name in media entity
now if we want to get any text field value then syntax will be..
$media_caption = $media_detail->get('field_capt2120')->getValue();
// here field_capt2120 is the machine name of caption field in media entity
foreach($m_caption as $mkey){
$capval = $mkey['value']; // here we will get the caption value
}
Note: If have any suggestions or issue regarding 'Programmatically Media load in drupal 8.' then you can ask by comments.
No comments:
Post a Comment