class ResourceField in RESTful 7.2
Hierarchy
- class \Drupal\restful\Plugin\resource\Field\ResourceFieldBase implements ResourceFieldInterface
- class \Drupal\restful\Plugin\resource\Field\ResourceField implements ResourceFieldInterface
Expanded class hierarchy of ResourceField
1 file declares its use of ResourceField
- LoginCookie__1_0.php in src/
Plugin/ resource/ LoginCookie__1_0.php - Contains \Drupal\restful\Plugin\resource\LoginCookie__1_0.
File
- src/
Plugin/ resource/ Field/ ResourceField.php, line 15 - Contains \Drupal\restful\Plugin\resource\ResourceField.
Namespace
Drupal\restful\Plugin\resource\FieldView source
class ResourceField extends ResourceFieldBase implements ResourceFieldInterface {
/**
* Constructor.
*
* @param array $field
* Contains the field values.
*
* @throws ServerConfigurationException
*/
public function __construct(array $field, RequestInterface $request) {
$this
->setRequest($request);
if (empty($field['public_name'])) {
throw new ServerConfigurationException('No public name provided in the field mappings.');
}
$this->publicName = $field['public_name'];
$this->accessCallbacks = isset($field['access_callbacks']) ? $field['access_callbacks'] : $this->accessCallbacks;
$this->property = isset($field['property']) ? $field['property'] : $this->property;
// $this->column = isset($field['column']) ? $field['column'] : $this->column;
$this->callback = isset($field['callback']) ? $field['callback'] : $this->callback;
$this->processCallbacks = isset($field['process_callbacks']) ? $field['process_callbacks'] : $this->processCallbacks;
$this->resource = isset($field['resource']) ? $field['resource'] : $this->resource;
$this->methods = isset($field['methods']) ? $field['methods'] : $this->methods;
// Store the definition, useful to access custom keys on custom resource
// fields.
$this->definition = $field;
}
/**
* {@inheritdoc}
*/
public static function create(array $field, RequestInterface $request = NULL) {
$request = $request ?: restful()
->getRequest();
if ($class_name = static::fieldClassName($field)) {
if ($class_name != get_called_class() && $class_name != '\\' . get_called_class()) {
// Call the create factory in the derived class.
return call_user_func_array(array(
$class_name,
'create',
), array(
$field,
$request,
new static($field, $request),
));
}
}
// If no other class was found, then use the current one.
$resource_field = new static($field, $request);
$resource_field
->addDefaults();
return $resource_field;
}
/**
* {@inheritdoc}
*/
public function value(DataInterpreterInterface $interpreter) {
if ($callback = $this
->getCallback()) {
return ResourceManager::executeCallback($callback, array(
$interpreter,
));
}
return NULL;
}
/**
* {@inheritdoc}
*/
public function set($value, DataInterpreterInterface $interpreter) {
// ResourceField only supports callbacks, so no set is possible.
}
/**
* {@inheritdoc}
*/
public function access($op, DataInterpreterInterface $interpreter) {
foreach ($this
->getAccessCallbacks() as $callback) {
$result = ResourceManager::executeCallback($callback, array(
$op,
$this,
$interpreter,
));
if ($result == ResourceFieldBase::ACCESS_DENY) {
return FALSE;
}
}
return TRUE;
}
/**
* {@inheritdoc}
*/
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);
}
/**
* Get the class name to use based on the field definition.
*
* @param array $field_definition
* The processed field definition with the user values.
*
* @return string
* The class name to use. If the class name is empty or does not implement
* ResourceFieldInterface then ResourceField will be used. NULL if nothing
* was found.
*/
public static function fieldClassName(array $field_definition) {
if (!empty($field_definition['class'])) {
$class_name = $field_definition['class'];
}
elseif (!empty($field_definition['sub_property']) || !empty($field_definition['formatter']) || !empty($field_definition['wrapper_method']) || !empty($field_definition['wrapper_method_on_entity']) || !empty($field_definition['column']) || !empty($field_definition['image_styles']) || (!empty($field_definition['property']) ? field_info_field($field_definition['property']) : NULL)) {
$class_name = '\\Drupal\\restful\\Plugin\\resource\\Field\\ResourceFieldEntity';
}
elseif (!empty($field_definition['property'])) {
$class_name = '\\Drupal\\restful\\Plugin\\resource\\Field\\ResourceFieldKeyValue';
}
if (!empty($class_name) && class_exists($class_name) && in_array('Drupal\\restful\\Plugin\\resource\\Field\\ResourceFieldInterface', class_implements($class_name))) {
return $class_name;
}
return NULL;
}
/**
* {@inheritdoc}
*/
public function compoundDocumentId(DataInterpreterInterface $interpreter) {
// Since this kind of field can be anything, just return the value.
return $this
->value($interpreter);
}
/**
* {@inheritdoc}
*/
public function render(DataInterpreterInterface $interpreter) {
return $this
->executeProcessCallbacks($this
->value($interpreter));
}
/**
* {@inheritdoc}
*/
public function getCardinality() {
// Default to cardinality of 1.
return 1;
}
/**
* {@inheritdoc}
*/
public function setCardinality($cardinality) {
$this->cardinality = $cardinality;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ResourceField:: |
public | function |
Check access on property by the defined access callbacks. Overrides ResourceFieldInterface:: |
|
ResourceField:: |
public | function |
Adds the default values to the definitions array. Overrides ResourceFieldInterface:: |
|
ResourceField:: |
public | function |
Fetches the embedded identifier(s) for the current resource field, if any. Overrides ResourceFieldInterface:: |
1 |
ResourceField:: |
public static | function |
Factory. Overrides ResourceFieldInterface:: |
2 |
ResourceField:: |
public static | function | Get the class name to use based on the field definition. | |
ResourceField:: |
public | function |
Gets the cardinality of the wrapped field. Overrides ResourceFieldInterface:: |
|
ResourceField:: |
public | function |
Gets the value of a field and applies all process callbacks to it. Overrides ResourceFieldInterface:: |
|
ResourceField:: |
public | function |
Gets the value for the field given a data source. Overrides ResourceFieldInterface:: |
|
ResourceField:: |
public | function |
Set the cardinality. Overrides ResourceFieldInterface:: |
|
ResourceField:: |
public | function |
Gets the value for the field given a data source. Overrides ResourceFieldInterface:: |
2 |
ResourceField:: |
public | function | Constructor. | 1 |
ResourceFieldBase:: |
protected | property | An array of callbacks to determine if user has access to the property. Note that this callback is on top of the access provided by entity API, and is used for convenience, where for example write operation on a property should be denied only on… | |
ResourceFieldBase:: |
protected | property | A callable callback to get a computed value. The wrapped entity is passed as argument. Defaults To FALSE. The callback function receive as first argument the entity. | |
ResourceFieldBase:: |
protected | property | Holds the field cardinality. | |
ResourceFieldBase:: |
protected | property | The field definition array. | |
ResourceFieldBase:: |
protected | property | A generic array storage. | |
ResourceFieldBase:: |
protected | property | The HTTP methods where this field applies. | |
ResourceFieldBase:: |
protected | property | An array of callbacks to perform on the returned value, or an array with the object and method. | |
ResourceFieldBase:: |
protected | property | The entity property (e.g. "title", "nid"). | |
ResourceFieldBase:: |
protected | property | Information about the field. | |
ResourceFieldBase:: |
protected | property | Contains the public field name. | |
ResourceFieldBase:: |
protected | property | The request object to be used. | |
ResourceFieldBase:: |
protected | property | This property can be assigned only to an entity reference field. Array of restful resources keyed by the target bundle. For example, if the field is referencing a node entity, with "Article" and "Page" bundles, we are able to map… | |
ResourceFieldBase:: |
constant | Return this value from public field access callbacks to allow access. | ||
ResourceFieldBase:: |
constant | Return this value from public field access callbacks to deny access. | ||
ResourceFieldBase:: |
constant | Return this value from public field access callbacks to not affect access. | ||
ResourceFieldBase:: |
public | function |
Add metadata to the field. Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
public | function | Basic auto discovery information. | |
ResourceFieldBase:: |
public static | function | Returns the basic discovery information for a given field. | |
ResourceFieldBase:: |
public | function |
Executes the process callbacks. Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
public | function |
Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
public | function |
Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
public | function |
Gets the original field definition as declared in Resource::publicFields(). Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
public | function |
Add metadata to the field. Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
public | function |
Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
public | function |
Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
public | function |
Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
public | function |
Gets the public field info object. Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
public | function |
Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
public | function |
Get the request in the data provider. Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
public | function |
Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
public | function |
Gets the ID of the resource field. Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
protected | function | Returns the last array element from the nested namespace array. | |
ResourceFieldBase:: |
final public static | function |
Helper method to determine if an array is numeric. Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
public | function |
Checks if the current field is computed. Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
public | function |
Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
public | function |
Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
public | function |
Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
public | function |
Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
public | function |
Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
public | function |
Gets the public field info object. Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
public | function |
Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
public | function |
Set the request. Overrides ResourceFieldInterface:: |
|
ResourceFieldBase:: |
public | function |
Overrides ResourceFieldInterface:: |