You are here

class ResourceFieldReference in RESTful 7.2

Class ResourceFieldReference.

This field type is useful when you have an arbitrary field, that is not an entity reference field, that returns an ID to another resource. This resource field type will allow you to have a field definition with a callback return an ID and use that as a relationship.

This is specially useful when adding a relationship to an entity based resource from a DB query, or vice versa. See an example of this in action in the example resource main:1.8.

If you need to add a reference to entity things like $node->uid, use \Drupal\restful\Plugin\resource\Field\ResourceFieldEntityReference instead.

@package Drupal\restful\Plugin\resource\Field

Hierarchy

Expanded class hierarchy of ResourceFieldReference

File

src/Plugin/resource/Field/ResourceFieldReference.php, line 29
Contains \Drupal\restful\Plugin\resource\Field\ResourceFieldReference.

Namespace

Drupal\restful\Plugin\resource\Field
View source
class ResourceFieldReference extends ResourceField {

  /**
   * Overrides ResourceField::compoundDocumentId().
   */
  public function compoundDocumentId(DataInterpreterInterface $interpreter) {
    $collection = parent::compoundDocumentId($interpreter);
    if (!$collection instanceof ResourceFieldCollectionInterface) {
      return NULL;
    }
    $id_field = $collection
      ->getIdField();
    if (!$id_field instanceof ResourceFieldInterface) {
      return NULL;
    }
    return $id_field
      ->render($collection
      ->getInterpreter());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ResourceField::access public function Check access on property by the defined access callbacks. Overrides ResourceFieldInterface::access
ResourceField::addDefaults public function Adds the default values to the definitions array. Overrides ResourceFieldInterface::addDefaults
ResourceField::create public static function Factory. Overrides ResourceFieldInterface::create 2
ResourceField::fieldClassName public static function Get the class name to use based on the field definition.
ResourceField::getCardinality public function Gets the cardinality of the wrapped field. Overrides ResourceFieldInterface::getCardinality
ResourceField::render public function Gets the value of a field and applies all process callbacks to it. Overrides ResourceFieldInterface::render
ResourceField::set public function Gets the value for the field given a data source. Overrides ResourceFieldInterface::set
ResourceField::setCardinality public function Set the cardinality. Overrides ResourceFieldInterface::setCardinality
ResourceField::value public function Gets the value for the field given a data source. Overrides ResourceFieldInterface::value 2
ResourceField::__construct public function Constructor. 1
ResourceFieldBase::$accessCallbacks 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::$callback 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::$cardinality protected property Holds the field cardinality.
ResourceFieldBase::$definition protected property The field definition array.
ResourceFieldBase::$metadata protected property A generic array storage.
ResourceFieldBase::$methods protected property The HTTP methods where this field applies.
ResourceFieldBase::$processCallbacks protected property An array of callbacks to perform on the returned value, or an array with the object and method.
ResourceFieldBase::$property protected property The entity property (e.g. "title", "nid").
ResourceFieldBase::$publicFieldInfo protected property Information about the field.
ResourceFieldBase::$publicName protected property Contains the public field name.
ResourceFieldBase::$request protected property The request object to be used.
ResourceFieldBase::$resource 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::ACCESS_ALLOW constant Return this value from public field access callbacks to allow access.
ResourceFieldBase::ACCESS_DENY constant Return this value from public field access callbacks to deny access.
ResourceFieldBase::ACCESS_IGNORE constant Return this value from public field access callbacks to not affect access.
ResourceFieldBase::addMetadata public function Add metadata to the field. Overrides ResourceFieldInterface::addMetadata
ResourceFieldBase::autoDiscovery public function Basic auto discovery information.
ResourceFieldBase::emptyDiscoveryInfo public static function Returns the basic discovery information for a given field.
ResourceFieldBase::executeProcessCallbacks public function Executes the process callbacks. Overrides ResourceFieldInterface::executeProcessCallbacks
ResourceFieldBase::getAccessCallbacks public function Overrides ResourceFieldInterface::getAccessCallbacks
ResourceFieldBase::getCallback public function Overrides ResourceFieldInterface::getCallback
ResourceFieldBase::getDefinition public function Gets the original field definition as declared in Resource::publicFields(). Overrides ResourceFieldInterface::getDefinition
ResourceFieldBase::getMetadata public function Add metadata to the field. Overrides ResourceFieldInterface::getMetadata
ResourceFieldBase::getMethods public function Overrides ResourceFieldInterface::getMethods
ResourceFieldBase::getProcessCallbacks public function Overrides ResourceFieldInterface::getProcessCallbacks
ResourceFieldBase::getProperty public function Overrides ResourceFieldInterface::getProperty
ResourceFieldBase::getPublicFieldInfo public function Gets the public field info object. Overrides ResourceFieldInterface::getPublicFieldInfo
ResourceFieldBase::getPublicName public function Overrides ResourceFieldInterface::getPublicName
ResourceFieldBase::getRequest public function Get the request in the data provider. Overrides ResourceFieldInterface::getRequest
ResourceFieldBase::getResource public function Overrides ResourceFieldInterface::getResource
ResourceFieldBase::id public function Gets the ID of the resource field. Overrides ResourceFieldInterface::id
ResourceFieldBase::internalMetadataElement protected function Returns the last array element from the nested namespace array.
ResourceFieldBase::isArrayNumeric final public static function Helper method to determine if an array is numeric. Overrides ResourceFieldInterface::isArrayNumeric
ResourceFieldBase::isComputed public function Checks if the current field is computed. Overrides ResourceFieldInterface::isComputed
ResourceFieldBase::setAccessCallbacks public function Overrides ResourceFieldInterface::setAccessCallbacks
ResourceFieldBase::setCallback public function Overrides ResourceFieldInterface::setCallback
ResourceFieldBase::setMethods public function Overrides ResourceFieldInterface::setMethods
ResourceFieldBase::setProcessCallbacks public function Overrides ResourceFieldInterface::setProcessCallbacks
ResourceFieldBase::setProperty public function Overrides ResourceFieldInterface::setProperty
ResourceFieldBase::setPublicFieldInfo public function Gets the public field info object. Overrides ResourceFieldInterface::setPublicFieldInfo
ResourceFieldBase::setPublicName public function Overrides ResourceFieldInterface::setPublicName
ResourceFieldBase::setRequest public function Set the request. Overrides ResourceFieldInterface::setRequest
ResourceFieldBase::setResource public function Overrides ResourceFieldInterface::setResource
ResourceFieldReference::compoundDocumentId public function Overrides ResourceField::compoundDocumentId(). Overrides ResourceField::compoundDocumentId