protected function FileMatcher::buildDescription in Linkit 8.4
Same name and namespace in other branches
- 8.5 src/Plugin/Linkit/Matcher/FileMatcher.php \Drupal\linkit\Plugin\Linkit\Matcher\FileMatcher::buildDescription()
Builds the description string used in the match array.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The matched entity.
Return value
string The description for this entity.
Overrides EntityMatcher::buildDescription
File
- src/
Plugin/ Linkit/ Matcher/ FileMatcher.php, line 148 - Contains \Drupal\linkit\Plugin\Linkit\Matcher\FileMatcher.
Class
- FileMatcher
- Plugin annotation @Matcher( id = "entity:file", target_entity = "file", label = @Translation("File"), provider = "file" )
Namespace
Drupal\linkit\Plugin\Linkit\MatcherCode
protected function buildDescription($entity) {
$description_array = array();
$description_array[] = parent::buildDescription($entity);
/** @var \Drupal\file\FileInterface $entity */
$file = $entity
->getFileUri();
/** @var \Drupal\Core\Image\ImageInterface $image */
$image = \Drupal::service('image.factory')
->get($file);
if ($image
->isValid()) {
if ($this->configuration['images']['show_dimensions']) {
$description_array[] = $image
->getWidth() . 'x' . $image
->getHeight() . 'px';
}
if ($this->configuration['images']['show_thumbnail'] && $this->moduleHandler
->moduleExists('image')) {
$image_element = array(
'#weight' => -10,
'#theme' => 'image_style',
'#style_name' => $this->configuration['images']['thumbnail_image_style'],
'#uri' => $entity
->getFileUri(),
);
$description_array[] = (string) \Drupal::service('renderer')
->render($image_element);
}
}
$description = implode('<br />', $description_array);
return LinkitXss::descriptionFilter($description);
}