You are here

class ResourceFieldFileEntityReference in RESTful 7.2

Hierarchy

Expanded class hierarchy of ResourceFieldFileEntityReference

File

src/Plugin/resource/Field/ResourceFieldFileEntityReference.php, line 15
Contains \Drupal\restful\Plugin\resource\Field\ResourceFieldFileEntityReference.

Namespace

Drupal\restful\Plugin\resource\Field
View source
class ResourceFieldFileEntityReference extends ResourceFieldEntityReference implements ResourceFieldEntityReferenceInterface {

  // TODO: Add testing to this!

  /**
   * Helper function to get the identifier from a property wrapper.
   *
   * @param \EntityMetadataWrapper $property_wrapper
   *   The property wrapper to get the ID from.
   *
   * @return string
   *   An identifier.
   */
  protected function propertyIdentifier(\EntityMetadataWrapper $property_wrapper) {

    // The property wrapper is a reference to another entity get the entity
    // ID.
    $file_array = $property_wrapper
      ->value();
    $identifier = $file_array['fid'];
    $resource = $this
      ->getResource();

    // TODO: Make sure we still want to support fullView.
    if (!$resource || !$identifier || isset($resource['fullView']) && $resource['fullView'] === FALSE) {
      return $identifier;
    }

    // If there is a resource that we are pointing to, we need to use the id
    // field that that particular resource has in its configuration. Trying to
    // load by the entity id in that scenario will lead to a 404.
    // We'll load the plugin to get the idField configuration.
    $instance_id = sprintf('%s:%d.%d', $resource['name'], $resource['majorVersion'], $resource['minorVersion']);

    /* @var ResourceInterface $resource */
    $resource = restful()
      ->getResourceManager()
      ->getPluginCopy($instance_id, Request::create('', array(), RequestInterface::METHOD_GET));
    $plugin_definition = $resource
      ->getPluginDefinition();
    if (empty($plugin_definition['dataProvider']['idField'])) {
      return $identifier;
    }
    try {
      $file_wrapper = entity_metadata_wrapper('file', $file_array['fid']);
      return $file_wrapper->{$plugin_definition['dataProvider']['idField']}
        ->value();
    } catch (\EntityMetadataWrapperException $e) {
      return $identifier;
    }
  }

  /**
   * Builds a metadata item for a field value.
   *
   * It will add information about the referenced entity.
   *
   * @param \EntityMetadataWrapper $wrapper
   *   The wrapper for the referenced file array.
   *
   * @return array
   *   The metadata array item.
   */
  protected function buildResourceMetadataItem($wrapper) {
    $file_array = $wrapper
      ->value();

    /* @var \EntityDrupalWrapper $wrapper */
    $wrapper = entity_metadata_wrapper('file', $file_array['fid']);
    return parent::buildResourceMetadataItem($wrapper);
  }

  /**
   * Helper function to get the referenced entity ID.
   *
   * @param \EntityStructureWrapper $property_wrapper
   *   The wrapper for the referenced file array.
   *
   * @return mixed
   *   The ID.
   */
  protected function referencedId($property_wrapper) {
    $file_array = $property_wrapper
      ->value();
    if (!$this->referencedIdProperty) {
      return $file_array['fid'];
    }

    /* @var \EntityDrupalWrapper $wrapper */
    $wrapper = entity_metadata_wrapper('file', $file_array['fid']);
    return $wrapper->{$this->referencedIdProperty}
      ->value();
  }

  /**
   * {@inheritdoc}
   */
  public function getRequest() {
    return $this->decorated
      ->getRequest();
  }

  /**
   * {@inheritdoc}
   */
  public function setRequest(RequestInterface $request) {
    $this->decorated
      ->setRequest($request);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ResourceFieldEntity::$bundle protected property The bundle name.
ResourceFieldEntity::$column protected property If the property is a field, set the column that would be used in queries. For example, the default column for a text field would be "value". Defaults to the first column returned by field_info_field(), otherwise FALSE.
ResourceFieldEntity::$decorated protected property Decorated resource field.
ResourceFieldEntity::$entityType protected property The entity type.
ResourceFieldEntity::$formatter protected property Used for rendering the value of a configurable field using Drupal field API's formatter. The value is the $display value that is passed to field_view_field().
ResourceFieldEntity::$imageStyles protected property Array of image styles to apply to this resource field maps to an image field.
ResourceFieldEntity::$property protected property A copy of the underlying property.
ResourceFieldEntity::$subProperty protected property A sub property name of a property to take from it the content.
ResourceFieldEntity::$wrapperMethod protected property The wrapper's method name to perform on the field. This can be used for example to get the entity label, by setting the value to "label". Defaults to "value".
ResourceFieldEntity::$wrapperMethodOnEntity protected property A Boolean to indicate on what to perform the wrapper method. If TRUE the method will perform on the entity (e.g. $wrapper->label()) and FALSE on the property or sub property (e.g. $wrapper->field_reference->label()).
ResourceFieldEntity::access public function Overrides ResourceFieldInterface::access
ResourceFieldEntity::addDefaults public function Almost all the defaults come are applied by the object's property defaults. Overrides ResourceFieldInterface::addDefaults
ResourceFieldEntity::addMetadata public function Add metadata to the field. Overrides ResourceFieldInterface::addMetadata
ResourceFieldEntity::autoDiscovery public function
ResourceFieldEntity::compoundDocumentId public function Fetches the embedded identifier(s) for the current resource field, if any. Overrides ResourceFieldInterface::compoundDocumentId
ResourceFieldEntity::create public static function Factory. Overrides ResourceFieldInterface::create
ResourceFieldEntity::decorate public function Decorate the object. Overrides ResourceFieldEntityInterface::decorate
ResourceFieldEntity::entityTypeWrapper protected function Gets the \EntityStructureWrapper for the entity type.
ResourceFieldEntity::executeProcessCallbacks public function Executes the process callbacks. Overrides ResourceFieldInterface::executeProcessCallbacks 2
ResourceFieldEntity::fieldClassName public static function Get the class name to use based on the field definition.
ResourceFieldEntity::fieldInfoField protected static function Gets statically cached information about a field.
ResourceFieldEntity::fieldValue protected function Get value from a property.
ResourceFieldEntity::formatterValue protected function Get value from a field rendered by Drupal field API's formatter.
ResourceFieldEntity::getAccessCallbacks public function Overrides ResourceFieldInterface::getAccessCallbacks
ResourceFieldEntity::getBundle public function Overrides ResourceFieldEntityInterface::getBundle
ResourceFieldEntity::getCallback public function Overrides ResourceFieldInterface::getCallback
ResourceFieldEntity::getCardinality public function Gets the cardinality of the wrapped field. Overrides ResourceFieldInterface::getCardinality
ResourceFieldEntity::getColumn public function Overrides ResourceFieldEntityInterface::getColumn
ResourceFieldEntity::getEntityType public function Overrides ResourceFieldEntityInterface::getEntityType
ResourceFieldEntity::getFormatter public function Overrides ResourceFieldEntityInterface::getFormatter
ResourceFieldEntity::getImageStyles public function Overrides ResourceFieldEntityInterface::getImageStyles
ResourceFieldEntity::getImageUris public static function Get the image URLs based on the configured image styles. Overrides ResourceFieldEntityInterface::getImageUris
ResourceFieldEntity::getMetadata public function Add metadata to the field. Overrides ResourceFieldInterface::getMetadata
ResourceFieldEntity::getMethods public function Overrides ResourceFieldInterface::getMethods
ResourceFieldEntity::getProcessCallbacks public function Overrides ResourceFieldInterface::getProcessCallbacks
ResourceFieldEntity::getProperty public function Overrides ResourceFieldInterface::getProperty
ResourceFieldEntity::getPublicFieldInfo public function Gets the public field info object. Overrides ResourceFieldInterface::getPublicFieldInfo
ResourceFieldEntity::getPublicName public function Overrides ResourceFieldInterface::getPublicName
ResourceFieldEntity::getResource public function Overrides ResourceFieldInterface::getResource
ResourceFieldEntity::getSubProperty public function Overrides ResourceFieldEntityInterface::getSubProperty
ResourceFieldEntity::getWrapperMethod public function Overrides ResourceFieldEntityInterface::getWrapperMethod
ResourceFieldEntity::id public function Gets the ID of the resource field. Overrides ResourceFieldInterface::id
ResourceFieldEntity::isArrayNumeric public static function Helper method to determine if an array is numeric. Overrides ResourceFieldInterface::isArrayNumeric
ResourceFieldEntity::isComputed public function Checks if the current field is computed. Overrides ResourceFieldInterface::isComputed
ResourceFieldEntity::isWrapperMethodOnEntity public function Overrides ResourceFieldEntityInterface::isWrapperMethodOnEntity
ResourceFieldEntity::nestedDottedChildren protected function Get the children of a query string parameter that apply to the field.
ResourceFieldEntity::nestedDottedFilters protected function Process the filter query string for the relevant sub-query.
ResourceFieldEntity::populatePublicInfoField protected function Populate public info field with Property API information.
ResourceFieldEntity::propertyIsField public static function Checks if a given string represents a Field API field. Overrides ResourceFieldEntityInterface::propertyIsField
ResourceFieldEntity::propertyOnEntity protected function Sets the resource field property to the schema field in the entity.
ResourceFieldEntity::propertyWrapper protected function Get the wrapper for the property associated to the current field.
ResourceFieldEntity::render public function Gets the value of a field and applies all process callbacks to it. Overrides ResourceFieldInterface::render
ResourceFieldEntity::resourceValue protected function Get value for a field based on another resource.
ResourceFieldEntity::set public function Gets the value for the field given a data source. Overrides ResourceFieldInterface::set
ResourceFieldEntity::setAccessCallbacks public function Overrides ResourceFieldInterface::setAccessCallbacks
ResourceFieldEntity::setBundle public function Overrides ResourceFieldEntityInterface::setBundle
ResourceFieldEntity::setCallback public function Overrides ResourceFieldInterface::setCallback
ResourceFieldEntity::setCardinality public function Set the cardinality. Overrides ResourceFieldInterface::setCardinality
ResourceFieldEntity::setColumn public function Overrides ResourceFieldEntityInterface::setColumn
ResourceFieldEntity::setEntityType public function Overrides ResourceFieldEntityInterface::setEntityType
ResourceFieldEntity::setFormatter public function Overrides ResourceFieldEntityInterface::setFormatter
ResourceFieldEntity::setImageStyles public function Overrides ResourceFieldEntityInterface::setImageStyles
ResourceFieldEntity::setMethods public function Overrides ResourceFieldInterface::setMethods
ResourceFieldEntity::setProcessCallbacks public function Overrides ResourceFieldInterface::setProcessCallbacks
ResourceFieldEntity::setProperty public function Overrides ResourceFieldInterface::setProperty
ResourceFieldEntity::setPublicFieldInfo public function Gets the public field info object. Overrides ResourceFieldInterface::setPublicFieldInfo
ResourceFieldEntity::setPublicName public function Overrides ResourceFieldInterface::setPublicName
ResourceFieldEntity::setResource public function Overrides ResourceFieldInterface::setResource
ResourceFieldEntity::setSubProperty public function Overrides ResourceFieldEntityInterface::setSubProperty
ResourceFieldEntity::setWrapperMethod public function Overrides ResourceFieldEntityInterface::setWrapperMethod
ResourceFieldEntity::setWrapperMethodOnEntity public function Overrides ResourceFieldEntityInterface::setWrapperMethodOnEntity
ResourceFieldEntity::singleValue protected function Returns the value for the current single field.
ResourceFieldEntityReference::$referencedIdProperty protected property Property where the ID should be retrieved from.
ResourceFieldEntityReference::getDefinition public function Gets the original field definition as declared in Resource::publicFields(). Overrides ResourceFieldEntity::getDefinition
ResourceFieldEntityReference::mergeEntityFromReference protected function Helper function; Create an entity from a a sub-resource.
ResourceFieldEntityReference::preprocess public function Massage the value to set according to the format expected by the wrapper. Overrides ResourceFieldEntity::preprocess
ResourceFieldEntityReference::subRequest public static function Creates a request object for the sub-request. Overrides ResourceFieldEntityReferenceInterface::subRequest
ResourceFieldEntityReference::subRequestId protected static function Get the ID of the resource this write sub-request is for.
ResourceFieldEntityReference::value public function Gets the value for the field given a data source. Overrides ResourceFieldEntity::value
ResourceFieldEntityReference::__construct public function Constructs a ResourceFieldEntityReference. Overrides ResourceFieldEntity::__construct
ResourceFieldFileEntityReference::buildResourceMetadataItem protected function Builds a metadata item for a field value. Overrides ResourceFieldEntity::buildResourceMetadataItem
ResourceFieldFileEntityReference::getRequest public function Get the request in the data provider. Overrides ResourceFieldEntityReference::getRequest
ResourceFieldFileEntityReference::propertyIdentifier protected function Helper function to get the identifier from a property wrapper. Overrides ResourceFieldEntity::propertyIdentifier
ResourceFieldFileEntityReference::referencedId protected function Helper function to get the referenced entity ID. Overrides ResourceFieldEntityReference::referencedId
ResourceFieldFileEntityReference::setRequest public function Set the request. Overrides ResourceFieldEntityReference::setRequest