You are here

protected function RestfulEntityBase::addDefaultValuesToPublicFields in RESTful 7

Add default values to the public fields array.

Parameters

array $public_fields: The unprocessed public fields array.

Return value

array The processed public fields array.

Overrides RestfulBase::addDefaultValuesToPublicFields

File

plugins/restful/RestfulEntityBase.php, line 1283
Contains RestfulEntityBase.

Class

RestfulEntityBase
An abstract implementation of RestfulEntityInterface.

Code

protected function addDefaultValuesToPublicFields(array $public_fields = array()) {
  $public_fields = parent::addDefaultValuesToPublicFields($public_fields);

  // Set defaults values.
  foreach (array_keys($public_fields) as $key) {

    // Set default values specific for entities.
    $info =& $public_fields[$key];
    $info += array(
      'access_callbacks' => array(),
      'column' => FALSE,
      'property' => FALSE,
      'resource' => array(),
      'sub_property' => FALSE,
      'wrapper_method' => 'value',
      'wrapper_method_on_entity' => FALSE,
      'formatter' => FALSE,
    );
    if ($field = field_info_field($info['property'])) {

      // If it's an image check if we need to add image style processing.
      if ($field['type'] == 'image' && !empty($info['image_styles'])) {
        array_unshift($info['process_callbacks'], array(
          array(
            $this,
            'getImageUris',
          ),
          array(
            $info['image_styles'],
          ),
        ));
      }
      if ($info['property'] && !$info['column']) {

        // Set the column name.
        $info['column'] = key($field['columns']);
      }
      if ($this
        ->getMethod() == \RestfulInterface::OPTIONS) {
        $info += $this
          ->getFieldInfoAndFormSchema($field);
      }
    }
    foreach ($info['resource'] as &$resource) {

      // Expand array to be verbose.
      if (!is_array($resource)) {
        $resource = array(
          'name' => $resource,
        );
      }

      // Set default value.
      $resource += array(
        'full_view' => TRUE,
      );

      // Set the default value for the version of the referenced resource.
      if (!isset($resource['major_version']) || !isset($resource['minor_version'])) {
        list($major_version, $minor_version) = static::getResourceLastVersion($resource['name']);
        $resource['major_version'] = $major_version;
        $resource['minor_version'] = $minor_version;
      }
    }
  }
  return $public_fields;
}