/** * {@inheritdoc} */ public static function create(array $field, RequestInterface $request = NULL) { $request = $request ?: restful()->getRequest(); $resource_field = ResourceField::create($field, $request); $output = new static($field, $request); $output->decorate($resource_field); return $output; }
/** * {@inheritdoc} */ 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; }