80 lines
4.0 KiB
Plaintext
80 lines
4.0 KiB
Plaintext
<?php
|
|
|
|
/**
|
|
* @file
|
|
* RESTful web services module.
|
|
*/
|
|
|
|
/**
|
|
* Implements hook_menu().
|
|
*
|
|
* @todo for now we use this hook for our admin page until
|
|
* http://drupal.org/node/1801570 is sorted out.
|
|
*/
|
|
function rest_menu() {
|
|
$items['admin/config/services/rest'] = array(
|
|
'title' => 'RESTful web services',
|
|
'description' => 'Configure resources and entities that are exposed as web API.',
|
|
'page callback' => 'drupal_get_form',
|
|
'page arguments' => array('rest_admin_form'),
|
|
'access arguments' => array('administer site configuration'),
|
|
'file' => 'rest.admin.inc',
|
|
);
|
|
return $items;
|
|
}
|
|
|
|
/**
|
|
* Implements hook_permission().
|
|
*/
|
|
function rest_permission() {
|
|
$permissions = array();
|
|
if (drupal_container()->has('plugin.manager.rest')) {
|
|
$manager = drupal_container()->get('plugin.manager.rest');
|
|
$resources = config('rest.settings')->get('resources');
|
|
if ($resources && $enabled = array_intersect_key($manager->getDefinitions(), $resources)) {
|
|
foreach ($enabled as $key => $resource) {
|
|
$plugin = $manager->getInstance(array('id' => $key));
|
|
$permissions = array_merge($permissions, $plugin->permissions());
|
|
}
|
|
}
|
|
}
|
|
return $permissions;
|
|
}
|
|
|
|
/**
|
|
* Implements hook_help().
|
|
*/
|
|
function rest_help($path, $arg) {
|
|
switch ($path) {
|
|
// Main module help for the REST module
|
|
case 'admin/help#rest':
|
|
$output = '';
|
|
$output .= '<h3>' . t('About') . '</h3>';
|
|
$output .= '<p>' . t('The REST module provides a framework for exposing Drupal\'s data structures as RESTful web services. It can be used to read and write resources remotely, such as entity types like nodes or users. For more information, see the online handbook entry for the <a href="@rest">RESTful web services module</a>.', array('@rest' => 'http://drupal.org/documentation/modules/rest')) . '</p>';
|
|
$output .= '<h3>' . t('Uses') . '</h3>';
|
|
$output .= '<dl>';
|
|
$output .= '<dt>' . t('Exposing resources') . '</dt>';
|
|
$output .= '<dd>' . t('Visit the <a href="@admin-rest">configuration page</a> to display a list of available resources and to enable them individually.', array('@admin-rest' => url('admin/config/services/rest'))) . '</dd>';
|
|
$output .= '</dl>';
|
|
$output .= '<dl>';
|
|
$output .= '<dt>' . t('Granting permissions') . '</dt>';
|
|
$output .= '<dd>' . t('The <a href="@permission-rest">permissions page</a> allows you to determine what user roles may access a web service operation.', array('@permission-rest' => url('admin/people/permissions', array('fragment' => 'module-rest')))) . '</dd>';
|
|
$output .= '</dl>';
|
|
return $output;
|
|
|
|
// Help for the configuration page.
|
|
case 'admin/config/services/rest':
|
|
$output = '';
|
|
$output .= '<p>' . t('This page allows you to expose resources using Drupal\'s REST API. That enables external clients to interact with your Drupal installation via a machine readable interface. All entity types are available for such operations while contributed modules can provide more.') . '</p>';
|
|
$output .= '<h3>' . t('Example uses') . '</h3>';
|
|
$output .= '<dl>';
|
|
$output .= '<dt>' . t('An HTTP GET request can be used to get a node') . '</dt>';
|
|
$output .= '<dd><code>curl -H "Accept: application/hal+json" --include --request GET --cookie ' . session_name() . '=' . session_id() . ' ' . url('entity/node/5', array('absolute' => TRUE)) . '</code></dd>';
|
|
$output .= '<dt>' . t('An HTTP DELETE request can be used to delete a node') . '</dt>';
|
|
$output .= '<dd><code>curl --include --request DELETE --cookie ' . session_name() . '=' . session_id() . ' ' . url('entity/node/5', array('absolute' => TRUE)) . '</code></dd>';
|
|
$output .= '</dl>';
|
|
$output .= '<p>' . t('Note: Session information of the current user is shown here, make sure that you have the <a href="@permissions">permission to use the web API</a> to get and delete nodes.', array('@permissions' => url('admin/people/permissions', array('fragment' => 'module-rest')))) . '</p>';
|
|
return $output;
|
|
}
|
|
}
|