/**
  * Constructor.
  *
  * @param RequestInterface $request
  *   The request.
  * @param ResourceFieldCollectionInterface $field_definitions
  *   The field definitions.
  * @param object $account
  *   The authenticated account.
  * @param string $plugin_id
  *   The resource ID.
  * @param string $resource_path
  *   The resource path.
  * @param array $options
  *   The plugin options for the data provider.
  * @param string $langcode
  *   (Optional) The entity language code.
  * @param ResourceInterface $resource
  *   The referenced resource.
  */
 public function __construct(RequestInterface $request, ResourceFieldCollectionInterface $field_definitions, $account, $plugin_id, $resource_path, array $options, $langcode = NULL, ResourceInterface $resource = NULL)
 {
     $resource->setRequest($request);
     $this->resource = $resource;
     $this->referencedDataProvider = $resource->getDataProvider();
     parent::__construct($request, $field_definitions, $account, $plugin_id, $resource_path, $options, $langcode);
 }
/**
 * Allow altering the request before it is processed.
 *
 * @param \Drupal\restful\Plugin\resource\ResourceInterface &$resource
 *   The resource object to alter.
 */
function hook_restful_resource_alter(\Drupal\restful\Plugin\resource\ResourceInterface &$resource)
{
    // Chain a decorator with the passed in resource based on the resource
    // annotation definition.
    $plugin_definition = $resource->getPluginDefinition();
    if (!empty($plugin_definition['renderCache']) && !empty($plugin_definition['renderCache']['render'])) {
        $resource = new \Drupal\restful\Plugin\resource\CachedResource($resource);
    }
}
 /**
  * Constructs a Drupal\Component\Plugin\PluginBase object.
  *
  * @param ResourceInterface $subject
  *   The decorated object.
  * @param RateLimitManager $rate_limit_manager
  *   Injected rate limit manager.
  */
 public function __construct(ResourceInterface $subject, RateLimitManager $rate_limit_manager = NULL)
 {
     $this->subject = $subject;
     $plugin_definition = $subject->getPluginDefinition();
     $rate_limit_info = empty($plugin_definition['rateLimit']) ? array() : $plugin_definition['rateLimit'];
     if ($limit = variable_get('restful_global_rate_limit', 0)) {
         $rate_limit_info['global'] = array('period' => variable_get('restful_global_rate_period', 'P1D'), 'limits' => array());
         foreach (user_roles() as $role_name) {
             $rate_limit_info['global']['limits'][$role_name] = $limit;
         }
     }
     $this->rateLimitManager = $rate_limit_manager ? $rate_limit_manager : new RateLimitManager($this, $rate_limit_info);
 }
 /**
  * Constructor for RateLimitManager.
  *
  * @param ResourceInterface $resource
  *   Resource being checked.
  * @param array $plugin_options
  *   Array of options keyed by plugin id.
  * @param object $account
  *   The identified user account for the request.
  * @param RateLimitPluginManager $manager
  *   The plugin manager.
  */
 public function __construct(ResourceInterface $resource, array $plugin_options, $account = NULL, RateLimitPluginManager $manager = NULL)
 {
     $this->resource = $resource;
     $account = $account ? $account : $resource->getAccount();
     $this->account = $account ? $account : drupal_anonymous_user();
     $manager = $manager ?: RateLimitPluginManager::create();
     $options = array();
     foreach ($plugin_options as $plugin_id => $rate_options) {
         // Set the instance id to articles::request and specify the plugin id.
         $instance_id = $resource->getResourceName() . PluginBase::DERIVATIVE_SEPARATOR . $plugin_id;
         $options[$instance_id] = array('id' => $plugin_id, 'resource' => $resource);
         $options[$instance_id] += $rate_options;
     }
     $this->plugins = new RateLimitPluginCollection($manager, $options);
 }
 /**
  * {@inheritdoc}
  */
 public function getVersion()
 {
     return $this->subject->getVersion();
 }
 /**
  * {@inheritdoc}
  */
 public function getPluginId()
 {
     return $this->subject->getPluginId();
 }