You are here

public function ResourceFieldCollection::__construct in RESTful 7.2

Constructor.

Creates the collection and each one of the field resource fields in it based on the configuration array.

Parameters

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.

RequestInterface $request: The request.

File

src/Plugin/resource/Field/ResourceFieldCollection.php, line 129
Contains \Drupal\restful\Plugin\resource\Field\ResourceFieldCollection.

Class

ResourceFieldCollection

Namespace

Drupal\restful\Plugin\resource\Field

Code

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');
}