You are here

public function BlazyEntity::getFieldString in Blazy 7

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

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

2 calls to BlazyEntity::getFieldString()
BlazyEntity::getFieldRenderable in src/BlazyEntity.php
Returns the formatted renderable array of the field.
BlazyEntity::getFieldTextOrLink in src/BlazyEntity.php
Returns the text or link value of the fields: link, or text.

File

src/BlazyEntity.php, line 124

Class

BlazyEntity
Implements BlazyFormatterInterface.

Namespace

Drupal\blazy

Code

public function getFieldString($entity, $field_name, $settings, $clean = TRUE) {
  if ($value = $this
    ->getFieldValue($entity, $field_name, $settings)) {

    // If Entity, use no index, or direct string value, file entity has.
    // Cannot use safe_value as it has nothing todo with the given text value.
    $string = isset($value['value']) ? $value['value'] : $value;
    $string = isset($value[0]['value']) ? $value[0]['value'] : $string;
    if ($string && is_string($string)) {
      $string = $clean ? strip_tags($string, '<a><strong><em><span><small>') : filter_xss($string, BlazyDefault::TAGS);
      return trim($string);
    }
  }
  return '';
}