public function ImageShortcode::process in Shortcode 8
Same name and namespace in other branches
- 2.0.x shortcode_basic_tags/src/Plugin/Shortcode/ImageShortcode.php \Drupal\shortcode_basic_tags\Plugin\Shortcode\ImageShortcode::process()
Performs the shortcode processing.
Parameters
array $attributes: Array of attributes.
string $text: The text string to be processed.
string $langcode: The language code of the text to be filtered. Defaults to LANGCODE_NOT_SPECIFIED.
Return value
string The processed text.
Overrides ShortcodeInterface::process
File
- shortcode_basic_tags/
src/ Plugin/ Shortcode/ ImageShortcode.php, line 23
Class
- ImageShortcode
- The image shortcode.
Namespace
Drupal\shortcode_basic_tags\Plugin\ShortcodeCode
public function process(array $attributes, $text, $langcode = Language::LANGCODE_NOT_SPECIFIED) {
// Merge with default attributes.
$attributes = $this
->getAttributes([
'class' => '',
'alt' => '',
'src' => '',
'mid' => '',
'imagestyle' => '',
], $attributes);
$class = $this
->addClass($attributes['class'], 'img');
if ($attributes['mid']) {
$properties = $this
->getImageProperties($attributes['mid']);
if ($properties['path']) {
if ($attributes['imagestyle']) {
$attributes['src'] = ImageStyle::load($attributes['imagestyle'])
->buildUrl($properties['path']);
}
else {
$attributes['src'] = file_create_url($properties['path']);
}
}
if ($properties['alt'] && !$attributes['alt']) {
$attributes['alt'] = $properties['alt'];
}
}
$output = [
'#theme' => 'shortcode_img',
'#src' => $attributes['src'],
'#class' => $class,
'#alt' => $attributes['alt'],
];
return $this
->render($output);
}