You are here

public function DisplayPluginBase::getFieldLabels in Views (for Drupal 7) 8.3

Retrieve a list of fields for the current display with the relationship associated if it exists.

Parameters

$groupable_only: Return only an array of field labels from handler that return TRUE from use_string_group_by method.

File

lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php, line 865
Definition of Drupal\views\Plugin\views\display\DisplayPluginBase.

Class

DisplayPluginBase
The default display plugin handler. Display plugins handle options and basic mechanisms for different output methods.

Namespace

Drupal\views\Plugin\views\display

Code

public function getFieldLabels() {

  // Use func_get_arg so the function signature isn't amended
  // but we can still pass TRUE into the function to filter
  // by groupable handlers.
  $args = func_get_args();
  $groupable_only = isset($args[0]) ? $args[0] : FALSE;
  $options = array();
  foreach ($this
    ->getHandlers('relationship') as $relationship => $handler) {
    if ($label = $handler
      ->label()) {
      $relationships[$relationship] = $label;
    }
    else {
      $relationships[$relationship] = $handler
        ->adminLabel();
    }
  }
  foreach ($this
    ->getHandlers('field') as $id => $handler) {
    if ($groupable_only && !$handler
      ->use_string_group_by()) {

      // Continue to next handler if it's not groupable.
      continue;
    }
    if ($label = $handler
      ->label()) {
      $options[$id] = $label;
    }
    else {
      $options[$id] = $handler
        ->adminLabel();
    }
    if (!empty($handler->options['relationship']) && !empty($relationships[$handler->options['relationship']])) {
      $options[$id] = '(' . $relationships[$handler->options['relationship']] . ') ' . $options[$id];
    }
  }
  return $options;
}