You are here

public function BlazyStyleOptionsTrait::getFieldString in Blazy 7

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

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

File

src/Dejavu/BlazyStyleOptionsTrait.php, line 106

Class

BlazyStyleOptionsTrait
A Trait common for optional views style plugins.

Namespace

Drupal\blazy\Dejavu

Code

public function getFieldString($row, $field_name, $index, $clean = TRUE) {
  $result = '';
  if ($value = $this
    ->get_field($index, $field_name)) {
    $value = is_array($value) ? array_filter($value) : $value;
    if (is_string($value)) {

      // Only respects tags with default CSV, just too much to worry about.
      if (strpos($value, ',') !== FALSE) {
        $tags = array_map('trim', explode(",", $value));
        $rendered_tags = [];
        foreach ($tags as $tag) {
          $rendered_tags[] = $clean ? drupal_clean_css_identifier($tag) : $tag;
        }
        $result = implode(' ', $rendered_tags);
      }
      else {
        $result = $clean ? drupal_clean_css_identifier($value) : $value;
      }
    }
    else {

      // @todo recheck if anything else but value worthwhile.
      $value = isset($value[0]) && !empty($value[0]['value']) ? $value[0]['value'] : '';
      if ($value) {
        $result = $clean ? drupal_clean_css_identifier($value) : $value;
      }
    }
  }
  return empty($result) ? '' : trim(strip_tags($result));
}