summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2014-11-19 09:41:38 (GMT)
committerAlex Pott2014-11-19 09:41:38 (GMT)
commitb0f2463942e195f9e31511910c30d05c0b831a49 (patch)
tree082a4c5b2c806d5b756983da3298ed16c84db8f9
parent5ddf7c26a02fa05029bfcc28376e882878585ad7 (diff)
Issue #2362987 by Wim Leers, Codenator, Pinolo: Remove hook_page_build() and hook_page_alter()
-rw-r--r--core/modules/system/src/Tests/Common/PageRenderTest.php18
-rw-r--r--core/modules/system/system.module22
-rw-r--r--core/modules/system/tests/modules/bc_test/bc_test.info.yml6
-rw-r--r--core/modules/system/tests/modules/bc_test/bc_test.module44
-rw-r--r--core/modules/system/tests/modules/common_test/common_test.module10
-rw-r--r--core/modules/system/theme.api.php54
-rw-r--r--core/modules/views/views.module2
7 files changed, 9 insertions, 147 deletions
diff --git a/core/modules/system/src/Tests/Common/PageRenderTest.php b/core/modules/system/src/Tests/Common/PageRenderTest.php
index e660448..e9eb691 100644
--- a/core/modules/system/src/Tests/Common/PageRenderTest.php
+++ b/core/modules/system/src/Tests/Common/PageRenderTest.php
@@ -34,24 +34,6 @@ class PageRenderTest extends KernelTestBase {
}
/**
- * Tests hook_page_build() exceptions, a deprecated hook kept around for BC.
- */
- function testHookPageBuildExceptions() {
- // Also enable the system module, because that module invokes the BC hooks.
- $this->enableModules(['bc_test', 'system']);
- $this->assertPageRenderHookExceptions('bc_test', 'hook_page_build');
- }
-
- /**
- * Tests hook_page_alter(), a deprecated hook kept around for BC.
- */
- function testHookPageAttachmentsAlter() {
- // Also enable the system module, because that module invokes the BC hooks.
- $this->enableModules(['bc_test', 'system']);
- $this->assertPageRenderHookExceptions('bc_test', 'hook_page_alter');
- }
-
- /**
* Asserts whether expected exceptions are thrown for invalid hook implementations.
*
* @param string $module
diff --git a/core/modules/system/system.module b/core/modules/system/system.module
index ba26844..9334a88 100644
--- a/core/modules/system/system.module
+++ b/core/modules/system/system.module
@@ -632,28 +632,6 @@ function system_page_attachments(array &$page) {
)
);
}
-
- // Invoke hook_page_build() for modules and hook_page_alter() for both modules
- // and themes, for backwards compatibility.
- $attachments = [];
- foreach (\Drupal::moduleHandler()->getImplementations('page_build') as $module) {
- $function = $module . '_page_build';
- $function($attachments);
- }
- if (array_diff(array_keys($attachments), ['#attached', '#post_render_cache']) !== []) {
- throw new \LogicException('Only #attached and #post_render_cache may be set in hook_page_build().');
- }
- \Drupal::moduleHandler()->alter('page', $attachments);
- \Drupal::theme()->alter('page', $attachments);
- if (array_diff(array_keys($attachments), ['#attached', '#post_render_cache']) !== []) {
- throw new \LogicException('Only #attached and #post_render_cache may be set in hook_page_alter().');
- }
- if (isset($attachments['#attached'])) {
- $page['#attached'] = $attachments['#attached'];
- }
- if (isset($attachments['#post_render_cache'])) {
- $page['#post_render_cache'] = $attachments['#post_render_cache'];
- }
}
/**
diff --git a/core/modules/system/tests/modules/bc_test/bc_test.info.yml b/core/modules/system/tests/modules/bc_test/bc_test.info.yml
deleted file mode 100644
index 20dbd82..0000000
--- a/core/modules/system/tests/modules/bc_test/bc_test.info.yml
+++ /dev/null
@@ -1,6 +0,0 @@
-name: 'Backwards Compatibility Test'
-type: module
-description: 'Support module for backwards compatibility tests.'
-package: Testing
-version: VERSION
-core: 8.x
diff --git a/core/modules/system/tests/modules/bc_test/bc_test.module b/core/modules/system/tests/modules/bc_test/bc_test.module
deleted file mode 100644
index 537acb8..0000000
--- a/core/modules/system/tests/modules/bc_test/bc_test.module
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php
-
-/**
- * @file
- * Helper module for backwards compatibility (BC) tests.
- */
-
-/**
- * Implements hook_page_build().
- *
- * @see \Drupal\system\Tests\Common\PageRenderTest::assertPageRenderHookExceptions()
- */
-function bc_test_page_build(&$page) {
- $page['#attached']['library'][] = 'core/jquery';
-
- if (\Drupal::state()->get('bc_test.hook_page_build.descendant_attached', FALSE)) {
- $page['content']['#attached']['library'][] = 'core/jquery';
- }
-
- if (\Drupal::state()->get('bc_test.hook_page_build.render_array', FALSE)) {
- $page['something'] = [
- '#markup' => 'test',
- ];
- }
-}
-
-/**
- * Implements hook_page_alter().
- *
- * @see \Drupal\system\Tests\Common\PageRenderTest::assertPageRenderHookExceptions()
- */
-function bc_test_page_alter(&$page) {
- $page['#attached']['library'][] = 'core/jquery';
-
- if (\Drupal::state()->get('bc_test.hook_page_alter.descendant_attached', FALSE)) {
- $page['content']['#attached']['library'][] = 'core/jquery';
- }
-
- if (\Drupal::state()->get('bc_test.hook_page_alter.render_array', FALSE)) {
- $page['something'] = [
- '#markup' => 'test',
- ];
- }
-}
diff --git a/core/modules/system/tests/modules/common_test/common_test.module b/core/modules/system/tests/modules/common_test/common_test.module
index 97ff0bf..a1100b4 100644
--- a/core/modules/system/tests/modules/common_test/common_test.module
+++ b/core/modules/system/tests/modules/common_test/common_test.module
@@ -260,7 +260,8 @@ function common_test_post_render_cache_placeholder(array $element, array $contex
* @see \Drupal\system\Tests\Common\PageRenderTest::assertPageRenderHookExceptions()
*/
function common_test_page_attachments(array &$page) {
- $page['#attached']['library'][] = 'core/jquery';
+ $page['#attached']['library'][] = 'core/foo';
+ $page['#attached']['library'][] = 'core/bar';
if (\Drupal::state()->get('common_test.hook_page_attachments.descendant_attached', FALSE)) {
$page['content']['#attached']['library'][] = 'core/jquery';
@@ -279,7 +280,12 @@ function common_test_page_attachments(array &$page) {
* @see \Drupal\system\Tests\Common\PageRenderTest::assertPageRenderHookExceptions()
*/
function common_test_page_attachments_alter(array &$page) {
- $page['#attached']['library'][] = 'core/jquery';
+ // Remove a library that was added in common_test_page_attachments(), to test
+ // that this hook can do what it claims to do.
+ if (isset($page['#attached']['library']) && ($index = array_search('core/bar', $page['#attached']['library'])) && $index !== FALSE) {
+ unset($page['#attached']['library'][$index]);
+ }
+ $page['#attached']['library'][] = 'core/baz';
if (\Drupal::state()->get('common_test.hook_page_attachments_alter.descendant_attached', FALSE)) {
$page['content']['#attached']['library'][] = 'core/jquery';
diff --git a/core/modules/system/theme.api.php b/core/modules/system/theme.api.php
index 1ba2efc..f13210d 100644
--- a/core/modules/system/theme.api.php
+++ b/core/modules/system/theme.api.php
@@ -813,60 +813,6 @@ function hook_css_alter(&$css) {
/**
* Add attachments (typically assets) to a page before it is rendered.
*
- * Kept around for backwards compatibility, but now allows only attachments to
- * be added, adding renderable arrays is no longer allowed.
- *
- * @deprecated in Drupal 8.x, will be removed before Drupal 9.0. Successor:
- * hook_page_attachments(). Is now effectively an alias of that hook.
- *
- * @param $page
- * The page to which to add attachments.
- *
- * @see hook_page_attachments()
- */
-function hook_page_build(&$page) {
- $path = drupal_get_path('module', 'foo');
- // Add JavaScript/CSS assets to all pages.
- // @see drupal_process_attached()
- $page['#attached']['js'][$path . '/foo.js'] = array('every_page' => TRUE);
- $page['#attached']['css'][$path . '/foo.base.css'] = array('every_page' => TRUE);
- $page['#attached']['css'][$path . '/foo.theme.css'] = array('every_page' => TRUE);
-
- // Add a special CSS file to a certain page only.
- if (drupal_is_front_page()) {
- $page['#attached']['css'][] = $path . '/foo.front.css';
- }
-}
-
-/**
- * Perform alterations before a page is rendered.
- *
- * Kept around for backwards compatibility, but now allows only attachments to
- * be added, altering the renderable array for the page is no longer allowed.
- *
- * @deprecated in Drupal 8.x, will be removed before Drupal 9.0. Successor:
- * hook_page_attachments_alter(). Is now effectively an alias of that hook.
- *
- * Use this hook when you want to remove or alter attachments at the page
- * level, or add attachments at the page level that depend on an other module's
- * attachments (this hook runs after hook_page_build().
- *
- * @param $page
- * An empty renderable array representing the page.
- *
- * @see hook_page_build()
- */
-function hook_page_alter(&$page) {
- // Conditionally remove an asset.
- if (in_array('core/jquery', $page['#attached']['library'])) {
- $index = array_search('core/jquery', $page['#attached']['library']);
- unset($page['#attached']['library'][$index]);
- }
-}
-
-/**
- * Add attachments (typically assets) to a page before it is rendered.
- *
* Use this hook when you want to conditionally add attachments to a page.
*
* If you want to alter the attachments added by other modules or if your module
diff --git a/core/modules/views/views.module b/core/modules/views/views.module
index f2a0b37..507758c 100644
--- a/core/modules/views/views.module
+++ b/core/modules/views/views.module
@@ -388,7 +388,7 @@ function views_preprocess_html(&$variables) {
* The ID of the display within $view whose contextual links will be added.
*
* @see \Drupal\views\Plugin\block\block\ViewsBlock::addContextualLinks()
- * @see views_page_alter()
+ * @see views_preprocess_page()
* @see template_preprocess_views_view()
*/
function views_add_contextual_links(&$render_element, $location, ViewExecutable $view, $display_id) {