class OffCanvasRenderer

Same name in other branches
  1. 9 core/lib/Drupal/Core/Render/MainContent/OffCanvasRenderer.php \Drupal\Core\Render\MainContent\OffCanvasRenderer
  2. 8.9.x core/lib/Drupal/Core/Render/MainContent/OffCanvasRenderer.php \Drupal\Core\Render\MainContent\OffCanvasRenderer
  3. 11.x core/lib/Drupal/Core/Render/MainContent/OffCanvasRenderer.php \Drupal\Core\Render\MainContent\OffCanvasRenderer

Default main content renderer for off-canvas dialog requests.

@internal

Hierarchy

Expanded class hierarchy of OffCanvasRenderer

1 string reference to 'OffCanvasRenderer'
core.services.yml in core/core.services.yml
core/core.services.yml
2 services use OffCanvasRenderer
main_content_renderer.off_canvas in core/core.services.yml
Drupal\Core\Render\MainContent\OffCanvasRenderer
main_content_renderer.off_canvas_top in core/core.services.yml
Drupal\Core\Render\MainContent\OffCanvasRenderer

File

core/lib/Drupal/Core/Render/MainContent/OffCanvasRenderer.php, line 17

Namespace

Drupal\Core\Render\MainContent
View source
class OffCanvasRenderer extends DialogRenderer {
    
    /**
     * The renderer.
     *
     * @var \Drupal\Core\Render\RendererInterface
     */
    protected $renderer;
    
    /**
     * The position to render the off-canvas dialog.
     *
     * @var string
     */
    protected $position;
    
    /**
     * Constructs a new OffCanvasRenderer.
     *
     * @param \Drupal\Core\Controller\TitleResolverInterface $title_resolver
     *   The title resolver.
     * @param \Drupal\Core\Render\RendererInterface $renderer
     *   The renderer.
     * @param string $position
     *   (optional) The position to render the off-canvas dialog.
     */
    public function __construct(TitleResolverInterface $title_resolver, RendererInterface $renderer, $position = 'side') {
        parent::__construct($title_resolver, $renderer);
        $this->renderer = $renderer;
        $this->position = $position;
    }
    
    /**
     * {@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']);
        // Determine the title.
        $title = $this->getTitleAsStringable($main_content, $request, $route_match);
        // Determine the title: use the title provided by the main content if any,
        // otherwise get it from the routing information.
        $options = $request->request
            ->all('dialogOptions');
        $response->addCommand(new OpenOffCanvasDialogCommand($title, $content, $options, NULL, $this->position));
        return $response;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
DialogRenderer::$titleResolver protected property The title resolver.
DialogRenderer::determineTargetSelector protected function Determine the target selector for the OpenDialogCommand.
DialogRenderer::getDialogOptions protected function Returns the dialog options from request.
DialogRenderer::getTitleAsStringable protected function Gets the title as a string or stringable object.
OffCanvasRenderer::$position protected property The position to render the off-canvas dialog.
OffCanvasRenderer::$renderer protected property The renderer. Overrides DialogRenderer::$renderer
OffCanvasRenderer::renderResponse public function Renders the main content render array into a response. Overrides DialogRenderer::renderResponse
OffCanvasRenderer::__construct public function Constructs a new OffCanvasRenderer. Overrides DialogRenderer::__construct

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.