W3cubDocs

/Drupal 8

function hook_rest_resource_alter

hook_rest_resource_alter(&$definitions)

Alter the resource plugin definitions.

Parameters

array $definitions: The collection of resource definitions.

Related topics

Hooks
Define functions that alter the behavior of Drupal core.

File

core/modules/rest/rest.api.php, line 19
Describes hooks provided by the RESTful Web Services module.

Code

function hook_rest_resource_alter(&$definitions) {
  if (isset($definitions['entity:node'])) {
    // We want to handle REST requests regarding nodes with our own plugin
    // class.
    $definitions['entity:node']['class'] = 'Drupal\mymodule\Plugin\rest\resource\NodeResource';
    // Serialized nodes should be expanded to my specific node class.
    $definitions['entity:node']['serialization_class'] = 'Drupal\mymodule\Entity\MyNode';
  }
  // We don't want Views to show up in the array of plugins at all.
  unset($definitions['entity:view']);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!rest!rest.api.php/function/hook_rest_resource_alter/8.1.x