You are here

protected function ResourceEntity::viewModeFields in RESTful 7.2

Get the public fields with default values based on view mode information.

Parameters

array $view_mode_info: View mode configuration array.

Return value

array The public fields.

Throws

ServerConfigurationException

1 call to ResourceEntity::viewModeFields()
ResourceEntity::dataProviderFactory in src/Plugin/resource/ResourceEntity.php
Data provider factory.

File

src/Plugin/resource/ResourceEntity.php, line 212
Contains \Drupal\restful\Plugin\resource\ResourceEntity.

Class

ResourceEntity

Namespace

Drupal\restful\Plugin\resource

Code

protected function viewModeFields(array $view_mode_info) {
  $field_definitions = array();
  $entity_type = $this
    ->getEntityType();
  $bundles = $this
    ->getBundles();
  $view_mode = $view_mode_info['name'];
  if (count($bundles) != 1) {
    throw new ServerConfigurationException('View modes can only be used in resources with a single bundle.');
  }
  $bundle = reset($bundles);
  foreach ($view_mode_info['fieldMap'] as $field_name => $public_field_name) {
    $field_instance = field_info_instance($entity_type, $field_name, $bundle);
    $formatter_info = $field_instance['display'][$view_mode];
    unset($formatter_info['module']);
    unset($formatter_info['weight']);
    unset($formatter_info['label']);
    $field_definitions[$public_field_name] = array(
      'property' => $field_name,
      'formatter' => $formatter_info,
      'entityType' => $this
        ->getEntityType(),
    );
  }
  return $field_definitions;
}