public function ShortcodeBase::getImageProperties in Shortcode 8
Same name and namespace in other branches
- 2.0.x src/Plugin/ShortcodeBase.php \Drupal\shortcode\Plugin\ShortcodeBase::getImageProperties()
Returns image properties for a given image media entity id.
Parameters
int $mid: Media entity id.
Return value
array File properties: `alt` and `path` where available.
1 call to ShortcodeBase::getImageProperties()
- ImageShortcode::process in shortcode_basic_tags/
src/ Plugin/ Shortcode/ ImageShortcode.php - Performs the shortcode processing.
File
- src/
Plugin/ ShortcodeBase.php, line 327
Class
- ShortcodeBase
- Provides a base class for Shortcode plugins.
Namespace
Drupal\shortcode\PluginCode
public function getImageProperties($mid) {
$properties = [
'alt' => '',
'path' => '',
];
if (intval($mid)) {
$media_entity = Media::load($mid);
}
if ($media_entity) {
$field_media = $this
->getMediaField($media_entity);
}
if ($field_media) {
$file = $field_media->entity;
if (isset($field_media->alt)) {
$properties['alt'] = $field_media->alt;
}
}
if ($file) {
$properties['path'] = $file
->getFileUri();
}
return $properties;
}