You are here

public function ResourceField::addDefaults in RESTful 7.2

Adds the default values to the definitions array.

Overrides ResourceFieldInterface::addDefaults

File

src/Plugin/resource/Field/ResourceField.php, line 103
Contains \Drupal\restful\Plugin\resource\ResourceField.

Class

ResourceField

Namespace

Drupal\restful\Plugin\resource\Field

Code

public function addDefaults() {

  // Almost all the defaults come are applied by the object's property
  // defaults.
  if (!($resource = $this
    ->getResource())) {
    return;
  }

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

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

  // Set the default value for the version of the referenced resource.
  if (!isset($resource['majorVersion']) || !isset($resource['minorVersion'])) {
    list($major_version, $minor_version) = restful()
      ->getResourceManager()
      ->getResourceLastVersion($resource['name']);
    $resource['majorVersion'] = $major_version;
    $resource['minorVersion'] = $minor_version;
  }
  $this
    ->setResource($resource);
}