/** * {@inheritdoc} */ public function value(DataInterpreterInterface $interpreter) { if ($value = parent::value($interpreter)) { return $value; } return $interpreter->getWrapper()->get($this->getProperty()); }
/** * 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()); }
/** * Login a user and return a JSON along with the authentication cookie. * * @return array * Array with the public fields populated. */ public function loginAndRespondWithCookie() { // Login the user. $account = $this->getAccount(); $this->loginUser($account); $user_resource = restful()->getResourceManager()->getPlugin('users:1.0'); // User resource may be disabled. $output = $user_resource ? $user_resource->view($account->uid) : array(); if ($resource_field_collection = reset($output)) { /* @var $resource_field_collection \Drupal\restful\Plugin\resource\Field\ResourceFieldCollectionInterface */ $resource_field_collection->set('X-CSRF-Token', ResourceField::create(array('public_name' => 'X-CSRF-Token', 'callback' => '\\Drupal\\restful\\Plugin\\resource\\LoginCookie__1_0::getCSRFTokenValue'))); } return $output; }
/** * {@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; }
/** * Constructor. * * Creates the collection and each one of the field resource fields in it * based on the configuration array. * * @param array $fields * Array with the optional values: * - "access_callbacks": 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 certain request * conditions. The Passed arguments are: * - op: The operation that access should be checked for. Can be "view" or * "edit". * - public_field_name: The name of the public field. * - property_wrapper: The wrapped property. * - wrapper: The wrapped entity. * - "property": The entity property (e.g. "title", "nid"). * - "sub_property": A sub property name of a property to take from it the * content. This can be used for example on a text field with filtered text * input format where we would need to do $wrapper->body->value->value(). * Defaults to FALSE. * - "formatter": 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(). * - "wrapper_method": 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". * - "wrapper_method_on_entity": 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()). Defaults to FALSE. * - "column": 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. * - "callback": 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 * EntityMetadataWrapper object. * - "process_callbacks": An array of callbacks to perform on the returned * value, or an array with the object and method. Defaults To empty array. * - "resource": 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 those bundles to their related * resource. Items with bundles that were not explicitly set would be * ignored. * It is also possible to pass an array as the value, with: * - "name": The resource name. * - "fullView": Determines if the referenced resource should be rendered * or just the referenced ID(s) to appear. Defaults to TRUE. * array( * // Shorthand. * 'article' => 'articles', * // Verbose * 'page' => array( * 'name' => 'pages', * 'fullView' => FALSE, * ), * ); * - "create_or_update_passthrough": Determines if a public field that isn't * mapped to any property or field, may be passed upon create or update * of an entity. Defaults to FALSE. * @param RequestInterface $request * The request. */ public function __construct(array $fields = array(), RequestInterface $request) { foreach ($fields as $public_name => $field_info) { $field_info['public_name'] = $public_name; // The default values are added. if (empty($field_info['resource'])) { $resource_field = ResourceField::create($field_info, $request); } else { $resource_field = ResourceFieldResource::create($field_info, $request); } $this->fields[$resource_field->id()] = $resource_field; } $this->idField = empty($fields['id']) ? NULL : $this->get('id'); }