summaryrefslogtreecommitdiffstats
path: root/core/lib/Drupal/Core/Render
diff options
context:
space:
mode:
authorLee Rowlands2017-10-24 22:46:32 (GMT)
committerLee Rowlands2017-10-24 22:46:32 (GMT)
commitc586b21786dfcd3823a6611fe8398a75dc5a9476 (patch)
tree8f7ada18fd3afdcd2adebb6861659e44bbaad7ae /core/lib/Drupal/Core/Render
parent850f03b9be840cdd3bb00d6868f1232689d2c4ff (diff)
Issue #2784443 by tedbow, Wim Leers, Cottser, tim.plunkett, droplet, drpal, nod_, lauriii: Move off-canvas functionality from Settings tray module into drupal.dialog.ajax library so that other modules can use it
Diffstat (limited to 'core/lib/Drupal/Core/Render')
-rw-r--r--core/lib/Drupal/Core/Render/MainContent/OffCanvasRenderer.php62
1 files changed, 62 insertions, 0 deletions
diff --git a/core/lib/Drupal/Core/Render/MainContent/OffCanvasRenderer.php b/core/lib/Drupal/Core/Render/MainContent/OffCanvasRenderer.php
new file mode 100644
index 0000000..55bf8eb
--- /dev/null
+++ b/core/lib/Drupal/Core/Render/MainContent/OffCanvasRenderer.php
@@ -0,0 +1,62 @@
+<?php
+
+namespace Drupal\Core\Render\MainContent;
+
+use Drupal\Core\Ajax\AjaxResponse;
+use Drupal\Core\Controller\TitleResolverInterface;
+use Drupal\Core\Render\RendererInterface;
+use Drupal\Core\Routing\RouteMatchInterface;
+use Drupal\Core\Ajax\OpenOffCanvasDialogCommand;
+use Symfony\Component\HttpFoundation\Request;
+
+/**
+ * Default main content renderer for off-canvas dialog requests.
+ *
+ * @internal
+ */
+class OffCanvasRenderer extends DialogRenderer {
+
+ /**
+ * The renderer.
+ *
+ * @var \Drupal\Core\Render\RendererInterface
+ */
+ protected $renderer;
+
+ /**
+ * Constructs a new OffCanvasRenderer.
+ *
+ * @param \Drupal\Core\Controller\TitleResolverInterface $title_resolver
+ * The title resolver.
+ * @param \Drupal\Core\Render\RendererInterface $renderer
+ * The renderer.
+ */
+ public function __construct(TitleResolverInterface $title_resolver, RendererInterface $renderer) {
+ parent::__construct($title_resolver);
+ $this->renderer = $renderer;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function renderResponse(array $main_content, Request $request, RouteMatchInterface $route_match) {
+ $response = new AjaxResponse();
+
+ // First render the main content, because it might provide a title.
+ $content = $this->renderer->renderRoot($main_content);
+ // Attach the library necessary for using the OpenOffCanvasDialogCommand and
+ // set the attachments for this Ajax response.
+ $main_content['#attached']['library'][] = 'core/drupal.dialog.off_canvas';
+ $response->setAttachments($main_content['#attached']);
+
+ // If the main content doesn't provide a title, use the title resolver.
+ $title = isset($main_content['#title']) ? $main_content['#title'] : $this->titleResolver->getTitle($request, $route_match->getRouteObject());
+
+ // Determine the title: use the title provided by the main content if any,
+ // otherwise get it from the routing information.
+ $options = $request->request->get('dialogOptions', []);
+ $response->addCommand(new OpenOffCanvasDialogCommand($title, $content, $options));
+ return $response;
+ }
+
+}