public function PhotosImage::getFids in Album Photos 6.0.x
Same name and namespace in other branches
- 8.5 src/Entity/PhotosImage.php \Drupal\photos\Entity\PhotosImage::getFids()
Gets the image file ids.
Return value
array The image file ids.
Overrides PhotosImageInterface::getFids
File
- src/
Entity/ PhotosImage.php, line 158
Class
- PhotosImage
- Defines the photos image entity class.
Namespace
Drupal\photos\EntityCode
public function getFids() {
$fids = [];
$photosImageFields = \Drupal::service('entity_field.manager')
->getFieldDefinitions('photos_image', 'photos_image');
// @todo warn if other unhandled fields exist?
foreach ($photosImageFields as $key => $field) {
/** @var \Drupal\Core\Field\FieldDefinitionInterface $field */
$fieldType = $field
->getType();
if ($fieldType == 'file' || $fieldType == 'image') {
// Check image and file fields.
foreach ($this->{$key} as $item) {
$fids[$item->entity
->id()] = $item->entity
->id();
}
}
elseif ($fieldType == 'entity_reference') {
// Check media fields.
$settings = $field
->getSettings();
if ($settings['target_type'] == 'media') {
foreach ($this->{$key} as $item) {
$media = Media::load($item->entity
->id());
// @todo maybe getSourceFieldDefinition here?
$fid = $media
->getSource()
->getSourceFieldValue($media);
$fids[$fid] = $fid;
}
}
}
}
return $fids;
}