You are here

protected function RestfulEntityViewMode::displayedFieldsList in RESTful 7

Helper method to get all the displayed fields for a bundle and a view_mode.

Parameters

string $view_mode: The view mode.

Return value

array An array of field names that are displayed in this view mode.

1 call to RestfulEntityViewMode::displayedFieldsList()
RestfulEntityViewMode::mapFields in includes/RestfulEntityViewMode.php
Generates the public properties configuration array from the mappings.

File

includes/RestfulEntityViewMode.php, line 95
Contains \RestfulEntityViewMode

Class

RestfulEntityViewMode
@file Contains \RestfulEntityViewMode

Code

protected function displayedFieldsList($view_mode) {
  $entity_field_instances = field_info_instances($this->entityType);
  $bundle_field_instances = reset($entity_field_instances);
  if ($bundle = $this->bundle) {
    $bundle_field_instances = $entity_field_instances[$bundle];
  }

  // Traverse the field instance to get all non hidden fields.
  $displayed_fields = array_map(function ($field_instance) use ($view_mode) {
    if (empty($field_instance['display'][$view_mode]) || $field_instance['display'][$view_mode]['type'] == 'hidden' || $field_instance['deleted']) {
      return NULL;
    }
    return $field_instance['field_name'];
  }, $bundle_field_instances);

  // Remove all NULL fields.
  return array_filter(array_values($displayed_fields));
}