You are here

function rest_views_views_data_alter in REST Views 2.0.x

Same name and namespace in other branches
  1. 8 rest_views.module \rest_views_views_data_alter()

Implements hook_views_data_alter().

File

./rest_views.module, line 13
Provides a new Views Field plugin for all entity fields.

Code

function rest_views_views_data_alter(array &$data) {
  foreach ($data as $table_alias => $fields) {

    /** @var array[] $fields */
    foreach ($fields as $field_alias => $field) {

      // Find all handlers that use the core Field plugin.
      if (isset($field['field']['id']) && $field['field']['id'] === 'field') {

        // Add a second handler that uses the Rest Field plugin.
        if (isset($field['title'])) {
          $field['title'] = t('@field (serializable)', [
            '@field' => $field['title'],
          ]);
        }
        $field['field']['id'] = 'field_export';

        // Only expose the field handler as the others are redundant.
        unset($field['argument'], $field['filter'], $field['sort']);
        $data[$table_alias]["{$field_alias}_export"] = $field;
      }
    }
  }
}