function hook_rest_resource_alter

Same name in other branches
  1. 8.9.x core/modules/rest/rest.api.php \hook_rest_resource_alter()
  2. 10 core/modules/rest/rest.api.php \hook_rest_resource_alter()
  3. 11.x core/modules/rest/rest.api.php \hook_rest_resource_alter()

Alter the resource plugin definitions.

Parameters

array $definitions: The collection of resource definitions.

Related topics

1 function implements hook_rest_resource_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

contact_rest_resource_alter in core/modules/contact/contact.module
Implements hook_rest_resource_alter().
1 invocation of hook_rest_resource_alter()
ResourcePluginManager::__construct in core/modules/rest/src/Plugin/Type/ResourcePluginManager.php
Constructs a new \Drupal\rest\Plugin\Type\ResourcePluginManager object.

File

core/modules/rest/rest.api.php, line 19

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.