Represents entities as resources.
@Plugin(
id = "entity",
label = @Translation("Entity"),
derivative = "Drupal\rest\Plugin\Derivative\EntityDerivative"
)
Expanded class hierarchy of EntityResource
class EntityResource extends ResourceBase {
/**
* Responds to entity GET requests.
*
* @param mixed $id
* The entity ID.
*
* @return \Drupal\rest\ResourceResponse
* The response containing the loaded entity.
*
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
*/
public function get($id) {
$definition = $this
->getDefinition();
$entity = entity_load($definition['entity_type'], $id);
if ($entity) {
return new ResourceResponse($entity);
}
throw new NotFoundHttpException(t('Entity with ID @id not found', array(
'@id' => $id,
)));
}
/**
* Responds to entity DELETE requests.
*
* @param mixed $id
* The entity ID.
*
* @return \Drupal\rest\ResourceResponse
* The HTTP response object.
*
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
*/
public function delete($id) {
$definition = $this
->getDefinition();
$entity = entity_load($definition['entity_type'], $id);
if ($entity) {
try {
$entity
->delete();
// Delete responses have an empty body.
return new ResourceResponse(NULL, 204);
} catch (EntityStorageException $e) {
throw new HttpException(500, 'Internal Server Error', $e);
}
}
throw new NotFoundHttpException(t('Entity with ID @id not found', array(
'@id' => $id,
)));
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityResource:: |
public | function | Responds to entity DELETE requests. | |
EntityResource:: |
public | function | Responds to entity GET requests. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The discovery object. | |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
public | function |
Implements Drupal\Component\Plugin\PluginInterface::getDefinition(). Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function |
Implements Drupal\Component\Plugin\PluginInterface::getPluginId(). Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Constructs a Drupal\Component\Plugin\PluginBase object. | 8 |
ResourceBase:: |
public | function | Provides an array of permissions suitable for hook_permission(). | |
ResourceBase:: |
protected | function | Provides predefined HTTP request methods. | |
ResourceBase:: |
public | function | Returns a collection of routes with URL path information for the resource. | 1 |