View source
<?php
namespace Drupal\restful\Plugin\resource;
use Drupal\restful\Http\RequestInterface;
use Drupal\restful\Plugin\resource\DataInterpreter\DataInterpreterInterface;
class Discovery extends Resource {
protected function publicFields() {
return array(
'label' => array(
'property' => 'label',
),
'description' => array(
'property' => 'description',
),
'name' => array(
'property' => 'name',
),
'resource' => array(
'property' => 'resource',
),
'majorVersion' => array(
'property' => 'majorVersion',
),
'minorVersion' => array(
'property' => 'minorVersion',
),
'self' => array(
'callback' => array(
$this,
'getSelf',
),
),
);
}
protected function dataProviderClassName() {
return '\\Drupal\\restful\\Plugin\\resource\\DataProvider\\DataProviderPlug';
}
public function getSelf(DataInterpreterInterface $interpreter) {
if ($menu_item = $interpreter
->getWrapper()
->get('menuItem')) {
$url = variable_get('restful_hook_menu_base_path', 'api') . '/' . $menu_item;
return url($url, array(
'absolute' => TRUE,
));
}
$base_path = variable_get('restful_hook_menu_base_path', 'api');
return url($base_path . '/v' . $interpreter
->getWrapper()
->get('majorVersion') . '.' . $interpreter
->getWrapper()
->get('minorVersion') . '/' . $interpreter
->getWrapper()
->get('resource'), array(
'absolute' => TRUE,
));
}
public function controllersInfo() {
return array(
'' => array(
RequestInterface::METHOD_GET => 'index',
RequestInterface::METHOD_HEAD => 'index',
),
'^.*$' => array(
RequestInterface::METHOD_GET => 'view',
RequestInterface::METHOD_HEAD => 'view',
RequestInterface::METHOD_PUT => array(
'callback' => 'replace',
'access callback' => 'resourceManipulationAccess',
),
RequestInterface::METHOD_DELETE => array(
'callback' => 'remove',
'access callback' => 'resourceManipulationAccess',
),
),
);
}
public function resourceManipulationAccess($path) {
return user_access('administer restful resources', $this
->getAccount());
}
}