You are here

public function RestfulEntityViewMode::mapFields in RESTful 7

Generates the public properties configuration array from the mappings.

Parameters

string $view_mode: The view mode.

array $field_map: Associative array that maps field names to public properties.

Return value

array The public properties info array.

Throws

\RestfulServerConfigurationException

File

includes/RestfulEntityViewMode.php, line 59
Contains \RestfulEntityViewMode

Class

RestfulEntityViewMode
@file Contains \RestfulEntityViewMode

Code

public function mapFields($view_mode, $field_map) {
  $displayed_fields = $this
    ->displayedFieldsList($view_mode);

  // Set the mappings from the field name to the output key.
  $public_fields = array();
  foreach ($displayed_fields as $field_name) {
    if (empty($field_map[$field_name])) {
      throw new \RestfulServerConfigurationException(format_string('No mapping was found for @field_name.', array(
        '@field_name' => $field_name,
      )));
    }

    // Add it to the public fields array with a special callback function.
    $public_fields[$field_map[$field_name]] = array(
      'callback' => array(
        array(
          $this,
          'renderField',
        ),
        array(
          $field_name,
          $view_mode,
        ),
      ),
    );
  }
  if (empty($public_fields)) {
    throw new \RestfulServerConfigurationException('No fields shown rendering entity view mode.');
  }
  return $public_fields;
}