You are here

class Bootstrap4ModalRenderer in Bootstrap 4 Modal 8

Same name and namespace in other branches
  1. 2.x src/Render/MainContent/Bootstrap4ModalRenderer.php \Drupal\bootstrap4_modal\Render\MainContent\Bootstrap4ModalRenderer

Default main content renderer for modal dialog requests.

Hierarchy

Expanded class hierarchy of Bootstrap4ModalRenderer

1 string reference to 'Bootstrap4ModalRenderer'
bootstrap4_modal.services.yml in ./bootstrap4_modal.services.yml
bootstrap4_modal.services.yml
1 service uses Bootstrap4ModalRenderer
main_content_renderer.bs4_modal in ./bootstrap4_modal.services.yml
Drupal\bootstrap4_modal\Render\MainContent\Bootstrap4ModalRenderer

File

src/Render/MainContent/Bootstrap4ModalRenderer.php, line 14

Namespace

Drupal\bootstrap4_modal\Render\MainContent
View source
class Bootstrap4ModalRenderer extends DialogRenderer {

  /**
   * {@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 OpenModalDialogCommand and set
    // the attachments for this Ajax response.
    $main_content['#attached']['library'][] = 'bootstrap4_modal/bs4_modal.dialog';
    $main_content['#attached']['library'][] = 'bootstrap4_modal/bs4_modal.dialog.ajax';
    $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());
    if (is_array($title)) {
      $title = $this->renderer
        ->renderPlain($title);
    }

    // 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 OpenBootstrap4ModalDialogCommand($title, $content, $options));
    return $response;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Bootstrap4ModalRenderer::renderResponse public function Renders the main content render array into a response. Overrides DialogRenderer::renderResponse
DialogRenderer::$renderer protected property The renderer. 1
DialogRenderer::$titleResolver protected property The title resolver.
DialogRenderer::determineTargetSelector protected function Determine the target selector for the OpenDialogCommand.
DialogRenderer::__construct public function Constructs a new DialogRenderer. 2