function DisplayPluginBase::getFieldLabels

Same name and namespace in other branches
  1. 8.9.x core/modules/views/src/Plugin/views/display/DisplayPluginBase.php \Drupal\views\Plugin\views\display\DisplayPluginBase::getFieldLabels()
  2. 10 core/modules/views/src/Plugin/views/display/DisplayPluginBase.php \Drupal\views\Plugin\views\display\DisplayPluginBase::getFieldLabels()
  3. 11.x core/modules/views/src/Plugin/views/display/DisplayPluginBase.php \Drupal\views\Plugin\views\display\DisplayPluginBase::getFieldLabels()

Retrieves a list of fields for the current display.

This also takes into account any associated relationships, if they exist.

Parameters

bool $groupable_only: (optional) TRUE to only return an array of field labels from handlers that support the useStringGroupBy method, defaults to FALSE.

Return value

array An array of applicable field options, keyed by ID.

Overrides DisplayPluginInterface::getFieldLabels

File

core/modules/views/src/Plugin/views/display/DisplayPluginBase.php, line 967

Class

DisplayPluginBase
Base class for views display plugins.

Namespace

Drupal\views\Plugin\views\display

Code

public function getFieldLabels($groupable_only = FALSE) {
    $options = [];
    foreach ($this->getHandlers('relationship') as $relationship => $handler) {
        $relationships[$relationship] = $handler->adminLabel();
    }
    foreach ($this->getHandlers('field') as $id => $handler) {
        if ($groupable_only && !$handler->useStringGroupBy()) {
            // 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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.