You are here

public function EntityListWrapper::label in Entity API 7

Returns the label for the list of set values if available.

Overrides EntityMetadataWrapper::label

File

includes/entity.wrapper.inc, line 1170
Provides wrappers allowing easy usage of the entity metadata.

Class

EntityListWrapper
Wraps a list of values.

Code

public function label() {
  if ($options = $this
    ->optionsList('view')) {
    $options = entity_property_options_flatten($options);
    $labels = array_intersect_key($options, array_flip((array) parent::value()));
  }
  else {

    // Get each label on its own, e.g. to support getting labels of a list
    // of entities.
    $labels = array();
    foreach ($this as $key => $property) {
      $label = $property
        ->label();
      if (!$label) {
        return NULL;
      }
      $labels[] = $label;
    }
  }
  return isset($labels) ? implode(', ', $labels) : NULL;
}