You are here

function views_isotope_views_helper_get_field_value in Brainstorm profile 7

Helper function to get a field value.

@todo: this seems very messy - there must be a better way to do it?

Parameters

object $entity: The entity.

string $fieldname: The field name.

Return value

array Value.

2 calls to views_isotope_views_helper_get_field_value()
template_preprocess_views_isotope_views_filter in modules/custom/views_isotope/views/views_isotope_views.theme.inc
Preprocess function to build isotope filter blocks.
template_preprocess_views_isotope_views_grid in modules/custom/views_isotope/views/views_isotope_views.theme.inc
Preprocess function to build the isotope grid.

File

modules/custom/views_isotope/views/views_isotope_views.theme.inc, line 108
Theme callbacks.

Code

function views_isotope_views_helper_get_field_value($entity, $fieldname) {
  if (!empty($entity->{'field_' . $fieldname})) {
    foreach ($entity->{'field_' . $fieldname} as $a) {
      if (!empty($a['rendered'])) {
        $field[] = render($a['rendered']);
      }
    }
  }
  elseif (!empty($entity->{'taxonomy_term_data_' . $fieldname})) {

    // Term title is not a real field in D7.
    $field[$fieldname] = $entity->{'taxonomy_term_data_' . $fieldname};
  }
  elseif (!empty($entity->{'node_' . $fieldname})) {
    $field[$fieldname] = $entity->{'node_' . $fieldname};
  }
  if (isset($field)) {
    $r = [];
    if (!is_array($field)) {
      $field = [
        $field,
      ];
    }
    foreach ($field as $f) {
      $filter_value = render($f);
      $r[] = trim(check_plain(strip_tags($filter_value)));
    }
    return $r;
  }
  return NULL;
}