protected function Paragraph::getFileSummary

Returns summary for file paragraph.

Parameters

string $field_name: Field name from field definition.

Return value

string Summary for image.

1 call to Paragraph::getFileSummary()
Paragraph::getSummaryItems in paragraphs/src/Entity/Paragraph.php
Returns the summary items of the Paragraph.

File

paragraphs/src/Entity/Paragraph.php, line 655

Class

Paragraph
Defines the Paragraph entity.

Namespace

Drupal\paragraphs\Entity

Code

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);
}