Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何获得;媒体id“;“来自媒体”;图像名称/路径“;drupal 8_Drupal_Drupal 8 - Fatal编程技术网

如何获得;媒体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])