Loading README.md +17 −13 Original line number Diff line number Diff line # Lupus Custom Elements Renderer This module turns Drupal into an API backend that provides the main content and page metadata only. This module turns Drupal into an API backend that provides the main content and page metadata only. The module renders pages into a tree of custom elements and provides JSON responses containing the page medadata and content. While the responses are always served in JSON, the page content may be delivered using custom elements The module renders pages into a tree of custom elements and provides JSON responses containing the page metadata and content. While the responses are always served in JSON, the page content may be delivered using custom elements serialized as markup or as JSON data structure. ## What's supported Loading @@ -15,18 +17,18 @@ Custom routes can be added, please refer to `Development`. ## Usage Custom elements rendering can be requested by appending `_format=custom_elements` to any Drupal URL, e.g. Custom elements rendering can be requested by appending `_format=custom_elements` to any Drupal URL, e.g. GET /node/1?_format=custom_elements Optionally, the renderer can be enabled by default for certain Drupal site-directories (e.g.api.yoursite.com) via settings.php: Optionally, the renderer can be enabled by default for certain Drupal site-directories (e.g.api.yoursite.com) via settings.php: $settings['lupus_ce_renderer_enable'] = TRUE; If done so, it's suggested to create a settings.php file for the admin backend, which has it disabled. If done so, it's suggested to create a settings.php file for the admin backend, which has it disabled. The supported render formats are `markup` and `json`. The default render format is `markup` and can be globally set via: Loading @@ -37,8 +39,10 @@ or overridden in the url: GET /node/1?_content_format=markup Finally, the optional _select parameter allows limiting the output to only the content, i.e. without the wrapping json object. This is in particular helpful for visually inspecting the content markup. The only supported value is 'content'. Finally, the optional _select parameter allows limiting the output to only the content, i.e. without the wrapping json object. This is in particular helpful for visually inspecting the content markup. The only supported value is 'content'. GET /node/1?_select=content Loading @@ -60,8 +64,8 @@ Lupus Custom Elements Renderer provides two ways for altering reponse data (title, messages, breadcrumbs, metatags, content format, local tasks, page layout). First the overrides from request attributes (key `lupus_ce_renderer_response_data`) are applied to response data. First the overrides from request attributes (key `lupus_ce_renderer_response_data`) are applied to response data. Secondly, `hook_lupus_ce_renderer_response_alter` hook is fired. Loading src/Controller/CustomElementsController.php +3 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ class CustomElementsController { * (optional) The view mode to use. Defaults to 'full'. * * @return \Drupal\custom_elements\CustomElement * Returns CustomElement object. * * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException */ Loading Loading @@ -60,6 +61,7 @@ class CustomElementsController { * The view mode to use. * * @return \Drupal\custom_elements\CustomElement * Returns CustomElement object. */ public function entityPreview(EntityInterface $node_preview, $view_mode = 'full') { $custom_element = $this->getCustomElementGenerator()->generate($node_preview, $view_mode); Loading src/CustomElementsRenderer.php +1 −1 Original line number Diff line number Diff line Loading @@ -334,7 +334,7 @@ class CustomElementsRenderer { $local_tasks = []; if (!empty($render_links)) { foreach ($render_links as $render_link) { /** @var $access \Drupal\Core\Access\AccessResult */ /** @var \Drupal\Core\Access\AccessResult $access */ $access = $render_link['#access'] ?? FALSE; // Check access to links. if ($access instanceof AccessResult && $access->isAllowed() || $access === TRUE) { Loading src/EventSubscriber/CustomElementsDynamicResponseSubscriber.php +2 −2 Original line number Diff line number Diff line Loading @@ -55,10 +55,10 @@ class CustomElementsDynamicResponseSubscriber implements EventSubscriberInterfac */ public static function getSubscribedEvents() { $events = []; // Run after DynamicPageCacheSubscriber::onRespond(), which has priority 100. // Run after DynamicPageCacheSubscriber::onRespond(), // which has priority 100. $events[KernelEvents::RESPONSE][] = ['onResponse', 10]; return $events; } } src/EventSubscriber/CustomElementsFormatSubscriber.php +6 −4 Original line number Diff line number Diff line Loading @@ -14,8 +14,10 @@ use Symfony\Component\HttpKernel\KernelEvents; /** * Post-processes responses if the custom elements format is enabled. * * Note that \Drupal\lupus_ce_renderer\Routing\CustomElementsRequestFormatRouteFilter is making the default format * 'custom_elements' when our renderer is enabled already. * Note that * \Drupal\lupus_ce_renderer\Routing\CustomElementsRequestFormatRouteFilter * is making the default format 'custom_elements' when our renderer is enabled * already. */ class CustomElementsFormatSubscriber implements EventSubscriberInterface { Loading @@ -31,8 +33,8 @@ class CustomElementsFormatSubscriber implements EventSubscriberInterface { // Dis-allow html format when custom elements rendering is enabled. Other // formats like 'json' should be allowed, so custom APIs can be added. // We do this // \Drupal\lupus_ce_renderer\EventSubscriber\CustomElementsViewSubscriber::handleClientErrorResponses // @todo: Make this alterable somehow. // \Drupal\lupus_ce_renderer\EventSubscriber\CustomElementsViewSubscriber::handleClientErrorResponses. // @todo Make this alterable somehow. if (Settings::get('lupus_ce_renderer_enable', FALSE) && $event->getRequest()->getRequestFormat('custom_elements') == 'html') { if (!$event->getRequest()->attributes->get('exception')) { throw new NotAcceptableHttpException('Not accepted format.'); Loading Loading
README.md +17 −13 Original line number Diff line number Diff line # Lupus Custom Elements Renderer This module turns Drupal into an API backend that provides the main content and page metadata only. This module turns Drupal into an API backend that provides the main content and page metadata only. The module renders pages into a tree of custom elements and provides JSON responses containing the page medadata and content. While the responses are always served in JSON, the page content may be delivered using custom elements The module renders pages into a tree of custom elements and provides JSON responses containing the page metadata and content. While the responses are always served in JSON, the page content may be delivered using custom elements serialized as markup or as JSON data structure. ## What's supported Loading @@ -15,18 +17,18 @@ Custom routes can be added, please refer to `Development`. ## Usage Custom elements rendering can be requested by appending `_format=custom_elements` to any Drupal URL, e.g. Custom elements rendering can be requested by appending `_format=custom_elements` to any Drupal URL, e.g. GET /node/1?_format=custom_elements Optionally, the renderer can be enabled by default for certain Drupal site-directories (e.g.api.yoursite.com) via settings.php: Optionally, the renderer can be enabled by default for certain Drupal site-directories (e.g.api.yoursite.com) via settings.php: $settings['lupus_ce_renderer_enable'] = TRUE; If done so, it's suggested to create a settings.php file for the admin backend, which has it disabled. If done so, it's suggested to create a settings.php file for the admin backend, which has it disabled. The supported render formats are `markup` and `json`. The default render format is `markup` and can be globally set via: Loading @@ -37,8 +39,10 @@ or overridden in the url: GET /node/1?_content_format=markup Finally, the optional _select parameter allows limiting the output to only the content, i.e. without the wrapping json object. This is in particular helpful for visually inspecting the content markup. The only supported value is 'content'. Finally, the optional _select parameter allows limiting the output to only the content, i.e. without the wrapping json object. This is in particular helpful for visually inspecting the content markup. The only supported value is 'content'. GET /node/1?_select=content Loading @@ -60,8 +64,8 @@ Lupus Custom Elements Renderer provides two ways for altering reponse data (title, messages, breadcrumbs, metatags, content format, local tasks, page layout). First the overrides from request attributes (key `lupus_ce_renderer_response_data`) are applied to response data. First the overrides from request attributes (key `lupus_ce_renderer_response_data`) are applied to response data. Secondly, `hook_lupus_ce_renderer_response_alter` hook is fired. Loading
src/Controller/CustomElementsController.php +3 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ class CustomElementsController { * (optional) The view mode to use. Defaults to 'full'. * * @return \Drupal\custom_elements\CustomElement * Returns CustomElement object. * * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException */ Loading Loading @@ -60,6 +61,7 @@ class CustomElementsController { * The view mode to use. * * @return \Drupal\custom_elements\CustomElement * Returns CustomElement object. */ public function entityPreview(EntityInterface $node_preview, $view_mode = 'full') { $custom_element = $this->getCustomElementGenerator()->generate($node_preview, $view_mode); Loading
src/CustomElementsRenderer.php +1 −1 Original line number Diff line number Diff line Loading @@ -334,7 +334,7 @@ class CustomElementsRenderer { $local_tasks = []; if (!empty($render_links)) { foreach ($render_links as $render_link) { /** @var $access \Drupal\Core\Access\AccessResult */ /** @var \Drupal\Core\Access\AccessResult $access */ $access = $render_link['#access'] ?? FALSE; // Check access to links. if ($access instanceof AccessResult && $access->isAllowed() || $access === TRUE) { Loading
src/EventSubscriber/CustomElementsDynamicResponseSubscriber.php +2 −2 Original line number Diff line number Diff line Loading @@ -55,10 +55,10 @@ class CustomElementsDynamicResponseSubscriber implements EventSubscriberInterfac */ public static function getSubscribedEvents() { $events = []; // Run after DynamicPageCacheSubscriber::onRespond(), which has priority 100. // Run after DynamicPageCacheSubscriber::onRespond(), // which has priority 100. $events[KernelEvents::RESPONSE][] = ['onResponse', 10]; return $events; } }
src/EventSubscriber/CustomElementsFormatSubscriber.php +6 −4 Original line number Diff line number Diff line Loading @@ -14,8 +14,10 @@ use Symfony\Component\HttpKernel\KernelEvents; /** * Post-processes responses if the custom elements format is enabled. * * Note that \Drupal\lupus_ce_renderer\Routing\CustomElementsRequestFormatRouteFilter is making the default format * 'custom_elements' when our renderer is enabled already. * Note that * \Drupal\lupus_ce_renderer\Routing\CustomElementsRequestFormatRouteFilter * is making the default format 'custom_elements' when our renderer is enabled * already. */ class CustomElementsFormatSubscriber implements EventSubscriberInterface { Loading @@ -31,8 +33,8 @@ class CustomElementsFormatSubscriber implements EventSubscriberInterface { // Dis-allow html format when custom elements rendering is enabled. Other // formats like 'json' should be allowed, so custom APIs can be added. // We do this // \Drupal\lupus_ce_renderer\EventSubscriber\CustomElementsViewSubscriber::handleClientErrorResponses // @todo: Make this alterable somehow. // \Drupal\lupus_ce_renderer\EventSubscriber\CustomElementsViewSubscriber::handleClientErrorResponses. // @todo Make this alterable somehow. if (Settings::get('lupus_ce_renderer_enable', FALSE) && $event->getRequest()->getRequestFormat('custom_elements') == 'html') { if (!$event->getRequest()->attributes->get('exception')) { throw new NotAcceptableHttpException('Not accepted format.'); Loading