class Discovery in RESTful 7.2
Class Discovery @package Drupal\restful_example\Plugin\Resource
Plugin annotation
@Resource(
name = "discovery:1.0",
resource = "discovery",
label = "Discovery",
description = "Discovery plugin.",
authenticationTypes = TRUE,
authenticationOptional = TRUE,
discoverable = FALSE,
dataProvider = {
"idField": "name"
},
menuItem = "",
majorVersion = 1,
minorVersion = 0
)
Hierarchy
- class \Drupal\restful\Plugin\resource\Resource extends \Drupal\Component\Plugin\PluginBase implements ResourceInterface uses ConfigurablePluginTrait
- class \Drupal\restful\Plugin\resource\Discovery
Expanded class hierarchy of Discovery
1 string reference to 'Discovery'
File
- src/
Plugin/ resource/ Discovery.php, line 33 - Contains \Drupal\restful\Plugin\resource\Discovery
Namespace
Drupal\restful\Plugin\resourceView source
class Discovery extends Resource {
/**
* {@inheritdoc}
*/
protected function publicFields() {
return array(
'label' => array(
'property' => 'label',
),
'description' => array(
'property' => 'description',
),
'name' => array(
'property' => 'name',
),
'resource' => array(
'property' => 'resource',
),
'majorVersion' => array(
'property' => 'majorVersion',
),
'minorVersion' => array(
'property' => 'minorVersion',
),
'self' => array(
'callback' => array(
$this,
'getSelf',
),
),
);
}
/**
* {@inheritdoc}
*/
protected function dataProviderClassName() {
return '\\Drupal\\restful\\Plugin\\resource\\DataProvider\\DataProviderPlug';
}
/**
* Returns the URL to the endpoint result.
*
* @param DataInterpreterInterface $interpreter
* The plugin's data interpreter.
*
* @return string
* The RESTful endpoint URL.
*/
public function getSelf(DataInterpreterInterface $interpreter) {
if ($menu_item = $interpreter
->getWrapper()
->get('menuItem')) {
$url = variable_get('restful_hook_menu_base_path', 'api') . '/' . $menu_item;
return url($url, array(
'absolute' => TRUE,
));
}
$base_path = variable_get('restful_hook_menu_base_path', 'api');
return url($base_path . '/v' . $interpreter
->getWrapper()
->get('majorVersion') . '.' . $interpreter
->getWrapper()
->get('minorVersion') . '/' . $interpreter
->getWrapper()
->get('resource'), array(
'absolute' => TRUE,
));
}
/**
* @inheritDoc
*/
public function controllersInfo() {
return array(
'' => array(
// GET returns a list of entities.
RequestInterface::METHOD_GET => 'index',
RequestInterface::METHOD_HEAD => 'index',
),
// We don't know what the ID looks like, assume that everything is the ID.
'^.*$' => array(
RequestInterface::METHOD_GET => 'view',
RequestInterface::METHOD_HEAD => 'view',
RequestInterface::METHOD_PUT => array(
'callback' => 'replace',
'access callback' => 'resourceManipulationAccess',
),
RequestInterface::METHOD_DELETE => array(
'callback' => 'remove',
'access callback' => 'resourceManipulationAccess',
),
),
);
}
/**
* Helper callback to check authorization for write operations.
*
* @param string $path
* The resource path.
*
* @return bool
* TRUE to grant access. FALSE otherwise.
*/
public function resourceManipulationAccess($path) {
return user_access('administer restful resources', $this
->getAccount());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigurablePluginTrait:: |
protected | property | Plugin instance configuration. | |
ConfigurablePluginTrait:: |
public | function | ||
ConfigurablePluginTrait:: |
public | function | ||
ConfigurablePluginTrait:: |
public | function | ||
Discovery:: |
public | function |
@inheritDoc Overrides Resource:: |
|
Discovery:: |
protected | function |
Data provider class. Overrides Resource:: |
|
Discovery:: |
public | function | Returns the URL to the endpoint result. | |
Discovery:: |
protected | function |
Public fields. Overrides Resource:: |
|
Discovery:: |
public | function | Helper callback to check authorization for write operations. | |
Resource:: |
protected | property | The authentication manager. | |
Resource:: |
protected | property | The data provider. | |
Resource:: |
protected | property | Indicates if the resource is enabled. | |
Resource:: |
protected | property | The field definition object. | |
Resource:: |
protected | property | The requested path. | |
Resource:: |
protected | property | The current request. | |
Resource:: |
public | function |
Determine if user can access the handler. Overrides ResourceInterface:: |
1 |
Resource:: |
protected | function | Checks access based on the referer header and the allowOrigin setting. | |
Resource:: |
public | function |
Basic implementation for create. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Data provider factory. Overrides ResourceInterface:: |
1 |
Resource:: |
public | function |
Overrides ConfigurablePluginTrait:: |
|
Resource:: |
public | function |
Disable the resource. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Discovery controller callback. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Shorthand method to perform a quick DELETE request. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Shorthand method to perform a quick GET request. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Shorthand method to perform a quick PATCH request. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Shorthand method to perform a quick POST request. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Shorthand method to perform a quick PUT request. Overrides ResourceInterface:: |
|
Resource:: |
private | function | ||
Resource:: |
public | function |
Enable the resource. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Get the user from for request. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Return the controller for a given path. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Gets the controllers for this resource. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Gets the data provider. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Gets the field definitions. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Gets the path of the resource. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Get the request object. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Gets the resource machine name. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Gets the resource name. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Helper method; Get the URL of the resource and query strings. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Return array keyed with the major and minor version of the resource. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Basic implementation for listing. Overrides ResourceInterface:: |
1 |
Resource:: |
protected | function | Initializes the authentication manager and adds the appropriate providers. | |
Resource:: |
public | function |
Checks if the resource is enabled. Overrides ResourceInterface:: |
|
Resource:: |
protected | function | Adds the Allowed-Origin headers. | |
Resource:: |
public | function |
Controller function that passes the data along and executes right action. Overrides ResourceInterface:: |
|
Resource:: |
protected | function | Get the public fields with the default values applied to them. | 2 |
Resource:: |
public | function |
Basic implementation for update. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Basic implementation for update. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Sets the data provider. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Sets the field definitions. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Sets the path of the resource. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Sets the plugin definition to the provided array. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Sets the request object. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Switches the user back from the original user for the session. Overrides ResourceInterface:: |
1 |
Resource:: |
public | function |
Basic implementation for update. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Gets a resource URL based on the current version. Overrides ResourceInterface:: |
|
Resource:: |
public | function |
Basic implementation for view. Overrides ResourceInterface:: |
|
Resource:: |
public | function | Constructs a Drupal\Component\Plugin\PluginBase object. | 1 |
ResourceInterface:: |
constant | The string that separates multiple ids. |