Change record status: 
Project: 
Introduced in branch: 
10.3.x
Introduced in version: 
10.3.0
Description: 

\Drupal\Core\Render\MainContent\DialogRenderer::getTitleAsStringable() has been added to make it simple for classes that extend \Drupal\Core\Render\MainContent\DialogRenderer to render the title from the main content array or the current route match simpler.

Also if an array is passed to \Drupal\Core\Ajax\OpenDialogCommand::__construct() or \Drupal\Core\Ajax\OpenOffCanvasDialogCommand::__construct() an exception will be triggered. Prior to 10.3.x this would produce a PHP warning and the title would be set to Array

Impacts: 
Module developers

Comments

cosmicdreams’s picture

Previously I was overriding the title with of an off-canvas dialog like this:

/**
   * Overrides \Drupal\Core\Entity\Controller\EntityViewController::title().
   *
   * Set preview pane title to "Preview" always.
   *
   * @param \Drupal\Core\Entity\EntityInterface|NULL $node_preview
   *   The node preview entity.
   *
   * @return \Drupal\Core\StringTranslation\TranslatableMarkup
   *   Title of the preview pane.
   */
  public function title(EntityInterface $node_preview = NULL): TranslatableMarkup {
    return t('Preview');
  }

This approach is broken after this change, because by the time $this->titleResolver->getTitle($request, $route_match->getRouteObject()) returns a result it already is a string. And the string primitive does not have a render() method.

What is the new way of overriding the title of an off-canvas dialog?