OptionsViewsHooks.php

Namespace

Drupal\options\Hook

File

core/modules/options/src/Hook/OptionsViewsHooks.php

View source
<?php

namespace Drupal\options\Hook;

use Drupal\field\FieldStorageConfigInterface;
use Drupal\Core\Hook\Attribute\Hook;

/**
 * Hook implementations for options.
 */
class OptionsViewsHooks {
    
    /**
     * Implements hook_field_views_data().
     *
     * Views integration for list fields. Have a different filter handler and
     * argument handlers for list fields. This should allow to select values of
     * the list.
     */
    public function fieldViewsData(FieldStorageConfigInterface $field) {
        $data = views_field_default_views_data($field);
        foreach ($data as $table_name => $table_data) {
            foreach ($table_data as $field_name => $field_data) {
                if (isset($field_data['filter']) && $field_name != 'delta') {
                    $data[$table_name][$field_name]['filter']['id'] = 'list_field';
                }
                if (isset($field_data['argument']) && $field_name != 'delta') {
                    if ($field->getType() == 'list_string') {
                        $data[$table_name][$field_name]['argument']['id'] = 'string_list_field';
                    }
                    else {
                        $data[$table_name][$field_name]['argument']['id'] = 'number_list_field';
                    }
                }
            }
        }
        return $data;
    }

}

Classes

Title Deprecated Summary
OptionsViewsHooks Hook implementations for options.

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