Commit b48a1266 authored by webchick's avatar webchick

Issue #1909178 by wiifm: Fixed Cleanup the administration screen and add...

Issue #1909178 by wiifm: Fixed Cleanup the administration screen and add better help on admin/config/services/rest.
parent 29a70d15
......@@ -17,29 +17,58 @@ function rest_admin_form($form, &$form_state) {
$entity_resources = array();
$other_resources = array();
foreach ($resources as $plugin_name => $definition) {
// Non-entity resources.
if (strpos($plugin_name, 'entity:') === FALSE) {
$other_resources[$plugin_name] = $definition['label'];
$other_resources[$plugin_name] = array(
'name' => $definition['label'],
'path' => '<code>/' . $definition['id'] . '/{id}</code>',
);
}
// Entity resources.
else {
$entity_resources[$plugin_name] = $definition['label'];
$entity_resources[$plugin_name] = array(
'name' => $definition['label'],
'path' => '<code>/entity/' . $definition['entity_type'] . '/{id}</code>',
);
}
}
asort($entity_resources);
asort($other_resources);
$enabled_resources = config('rest.settings')->get('resources') ?: array();
// Render the output using table_select().
$header = array(
'name' => t('Name'),
'path' => t('Path'),
);
$form['entity_resources_title'] = array(
'#markup' => '<h3>' . t('Entity resource types that should be exposed as web services') . '</h3>',
);
$form['entity_resources'] = array(
'#type' => 'checkboxes',
'#type' => 'tableselect',
'#js_select' => TRUE,
'#multiple' => TRUE,
'#header' => $header,
'#options' => $entity_resources,
'#default_value' => $enabled_resources,
'#title' => t('Entity resource types that should be exposed as web services:'),
'#empty' => t('Nothing to show'),
);
if (!empty($other_resources)) {
$form['other_resources_title'] = array(
'#markup' => '<h3>' . t('Other available resource types that should be exposed as web services') . '</h3>',
);
$form['other_resources'] = array(
'#type' => 'checkboxes',
'#type' => 'tableselect',
'#js_select' => TRUE,
'#multiple' => TRUE,
'#header' => $header,
'#options' => $other_resources,
'#default_value' => $enabled_resources,
'#title' => t('Other available resource types that should be exposed as web services:'),
'#empty' => t('Nothing to show'),
);
}
......
......@@ -62,10 +62,18 @@ function rest_help($path, $arg) {
$output .= '</dl>';
return $output;
// Help for the configuration page.
case 'admin/config/services/rest':
return '<p>' . t('This page allows you to expose resources as RESTful web API. That enables external third parties 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>' .
'<p>' . t('Example: when enabled, the node resource is available at the path <code>/entity/node/{id}</code> and a HTTP DELETE request can be used to delete a node. Testing on the command line with cURL (deletes node 5, make sure to replace the node ID accordingly):') . '</p>' .
'<p><code>curl --include --request DELETE --cookie ' . session_name() . '=' . session_id() . ' ' . url('entity/node/5', array('absolute' => TRUE)) . '</code>' .
'<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 delete nodes.', array('@permissions' => url('admin/people/permissions', array('fragment' => 'module-rest')))) . '</p>';
$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/vnd.drupal.ld+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;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment