Returns summary for file paragraph.
string $field_name: Field name from field definition.
string Summary for image.
protected function getFileSummary($field_name) {
$summary = '';
if ($this
->get($field_name)->entity) {
foreach ($this
->get($field_name) as $file_value) {
$text = '';
if ($file_value->description != '') {
$text = $file_value->description;
}
elseif ($file_value->title != '') {
$text = $file_value->title;
}
elseif ($file_value->alt != '') {
$text = $file_value->alt;
}
elseif ($file_value->entity && $file_value->entity
->getFileName()) {
$text = $file_value->entity
->getFileName();
}
if (strlen($text) > 150) {
$text = Unicode::truncate($text, 150);
}
$summary = $text;
}
}
return trim($summary);
}