我在媒体内容类型上创建了图像字段,然后在文章节点中创建了媒体引用字段。
我想从图像路径检索媒体 ID。
最佳答案
这是从文件名获取媒体 ID 的方法
// Load file by filename
// array.
$file = $this->entityTypeManager
->getStorage('file')
->loadByProperties(['filename' => $file_name]);
// 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]);
关于drupal - 如何从媒体 "media id"drupal 8 获取 "image name/path",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64367545/