diff --git a/restui.module b/restui.module index 1a79696..6cacaef 100644 --- a/restui.module +++ b/restui.module @@ -23,7 +23,7 @@ function restui_theme() { return array( // list resources. 'restui_resource_info' => array( - 'variables' => array('config' => array()), + 'variables' => array('resource' => array()), 'template' => 'restui-resource-info', ), ); @@ -37,12 +37,12 @@ function restui_theme() { function restui_preprocess_restui_resource_info(&$variables) { $formats = \Drupal::getContainer()->getParameter('serializer.formats'); $authentication_providers = array_keys(\Drupal::service('authentication_collector')->getSortedProviders()); - foreach ($variables['config'] as $method => $properties) { + foreach ($variables['resource'] as $method => $properties) { if (empty($properties['supported_formats'])) { - $variables['config'][$method]['supported_formats'] = $formats; + $variables['resource'][$method]['supported_formats'] = $formats; } if (empty($properties['supported_auth'])) { - $variables['config'][$method]['supported_auth'] = $authentication_providers; + $variables['resource'][$method]['supported_auth'] = $authentication_providers; } } } diff --git a/src/Controller/RestUIController.php b/src/Controller/RestUIController.php index ca8836f..0e6958b 100644 --- a/src/Controller/RestUIController.php +++ b/src/Controller/RestUIController.php @@ -2,9 +2,7 @@ namespace Drupal\restui\Controller; -use Drupal\Core\Config\Entity\ConfigEntityStorageInterface; use Drupal\Core\Entity\EntityStorageInterface; -use Drupal\rest\RestResourceConfigInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -94,9 +92,8 @@ class RestUIController implements ContainerInjectionInterface { $enabled_resources = array_combine(array_keys($config), array_keys($config)); $available_resources = array('enabled' => array(), 'disabled' => array()); $resources = $this->resourcePluginManager->getDefinitions(); - foreach ($resources as $id => $resource) { - $status = in_array( str_replace(':', '.', $id), $enabled_resources) ? 'enabled' : 'disabled'; + $status = in_array($this->getResourceKey($id), $enabled_resources) ? 'enabled' : 'disabled'; $available_resources[$status][$id] = $resource; } @@ -197,7 +194,7 @@ class RestUIController implements ContainerInjectionInterface { $list[$status]['table']['#rows'][$id]['data']['description']['data'] = array( '#theme' => 'restui_resource_info', - '#config' => $config[str_replace(':', '.', $id)]->get('configuration'), + '#resource' => $config[$this->getResourceKey($id)]->get('configuration'), ); } } @@ -222,11 +219,10 @@ class RestUIController implements ContainerInjectionInterface { * Access is denied, if the token is invalid or missing. */ public function disable($resource_id) { - $resources = $this->resourceConfigStorage->loadMultiple(); - if ($resources[str_replace(':', '.', $resource_id)]) { - $resources[str_replace(':', '.', $resource_id)]->delete(); + if ($resources[$this->getResourceKey($resource_id)]) { + $resources[$this->getResourceKey($resource_id)]->delete(); // Rebuild routing cache. $this->routeBuilder->rebuild(); drupal_set_message(t('The resource was disabled successfully.')); @@ -236,4 +232,17 @@ class RestUIController implements ContainerInjectionInterface { return new RedirectResponse($this->urlGenerator->generate('restui.list', array(), TRUE)); } + /** + * The key used in the form. + * + * @param string $resource_id + * The resource ID. + * + * @return string + * The resource key in the form. + */ + protected function getResourceKey($resource_id) { + return str_replace(':', '.', $resource_id); + } + } diff --git a/src/Form/RestUIForm.php b/src/Form/RestUIForm.php index 4d2f19a..6ecbf40 100644 --- a/src/Form/RestUIForm.php +++ b/src/Form/RestUIForm.php @@ -250,9 +250,7 @@ class RestUIForm extends ConfigFormBase { else { unset($configuration[$method]); } - } - $config->set('configuration', $configuration); $config->save(); diff --git a/templates/restui-resource-info.html.twig b/templates/restui-resource-info.html.twig index 58f415c..e0a8b20 100644 --- a/templates/restui-resource-info.html.twig +++ b/templates/restui-resource-info.html.twig @@ -4,12 +4,12 @@ * Default theme implementation for basic administrative info about a REST resource. * * Available variables: - * - config: array REST resource config. + * - resource: array REST resource config. * * @ingroup themeable */ #} -{% for method, properties in config %} +{% for method, properties in resource %}

{{ method }}
authentication: {{ properties.supported_auth|join(', ') }}
formats: {{ properties.supported_formats|join(', ') }}