You are here

rest_views.module in REST Views 8

Same filename and directory in other branches
  1. 2.0.x rest_views.module

Provides a new Views Field plugin for all entity fields.

File

rest_views.module
View source
<?php

/**
 * @file
 * Provides a new Views Field plugin for all entity fields.
 */

/**
 * Implements hook_views_data_alter().
 */
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.
        $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;
      }
    }
  }
}

Functions