Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This project is not covered by Drupal’s security advisory policy.
Services OOP allows declarative definition of resource-based services through class declarations.
Example
This is a incomplete example of how a resource could be implemented.
/**
* Class that defines the event resource
*
* @Relationship(name='occasions', controller='retrieveOccasions')
*/
class EventResource {
/**
* Creates a event
*
* @param object $event ["data"]
* @return object
*
* @Access(callback='_event_resource_access', args={'create'}, appendArgs=true)
*/
public static function create($event) {
// Do your thing here
}
/**
* Retrieves a event
*
* @param int $nid ["path","0"]
* The nid of the event to get
* @return object
*
* @Access(callback='_event_resource_access', args={'view'}, appendArgs=true)
* @Model(class='ResourceFeedModel', implementation='EventResourceFeedModel')
*/
public static function retrieve($nid) {
// Do your thing here
}
/**
* Updates a event
*
* @param int $nid ["path","0"]
* The nid of the event to update
* @param object $event ["data"]
* The event object
* @return object
*
* @Access(callback='_event_resource_access', args={'update'}, appendArgs=true)
*/
public static function update($nid, $event) {
// Do your thing here
}
/**
* Deletes a event
*
* @param int $nid ["path","0"]
* The nid of the event to get
* @return bool
*
* @Access(callback='_event_resource_access', args={'delete'}, appendArgs=true)
*/
public static function delete($nid) {
// Do your thing here
}
/**
* Retrieves a listing of events
*
* @param int $page ["param","page"]
* @param string $fields ["param","fields"]
* @param array $params ["param"]
* @return array
*
* @Access(callback='user_access', args={'access content'}, appendArgs=false)
* @Model(class='ResourceFeedModel', implementation='EventResourceFeedModel')
* @Model(class='ResourceTimeFeedModel', implementation='EventResourceFeedModel')
*/
public static function index($page=0, $fields=array(), $params=array()) {
// Do your thing here
}
/**
* Controller method for getting occasions for a event
*
* @param int $nid ["path","0"]
* The nid of the event to get occasions for
* @param int $page ["param","page"]
* @return array
*
* @Model(class='ResourceFeedModel', implementation='EventOccasionsFeedModel')
* @Model(class='ResourceTimeFeedModel', implementation='EventOccasionsFeedModel')
*/
public static function retrieveOccasions($nid, $page=0) {
// Do your thing here
}
}
Project information
- Module categories: Developer Tools
- 1 site reports using this module
- By Hugo Wetterberg on , updated
- This project is not covered by the security advisory policy.
Use at your own risk! It may have publicly disclosed vulnerabilities.
Releases
7.x-1.0-rc1
released 13 March 2012
Works with Drupal: 7.x
✓ Recommended by the project’s maintainer.