You are here

public function BlazyEntity::getFieldString in Blazy 8.2

Same name and namespace in other branches
  1. 7 src/BlazyEntity.php \Drupal\blazy\BlazyEntity::getFieldString()

Returns the string value of the fields: link, or text.

1 call to BlazyEntity::getFieldString()
BlazyEntity::getFieldTextOrLink in src/BlazyEntity.php
Returns the text or link value of the fields: link, or text.

File

src/BlazyEntity.php, line 184

Class

BlazyEntity
Provides common entity utilities to work with field details.

Namespace

Drupal\blazy

Code

public function getFieldString($entity, $field_name, $langcode, $clean = TRUE) {
  if ($entity
    ->hasField($field_name)) {
    $values = $this
      ->getFieldValue($entity, $field_name, $langcode);

    // Can be text, or link field.
    $string = isset($values[0]['uri']) ? $values[0]['uri'] : (isset($values[0]['value']) ? $values[0]['value'] : '');
    if ($string && is_string($string)) {
      $string = $clean ? strip_tags($string, '<a><strong><em><span><small>') : Xss::filter($string, BlazyDefault::TAGS);
      return trim($string);
    }
  }
  return '';
}