Issue #2284917 by Wim Leers, larowlan, olli: In-place editing of custom blocks broken *again* (because attributes and contextual links of custom blocks are lost)

8.0.x
Alex Pott 2014-12-24 12:53:40 +01:00
parent 95d4c594b0
commit 54c74fda4d
3 changed files with 47 additions and 4 deletions

View File

@ -16,6 +16,25 @@ use Drupal\Core\Entity\EntityViewBuilder;
*/
class BlockContentViewBuilder extends EntityViewBuilder {
/**
* {@inheritdoc}
*/
public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
return $this->viewMultiple(array($entity), $view_mode, $langcode)[0];
}
/**
* {@inheritdoc}
*/
public function viewMultiple(array $entities = array(), $view_mode = 'full', $langcode = NULL) {
$build_list = parent::viewMultiple($entities, $view_mode, $langcode);
// Apply the buildMultiple() #pre_render callback immediately, to make
// bubbling of attributes and contextual links to the actual block work.
// @see \Drupal\block\BlockViewBuilder::buildBlock()
unset($build_list['#pre_render'][0]);
return $this->buildMultiple($build_list);
}
/**
* {@inheritdoc}
*/
@ -33,7 +52,7 @@ class BlockContentViewBuilder extends EntityViewBuilder {
protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode, $langcode = NULL) {
parent::alterBuild($build, $entity, $display, $view_mode, $langcode);
// Add contextual links for this custom block.
if (!$entity->isNew() && $view_mode == 'full') {
if (!$entity->isNew()) {
$build['#contextual_links']['block_content'] = array(
'route_parameters' => array('block_content' => $entity->id()),
'metadata' => array('changed' => $entity->getChangedTime()),

View File

@ -53,7 +53,13 @@ use Drupal\block_content\BlockContentInterface;
* },
* bundle_entity_type = "block_content_type",
* field_ui_base_route = "entity.block_content_type.edit_form",
* render_cache = FALSE,
* )
*
* Note that render caching of block_content entities is disabled because they
* are always rendered as blocks, and blocks already have their own render
* caching.
* See https://www.drupal.org/node/2284917#comment-9132521 for more information.
*/
class BlockContent extends ContentEntityBase implements BlockContentInterface {

View File

@ -8,11 +8,10 @@
namespace Drupal\quickedit\Tests;
use Drupal\Component\Serialization\Json;
use Drupal\simpletest\WebTestBase;
use Drupal\quickedit\Ajax\MetadataCommand;
use Drupal\Core\Ajax\AppendCommand;
use Drupal\Component\Utility\Unicode;
use Drupal\block_content\Entity\BlockContent;
use Drupal\node\Entity\Node;
use Drupal\simpletest\WebTestBase;
/**
* Tests loading of in-place editing functionality and lazy loading of its
@ -493,4 +492,23 @@ class QuickEditLoadingTest extends WebTestBase {
}
}
/**
* Tests that Quick Edit's data- attributes are present for content blocks.
*/
public function testContentBlock() {
\Drupal::service('module_installer')->install(array('block_content'));
// Create and place a content_block block.
$block = BlockContent::create([
'info' => $this->randomMachineName(),
'type' => 'basic',
'langcode' => 'en',
]);
$block->save();
$this->drupalPlaceBlock('block_content:' . $block->uuid());
// Check that the data- attribute is present.
$this->drupalGet('');
$this->assertRaw('data-quickedit-entity-id="block_content/1"');
}
}