如何获得;媒体id“;“来自媒体”;图像名称/路径“;drupal 8
我已经在媒体内容类型上创建了图像字段,然后在文章节点中创建了媒体引用字段如何获得;媒体id“;“来自媒体”;图像名称/路径“;drupal 8,drupal,drupal-8,Drupal,Drupal 8,我已经在媒体内容类型上创建了图像字段,然后在文章节点中创建了媒体引用字段 我想从映像路径中检索媒体id。这是从文件名中获取媒体id的方法 //Load file by filename //array $file = $this->entityTypeManager ->getStorage('file') ->loadByProperties(['filename'=>$filename]) //get First file (make a loop if you g
我想从映像路径中检索媒体id。这是从文件名中获取媒体id的方法
//Load file by filename
//array
$file = $this->entityTypeManager
->getStorage('file')
->loadByProperties(['filename'=>$filename])
//get First file (make a loop if you get many files)
$fileId =array_shift($file))->fid->value
//Array of Medias witch contains your file
$this->entityTypeManager
->getStorage('media')
->loadByProperties(['field_media_image'=> $fileId])