core/includes/common.inc | 3 ++ core/lib/Drupal/Core/Entity/EntityViewBuilder.php | 1 - .../Core/Entity/EntityViewBuilderInterface.php | 2 +- .../Tests/CustomBlockBuildContentTest.php | 41 ------------------- .../lib/Drupal/comment/CommentViewBuilder.php | 9 +++-- .../FieldFormatter/CommentDefaultFormatter.php | 9 +++-- .../Drupal/comment/Tests/CommentCacheTagsTest.php | 15 +++++-- .../comment/Tests/CommentContentRebuildTest.php | 46 ---------------------- .../Drupal/datetime/Tests/DateTimeFieldTest.php | 4 +- .../EntityReferenceEntityFormatter.php | 4 +- .../node/lib/Drupal/node/NodeViewBuilder.php | 11 ++++-- .../lib/Drupal/node/Tests/NodeBuildContentTest.php | 38 ------------------ .../lib/Drupal/node/Tests/NodeCacheTagsTest.php | 2 + .../lib/Drupal/node/Tests/NodeRSSContentTest.php | 4 +- .../lib/Drupal/system/Tests/Common/RenderTest.php | 5 +-- .../tests/modules/common_test/common_test.module | 6 ++- 16 files changed, 47 insertions(+), 153 deletions(-) diff --git a/core/includes/common.inc b/core/includes/common.inc index d10b9ca..5657f4b 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -3990,6 +3990,9 @@ function drupal_render_cache_set(&$markup, array $elements) { * @param string $token * A unique token to uniquely identify the placeholder. * + * @return string + * The generated placeholder HTML. + * * @see drupal_render_cache_get() */ function drupal_render_cache_generate_placeholder($callback, array $context, $token) { diff --git a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php index e18c9a6..a2efcb4 100644 --- a/core/lib/Drupal/Core/Entity/EntityViewBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php @@ -15,7 +15,6 @@ use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\TypedData\TranslatableInterface; use Drupal\entity\Entity\EntityViewDisplay; -use Drupal\Core\Render\Element; use Drupal\Component\Utility\NestedArray; use Symfony\Component\DependencyInjection\ContainerInterface; diff --git a/core/lib/Drupal/Core/Entity/EntityViewBuilderInterface.php b/core/lib/Drupal/Core/Entity/EntityViewBuilderInterface.php index dd658b0..0e8697a 100644 --- a/core/lib/Drupal/Core/Entity/EntityViewBuilderInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilderInterface.php @@ -19,7 +19,7 @@ * Build the structured $content property on the entity. * * @param &$build - * The elements being built. + * The renderable array representing the entity content. * @param \Drupal\Core\Entity\EntityInterface[] $entities * The entities whose content is being built. * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface[] $displays diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockBuildContentTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockBuildContentTest.php deleted file mode 100644 index cee6ce8..0000000 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockBuildContentTest.php +++ /dev/null @@ -1,41 +0,0 @@ - 'Rebuild content', - 'description' => 'Test the rebuilding of content for full view modes.', - 'group' => 'Custom Block', - ); - } - - /** - * Ensures that content is rebuilt in calls to custom_block_build_content(). - */ - public function testCustomBlockRebuildContent() { - $block = $this->createCustomBlock(); - - // Set a property in the content array so we can test for its existence later on. - $block->content['test_content_property'] = array( - '#value' => $this->randomString(), - ); - $content = entity_view_multiple(array($block), 'full'); - - // If the property doesn't exist it means the block->content was rebuilt. - $this->assertFalse(isset($content['test_content_property']), 'Custom block content was emptied prior to being built.'); - } -} diff --git a/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php b/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php index c37fafd..abb698a 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php +++ b/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php @@ -88,9 +88,8 @@ public function __construct(EntityTypeInterface $entity_type, EntityManagerInter */ public function buildContent(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL) { /** @var \Drupal\comment\CommentInterface[] $entities */ - $return = array(); if (empty($entities)) { - return $return; + return; } // Pre-load associated users into cache to leverage multiple loading. @@ -162,6 +161,8 @@ public function buildContent(array &$build, array $entities, array $displays, $v * * Renders the links on a comment. * + * @param array $element + * The renderable array that contains the to be replaced placeholder. * @param array $context * An array with the following keys: * - comment_entity_id: a comment entity ID @@ -197,8 +198,8 @@ public static function renderLinks(array $element, array $context) { ); \Drupal::moduleHandler()->alter('comment_links', $links, $entity, $hook_context); } - $replace = drupal_render($links); - $element['#markup'] = str_replace($placeholder, $replace, $element['#markup']); + $markup = drupal_render($links); + $element['#markup'] = str_replace($placeholder, $markup, $element['#markup']); return $element; } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php index 4b1d772..c304c79 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php @@ -196,6 +196,8 @@ public function viewElements(FieldItemListInterface $items) { /** * #post_render_cache callback; replaces placeholder with comment form. * + * @param array $element + * The renderable array that contains the to be replaced placeholder. * @param array $context * An array with the following keys: * - entity_type: an entity type @@ -210,9 +212,10 @@ public static function renderForm(array $element, array $context) { $placeholder = drupal_render_cache_generate_placeholder($callback, $context, $context['token']); $entity = entity_load($context['entity_type'], $context['entity_id']); $form = comment_add($entity, $context['field_name']); - // @todo: #attached. - $replace = drupal_render($form, TRUE); - $element['#markup'] = str_replace($placeholder, $replace, $element['#markup']); + // @todo: This only works as long as assets are still tracked in a global + // static variable, see https://drupal.org/node/2238835 + $markup = drupal_render($form, TRUE); + $element['#markup'] = str_replace($placeholder, $markup, $element['#markup']); return $element; } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentCacheTagsTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentCacheTagsTest.php index 082604d..d12c6bb 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentCacheTagsTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentCacheTagsTest.php @@ -58,10 +58,13 @@ protected function createEntity() { )); $entity_test->save(); - // Create a "Llama" taxonomy term. + // Create a "Llama" comment. $comment = entity_create('comment', array( 'subject' => 'Llama', - 'comment_body' => 'The name "llama" was adopted by European settlers from native Peruvians.', + 'comment_body' => array( + 'value' => 'The name "llama" was adopted by European settlers from native Peruvians.', + 'format' => 'plain_text', + ), 'entity_id' => $entity_test->id(), 'entity_type' => 'entity_test', 'field_name' => 'comment', @@ -72,7 +75,13 @@ protected function createEntity() { return $comment; } + /** + * {@inheritdoc} + * + * Each comment must have a comment body, which always has a text format. + */ protected function getAdditionalCacheTagsForEntity(EntityInterface $entity) { - return array('filter_format:'); + return array('filter_format:plain_text'); } + } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentContentRebuildTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentContentRebuildTest.php deleted file mode 100644 index c467a09..0000000 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentContentRebuildTest.php +++ /dev/null @@ -1,46 +0,0 @@ - 'Comment Rebuild', - 'description' => 'Test to make sure the comment content is rebuilt.', - 'group' => 'Comment', - ); - } - - /** - * Tests the rebuilding of comment's content arrays on calling comment_view(). - */ - function testCommentRebuild() { - // Update the comment settings so preview isn't required. - $this->drupalLogin($this->admin_user); - $this->setCommentSubject(TRUE); - $this->setCommentPreview(DRUPAL_OPTIONAL); - $this->drupalLogout(); - - // Log in as the web user and add the comment. - $this->drupalLogin($this->web_user); - $subject_text = $this->randomName(); - $comment_text = $this->randomName(); - $comment = $this->postComment($this->node, $comment_text, $subject_text, TRUE); - $this->assertTrue($this->commentExists($comment), 'Comment found.'); - - // Add the property to the content array and then see if it still exists on build. - $comment->content['test_property'] = array('#value' => $this->randomString()); - $built_content = comment_view($comment); - - // This means that the content was rebuilt as the added test property no longer exists. - $this->assertFalse(isset($built_content['test_property']), 'Comment content was emptied before being built.'); - } -} diff --git a/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeFieldTest.php b/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeFieldTest.php index 76b4cb9..dc28adf 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeFieldTest.php +++ b/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeFieldTest.php @@ -457,8 +457,8 @@ protected function renderTestEntity($id, $view_mode = 'full', $reset = TRUE) { } $entity = entity_load('entity_test', $id); $display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode); - $entity->content = $display->build($entity); - $output = drupal_render($entity->content); + $build = $display->build($entity); + $output = drupal_render($build); $this->drupalSetContent($output); $this->verbose($output); } diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php index 623140f..a21047d 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php @@ -93,9 +93,7 @@ public function viewElements(FieldItemListInterface $items) { } if (!empty($item->target_id)) { - $entity = clone $item->entity; - unset($entity->content); - $elements[$delta] = entity_view($entity, $view_mode, $item->getLangcode()); + $elements[$delta] = entity_view($item->entity, $view_mode, $item->getLangcode()); if (empty($links) && isset($result[$delta][$target_type][$item->target_id]['links'])) { // Hide the element links. diff --git a/core/modules/node/lib/Drupal/node/NodeViewBuilder.php b/core/modules/node/lib/Drupal/node/NodeViewBuilder.php index 1a61aa0..0f6a800 100644 --- a/core/modules/node/lib/Drupal/node/NodeViewBuilder.php +++ b/core/modules/node/lib/Drupal/node/NodeViewBuilder.php @@ -20,9 +20,9 @@ class NodeViewBuilder extends EntityViewBuilder { * {@inheritdoc} */ public function buildContent(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL) { - $return = array(); + /** @var \Drupal\node\NodeInterface[] $entities */ if (empty($entities)) { - return $return; + return; } // Attach user account. @@ -79,6 +79,7 @@ protected function getBuildDefaults(EntityInterface $entity, $view_mode = 'full' else { // The node 'submitted' info is not rendered in a standard way (renderable // array) so we have to add a cache tag manually. + // @todo Delete this once https://drupal.org/node/2226493 lands. $defaults['#cache']['tags']['user'][] = $entity->getOwnerId(); } @@ -90,6 +91,8 @@ protected function getBuildDefaults(EntityInterface $entity, $view_mode = 'full' * * Renders the links on a node. * + * @param array $element + * The renderable array that contains the to be replaced placeholder. * @param array $context * An array with the following keys: * - node_entity_id: a node entity ID @@ -121,8 +124,8 @@ public static function renderLinks(array $element, array $context) { ); \Drupal::moduleHandler()->alter('node_links', $links, $entity, $hook_context); } - $replace = drupal_render($links); - $element['#markup'] = str_replace($placeholder, $replace, $element['#markup']); + $markup = drupal_render($links); + $element['#markup'] = str_replace($placeholder, $markup, $element['#markup']); return $element; } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeBuildContentTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeBuildContentTest.php deleted file mode 100644 index 17833d9..0000000 --- a/core/modules/node/lib/Drupal/node/Tests/NodeBuildContentTest.php +++ /dev/null @@ -1,38 +0,0 @@ - 'Rebuild content', - 'description' => 'Test the rebuilding of content for different build modes.', - 'group' => 'Node', - ); - } - - /** - * Ensures that content array is rebuilt on every call to node_build_content(). - */ - function testNodeRebuildContent() { - $node = $this->drupalCreateNode(); - - // Set a property in the content array so we can test for its existence later on. - $node->content['test_content_property'] = array( - '#value' => $this->randomString(), - ); - $content = node_view($node); - - // If the property doesn't exist it means the node->content was rebuilt. - $this->assertFalse(isset($content['test_content_property']), 'Node content was emptied prior to being built.'); - } -} diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeCacheTagsTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeCacheTagsTest.php index 0d3dc2a..962f2f8 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeCacheTagsTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeCacheTagsTest.php @@ -61,6 +61,8 @@ protected function createEntity() { /** * {@inheritdoc} + * + * Each node must have an author. */ protected function getAdditionalCacheTagsForEntity(EntityInterface $node) { return array('user:' . $node->getOwnerId()); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeRSSContentTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeRSSContentTest.php index 5357899..64f8a2a 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeRSSContentTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeRSSContentTest.php @@ -11,8 +11,8 @@ * Ensures that data added to nodes by other modules appears in RSS feeds. * * Create a node, enable the node_test module to ensure that extra data is - * added to the node->content array, then verify that the data appears on the - * sitewide RSS feed at rss.xml. + * added to the node's renderable array, then verify that the data appears on + * the site-wide RSS feed at rss.xml. */ class NodeRSSContentTest extends NodeTestBase { diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php index 2b8d411..7e0b782 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php @@ -11,7 +11,6 @@ use Drupal\Component\Utility\Json; use Drupal\Core\Render\Element; use Drupal\simpletest\DrupalUnitTestBase; -use Drupal\Component\Utility\Crypt; /** * Tests drupal_render(). @@ -549,7 +548,7 @@ function testDrupalRenderPostRenderCache() { function testDrupalRenderRenderCachePlaceholder() { $context = array( 'bar' => $this->randomContextValue(), - 'token' => Crypt::randomBytesBase64(55), + 'token' => drupal_render_cache_generate_token(), ); $callback = 'common_test_post_render_cache_placeholder'; $test_element = array( @@ -638,7 +637,7 @@ function testDrupalRenderChildElementRenderCachePlaceholder() { ); $context = array( 'bar' => $this->randomContextValue(), - 'token' => Crypt::randomBytesBase64(55), + 'token' => drupal_render_cache_generate_token(), ); $callback = 'common_test_post_render_cache_placeholder'; $test_element = array( 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 4982aac..2785be9 100644 --- a/core/modules/system/tests/modules/common_test/common_test.module +++ b/core/modules/system/tests/modules/common_test/common_test.module @@ -197,6 +197,8 @@ function common_test_post_render_cache(array $element, array $context) { /** * #post_render_cache callback; replaces placeholder, extends #attached. * + * @param array $element + * The renderable array that contains the to be replaced placeholder. * @param array $context * An array with the following keys: * - bar: contains a random string. @@ -219,8 +221,8 @@ function common_test_post_render_cache_placeholder(array $element, array $contex ), ), ); - $replace = drupal_render($replace_element); - $element['#markup'] = str_replace($placeholder, $replace, $element['#markup']); + $markup = drupal_render($replace_element); + $element['#markup'] = str_replace($placeholder, $markup, $element['#markup']); return $element; }