diff --git a/core/includes/common.inc b/core/includes/common.inc index 02ee536..d0a538e 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -3675,6 +3675,25 @@ function drupal_prepare_page($page) { } /** + * @needsdoc + */ +function drupal_build(&$elements) { + if (isset($elements['#build'])) { + foreach ($elements['#build'] as $callable) { + $elements = call_user_func($callable, $elements); + } + // Once the item is built, the callback is no longer needed. + unset($elements['#build']); + } + // Build the child elements as well. + if ($children = element_children($elements)) { + foreach ($children as $child) { + drupal_build($elements[$child]); + } + } +} + +/** * Renders the page, including all theming. * * @param string|array $page @@ -3859,6 +3878,12 @@ function drupal_render(&$elements, $is_recursive_call = FALSE) { } } + // If element building has been postponed with #build callbacks, invoke them + // now before rendering starts. + if (!$is_recursive_call) { + drupal_build($elements); + } + // If the default values for this element have not been loaded yet, populate // them. if (isset($elements['#type']) && empty($elements['#defaults_loaded'])) { @@ -3992,17 +4017,6 @@ function drupal_render(&$elements, $is_recursive_call = FALSE) { $suffix = isset($elements['#suffix']) ? $elements['#suffix'] : ''; $elements['#markup'] = $prefix . $elements['#children'] . $suffix; - // Collect all #post_render_cache callbacks associated with this element when: - // - it is the root element is a drupal_render() invocation; and - // - the first attempt to establish a post_render_cache turned up nothing - // because of pre-render functions in child elements that have not run yet. - if (!$is_recursive_call && empty($elements['#post_render_cache'])) { - $post_render_cache = drupal_render_collect_post_render_cache($elements); - if ($post_render_cache) { - $elements['#post_render_cache'] = $post_render_cache; - } - } - // Cache the processed element if #cache is set. if (isset($elements['#cache'])) { drupal_render_cache_set($elements['#markup'], $elements); diff --git a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php index ec6ad9b..5831d57 100644 --- a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php @@ -154,7 +154,7 @@ protected function getBuildDefaults(EntityInterface $entity, $view_mode = 'full' "#{$this->entityTypeId}" => $entity, '#view_mode' => $view_mode, '#langcode' => $langcode, - '#pre_render' => array(array($this, 'entityViewBuilderPreRender')), + '#build' => array(array($this, 'entityViewBuilderBuildView')), ); // Cache the rendered output if permitted by the view mode and global entity @@ -188,9 +188,9 @@ protected function getBuildDefaults(EntityInterface $entity, $view_mode = 'full' } /** - * Performs pre-render tasks on an entity view. + * Builds an entity's view on an entity view; augments entity defaults. * - * This function is assigned as a #pre_render callback in + * This function is assigned as a #build callback in * \Drupal\Core\Entity\EntityViewBuilder::getBuildDefaults(). * * @param array $elements @@ -199,7 +199,7 @@ protected function getBuildDefaults(EntityInterface $entity, $view_mode = 'full' * * @see drupal_render() */ - public function entityViewBuilderPreRender(array $elements) { + public function entityViewBuilderBuildView(array $elements) { $entity = $elements['#entity']; $bundle = $entity->bundle(); $view_hook = "{$this->entityTypeId}_view"; diff --git a/core/lib/Drupal/Core/Field/FormatterBase.php b/core/lib/Drupal/Core/Field/FormatterBase.php index abbc055..1df3122 100644 --- a/core/lib/Drupal/Core/Field/FormatterBase.php +++ b/core/lib/Drupal/Core/Field/FormatterBase.php @@ -65,24 +65,22 @@ public function __construct($plugin_id, array $plugin_definition, FieldDefinitio $this->viewMode = $view_mode; } - + /** + * @needsdoc + */ public function getDefaults(FieldItemListInterface $items) { - $info = array(); - $elements = $this->viewElements($items); - if ($elements) { - $info = array( - '#cache' => array('tags' => array()), - ); - // Gather cache tags from reference fields. - foreach ($items as $item) { - if (isset($item->format)) { - $info['#cache']['tags']['filter_format'] = $item->format; - } - - if (isset($item->entity)) { - $info['#cache']['tags'][$item->entity->getEntityTypeId()][] = $item->entity->id(); - $info['#cache']['tags'][$item->entity->getEntityTypeId() . '_view'] = TRUE; - } + $info = array( + '#cache' => array('tags' => array()), + ); + // Gather cache tags from reference fields. + foreach ($items as $item) { + if (isset($item->format)) { + $info['#cache']['tags']['filter_format'] = $item->format; + } + + if (isset($item->entity)) { + $info['#cache']['tags'][$item->entity->getEntityTypeId()][] = $item->entity->id(); + $info['#cache']['tags'][$item->entity->getEntityTypeId() . '_view'] = TRUE; } } return $info; diff --git a/core/lib/Drupal/Core/Field/FormatterInterface.php b/core/lib/Drupal/Core/Field/FormatterInterface.php index 1409555..a6f015f 100644 --- a/core/lib/Drupal/Core/Field/FormatterInterface.php +++ b/core/lib/Drupal/Core/Field/FormatterInterface.php @@ -40,6 +40,9 @@ public function settingsForm(array $form, array &$form_state); */ public function settingsSummary(); + /** + * @needsdoc + */ public function getDefaults(FieldItemListInterface $items); /** diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index e5a74d6..bc84515 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -14,6 +14,7 @@ use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\Core\Entity\EntityChangedInterface; use Drupal\Core\Entity\EntityInterface; +use Drupal\entity\Entity\EntityViewDisplay; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\field\FieldInstanceConfigInterface; use Drupal\field\FieldConfigInterface; diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 2dd7bcc..91ff060 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -335,6 +335,9 @@ protected function drupalCreateContentType(array $values = array()) { return $type; } + /** + * @needsdoc + */ protected function drupalBuildView($entity, $view_mode = 'full', $langcode = NULL, $reset = FALSE) { $render_controller = $this->container->get('entity.manager')->getViewBuilder($entity->getEntityTypeId()); if ($reset) { diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php index 90c2c92..261aa70 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php @@ -26,7 +26,7 @@ public static function getInfo() { /** * Tests language related methods of the Entity class. */ - public function atestEntityLanguageMethods() { + public function testEntityLanguageMethods() { // All entity variations have to have the same results. foreach (entity_test_entity_types() as $entity_type) { $this->_testEntityLanguageMethods($entity_type); @@ -129,7 +129,7 @@ protected function _testEntityLanguageMethods($entity_type) { /** * Tests multilingual properties. */ - public function atestMultilingualProperties() { + public function testMultilingualProperties() { // Test all entity variations with data table support. foreach (entity_test_entity_types(ENTITY_TEST_TYPES_MULTILINGUAL) as $entity_type) { $this->_testMultilingualProperties($entity_type); @@ -288,7 +288,7 @@ protected function _testMultilingualProperties($entity_type) { /** * Tests the Entity Translation API behavior. */ - function atestEntityTranslationAPI() { + function testEntityTranslationAPI() { $default_langcode = $this->langcodes[0]; $langcode = $this->langcodes[1]; $entity = $this->entityManager @@ -510,7 +510,7 @@ function testLanguageFallback() { /** * Check that field translatability is handled properly. */ - function atestFieldDefinitions() { + function testFieldDefinitions() { // Check that field translatability can be altered to be enabled or disabled // in field definitions. $entity_type = 'entity_test_mulrev'; @@ -548,7 +548,7 @@ function atestFieldDefinitions() { /** * Tests that changing entity language does not break field language. */ - public function atestLanguageChange() { + public function testLanguageChange() { $entity_type = 'entity_test_mul'; $controller = $this->entityManager->getStorageController($entity_type); $langcode = $this->langcodes[0];