core/modules/book/book.module | 7 +++---- core/modules/book/book.services.yml | 2 +- core/modules/book/src/BookExport.php | 6 +++--- core/modules/book/src/Controller/BookController.php | 18 +++++++++++++++--- core/modules/system/src/Tests/Common/UrlTest.php | 2 ++ 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/core/modules/book/book.module b/core/modules/book/book.module index f7ee374..e80b5e3 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -71,7 +71,7 @@ function book_theme() { 'render element' => 'book_menus', ), 'book_node_export_html' => array( - 'variables' => array('node' => NULL, 'children' => NULL), + 'variables' => array('node' => NULL, 'content' => NULL, 'children' => NULL), ), ); } @@ -234,9 +234,9 @@ function book_node_view(array &$build, EntityInterface $node, EntityViewDisplayI if (!$book_node->access()) { return; } - $book_navigation = array( '#theme' => 'book_navigation', '#book_link' => $node->book); $build['book_navigation'] = array( - '#markup' => drupal_render($book_navigation), + '#theme' => 'book_navigation', + '#book_link' => $node->book, '#weight' => 100, // The book navigation is a listing of Node entities, so associate its // list cache tag for correct invalidation. @@ -491,7 +491,6 @@ function template_preprocess_book_export_html(&$variables) { function template_preprocess_book_node_export_html(&$variables) { $variables['depth'] = $variables['node']->book['depth']; $variables['title'] = SafeMarkup::checkPlain($variables['node']->label()); - $variables['content'] = $variables['node']->rendered; } /** diff --git a/core/modules/book/book.services.yml b/core/modules/book/book.services.yml index 3b45dae..0a022a7 100644 --- a/core/modules/book/book.services.yml +++ b/core/modules/book/book.services.yml @@ -12,7 +12,7 @@ services: arguments: ['@book.manager'] book.export: class: Drupal\book\BookExport - arguments: ['@entity.manager', '@book.manager'] + arguments: ['@entity.manager', '@book.manager', '@renderer'] book.outline_storage: class: Drupal\book\BookOutlineStorage arguments: ['@database'] diff --git a/core/modules/book/src/BookExport.php b/core/modules/book/src/BookExport.php index b71c7a0..dbb62e9 100644 --- a/core/modules/book/src/BookExport.php +++ b/core/modules/book/src/BookExport.php @@ -8,6 +8,7 @@ namespace Drupal\book; use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Render\RendererInterface; use Drupal\node\Entity\Node; use Drupal\node\NodeInterface; @@ -118,7 +119,7 @@ protected function exportTraverse(array $tree, $callable) { } } - return drupal_render($build); + return $build; } /** @@ -139,10 +140,9 @@ protected function bookNodeExport(NodeInterface $node, $children = '') { $build = $this->viewBuilder->view($node, 'print', NULL); unset($build['#theme']); - // @todo Rendering should happen in the template using render(). - $node->rendered = drupal_render($build); return array( '#theme' => 'book_node_export_html', + '#content' => $build, '#node' => $node, '#children' => $children, ); diff --git a/core/modules/book/src/Controller/BookController.php b/core/modules/book/src/Controller/BookController.php index 2f89937..53c64ad 100644 --- a/core/modules/book/src/Controller/BookController.php +++ b/core/modules/book/src/Controller/BookController.php @@ -10,6 +10,7 @@ use Drupal\book\BookExport; use Drupal\book\BookManagerInterface; use Drupal\Core\Controller\ControllerBase; +use Drupal\Core\Render\RendererInterface; use Drupal\Core\Url; use Drupal\node\Entity\Node; use Drupal\node\NodeInterface; @@ -38,16 +39,26 @@ class BookController extends ControllerBase { protected $bookExport; /** + * The renderer. + * + * @var \Drupal\Core\Render\RendererInterface + */ + protected $renderer; + + /** * Constructs a BookController object. * * @param \Drupal\book\BookManagerInterface $bookManager * The book manager. * @param \Drupal\book\BookExport $bookExport * The book export service. + * @param \Drupal\Core\Render\RendererInterface $renderer + * The renderer. */ - public function __construct(BookManagerInterface $bookManager, BookExport $bookExport) { + public function __construct(BookManagerInterface $bookManager, BookExport $bookExport, RendererInterface $renderer) { $this->bookManager = $bookManager; $this->bookExport = $bookExport; + $this->renderer = $renderer; } /** @@ -56,7 +67,8 @@ public function __construct(BookManagerInterface $bookManager, BookExport $bookE public static function create(ContainerInterface $container) { return new static( $container->get('book.manager'), - $container->get('book.export') + $container->get('book.export'), + $container->get('renderer') ); } @@ -154,7 +166,7 @@ public function bookExport($type, NodeInterface $node) { } $exported_book = $this->bookExport->{$method}($node); - return new Response(drupal_render($exported_book)); + return new Response($this->renderer->renderRoot($exported_book)); } } diff --git a/core/modules/system/src/Tests/Common/UrlTest.php b/core/modules/system/src/Tests/Common/UrlTest.php index 93f0503..c8e553b 100644 --- a/core/modules/system/src/Tests/Common/UrlTest.php +++ b/core/modules/system/src/Tests/Common/UrlTest.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Cache\Cache; +use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Language\Language; use Drupal\Core\Url; use Drupal\simpletest\WebTestBase; @@ -57,6 +58,7 @@ function testLinkCacheability() { foreach ($cases as $case) { list($title, $uri, $options, $expected_cacheability) = $case; + $expected_cacheability['contexts'] = Cache::mergeContexts($expected_cacheability['contexts'], ['languages:language_interface', 'theme']); $link = [ '#type' => 'link', '#title' => $title,