protected function ServicesResourceControllerAbstract::getInfoElement in Services Entity API 7.2
Helper function to return basic information about a resource operation.
Invoke this method to build the basic info array, and then override elements as needed for your specific entity/operation.
Parameters
string $entity_type: The entity type.
string $controller_method: The name of the method the service should invoke on the controller. This must be defined in the controller class.
$access_op: If set, the $op value to pass to the access method for this operation. Defaults to the method name. This is useful when the operation expected by entity_access() differs from the method name (e.g. 'view' rather than 'retrieve'), or when you want to use the same access rules for more than one method (for example, a relationship might want to simply use the entity's default 'view' access).
boolean $id_arg: If set, add an argument representing the entity_id. This will be taken from path index 0.
boolean $values_arg: If set, add an argument representing the entity values. This will be taken from the POST data.
Return value
An info array which can be used as a basis for building a services resource definition.
See also
ServicesResourceControllerAbstract::resourceInfo()
1 call to ServicesResourceControllerAbstract::getInfoElement()
- ServicesResourceControllerAbstract::resourceInfo in plugins/
services_entity_abstract.inc - Implemented to define basic CRUD/I operations.
File
- plugins/
services_entity_abstract.inc, line 51 - Services Entity module integration for entities.
Class
- ServicesResourceControllerAbstract
- An abstract controller providing basic CRUD resource info for entities.
Code
protected function getInfoElement($entity_type, $controller_method, $access_op = NULL, $id_arg = FALSE, $values_arg = FALSE) {
$element = array(
'callback' => '_services_entity_resource_callback',
'file' => array(
'type' => 'inc',
'module' => 'services_entity',
'name' => 'services_entity.resources',
),
'help' => "Executes the {$controller_method} operation on entities of type {$entity_type}",
'args' => array(
// This pseudo-argument is how we will pass the specific method name to
// our generic callback.
array(
'name' => 'method',
'optional' => TRUE,
// Otherwise throws an error
'default value' => $controller_method,
'type' => 'string',
'description' => 'Internal use only: the method to invoke.',
),
// This pseudo-argument is how we will pass the specific entity type to
// our generic callback.
array(
'name' => 'entity_type',
'optional' => TRUE,
// Otherwise throws an error
'default value' => $entity_type,
'type' => 'string',
'description' => 'Internal use only: the type of entity.',
),
),
'access callback' => '_services_entity_access_callback',
// Specify what will be passed as the $op argument to the access method
// of the controller; this defaults to the method name.
'access arguments' => array(
$access_op ? $access_op : $controller_method,
),
'access arguments append' => TRUE,
);
// If specified, add an argument representing the entity_id.
// This will be taken from index 0 of the path.
if ($id_arg) {
$element['args'][] = array(
'name' => $entity_type . '_id',
'optional' => FALSE,
'source' => array(
'path' => 0,
),
'type' => 'int',
'description' => "The {$entity_type} id.",
);
}
// If specified, add an argument representing the entity data.
// This will be taken from the post data.
if ($values_arg) {
$element['args'][] = array(
'name' => 'values',
'optional' => FALSE,
'source' => 'data',
'description' => "A representation of the {$entity_type}",
'type' => 'struct',
);
}
return $element;
}