You are here

public static function ResourceFieldEntity::create in RESTful 7.2

Factory.

Parameters

array $field: Contains the field values.

RequestInterface $request: The request.

Return value

ResourceFieldInterface The created field

Throws

ServerConfigurationException

Overrides ResourceFieldInterface::create

File

src/Plugin/resource/Field/ResourceFieldEntity.php, line 148
Contains \Drupal\restful\Plugin\resource\Field\ResourceFieldEntity

Class

ResourceFieldEntity
Class ResourceFieldEntity.

Namespace

Drupal\restful\Plugin\resource\Field

Code

public static function create(array $field, RequestInterface $request = NULL, ResourceFieldInterface $decorated = NULL) {
  $request = $request ?: restful()
    ->getRequest();
  $resource_field = NULL;
  $class_name = static::fieldClassName($field);

  // If the class exists and is a ResourceFieldEntityInterface use that one.
  if ($class_name && class_exists($class_name) && in_array('Drupal\\restful\\Plugin\\resource\\Field\\ResourceFieldEntityInterface', class_implements($class_name))) {
    $resource_field = new $class_name($field, $request);
  }

  // If no specific class was found then use the current one.
  if (!$resource_field) {

    // Create the current object.
    $resource_field = new static($field, $request);
  }
  if (!$resource_field) {
    throw new ServerConfigurationException('Unable to create resource field');
  }

  // Set the basic object to the decorated property.
  $resource_field
    ->decorate($decorated ? $decorated : new ResourceField($field, $request));
  $resource_field->decorated
    ->addDefaults();

  // Add the default specifics for the current object.
  $resource_field
    ->addDefaults();
  return $resource_field;
}