You are here

public function BlazyStyleOptionsTrait::getFieldString in Blazy 8.2

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

Returns the string values for the expected Title, ET label, List, Term.

@todo re-check this, or if any consistent way to retrieve string values.

File

src/Dejavu/BlazyStyleOptionsTrait.php, line 174

Class

BlazyStyleOptionsTrait
A Trait common for optional views style plugins.

Namespace

Drupal\blazy\Dejavu

Code

public function getFieldString($row, $field_name, $index, $clean = TRUE) {
  $values = [];

  // Content title/List/Text, either as link or plain text.
  if ($value = $this
    ->getFieldValue($index, $field_name)) {
    $value = is_array($value) ? array_filter($value) : $value;

    // Entity reference label where the above $value can be term ID.
    if ($markup = $this
      ->getField($index, $field_name)) {
      $value = is_object($markup) ? trim(strip_tags($markup
        ->__toString())) : $value;
    }
    if (is_string($value)) {

      // Only respects tags with default CSV, just too much to worry about.
      if (strpos($value, ',') !== FALSE) {
        $tags = explode(',', $value);
        $rendered_tags = [];
        foreach ($tags as $tag) {
          $tag = trim($tag);
          $rendered_tags[] = $clean ? Html::cleanCssIdentifier(mb_strtolower($tag)) : $tag;
        }
        $values[$index] = implode(' ', $rendered_tags);
      }
      else {
        $values[$index] = $clean ? Html::cleanCssIdentifier(mb_strtolower($value)) : $value;
      }
    }
    else {
      $value = isset($value[0]['value']) && !empty($value[0]['value']) ? $value[0]['value'] : '';
      if ($value) {
        $values[$index] = $clean ? Html::cleanCssIdentifier(mb_strtolower($value)) : $value;
      }
    }
  }
  return $values;
}