Verified Commit 0f891c58 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3056135 by tim.plunkett, tedbow, Wim Leers, marcoscano, rpayanm,...

Issue #3056135 by tim.plunkett, tedbow, Wim Leers, marcoscano, rpayanm, raman.b, smustgrave: Viewing Layout Builder enable node fails after Workflow enabled on bundle if another node was created before enabling
parent b70dfff4
Loading
Loading
Loading
Loading
Loading
+19 −7
Original line number Diff line number Diff line
@@ -43,11 +43,8 @@ protected function setUp(): void {
    //   https://www.drupal.org/project/drupal/issues/2917777.
    $this->drupalPlaceBlock('local_tasks_block');

    $workflow = $this->createEditorialWorkflow();

    // Add a new bundle and add an editorial workflow.
    // Add a new bundle.
    $this->createContentType(['type' => 'bundle_with_section_field']);
    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'bundle_with_section_field');

    // Add a new block content bundle to the editorial workflow.
    BlockContentType::create([
@@ -57,14 +54,29 @@ protected function setUp(): void {
    ])->save();
    block_content_add_body_field('basic');

    $workflow->getTypePlugin()->addEntityTypeAndBundle('block_content', 'basic');
    $workflow->save();

    // Enable layout overrides.
    LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')
      ->enableLayoutBuilder()
      ->setOverridable()
      ->save();
    // Create a node before enabling the workflow on the bundle.
    $node = $this->createNode([
      'type' => 'bundle_with_section_field',
      'title' => 'Pre-workflow node',
      'body' => [
        [
          'value' => 'The first node body',
        ],
      ],
    ]);
    // View the node to ensure the new extra field blocks are not cached when
    // the workflow is updated.
    $this->drupalGet($node->toUrl());
    // Add editorial workflow for the bundle.
    $workflow = $this->createEditorialWorkflow();
    $workflow->getTypePlugin()->addEntityTypeAndBundle('block_content', 'basic');
    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'bundle_with_section_field');
    $workflow->save();

    $this->drupalLogin($this->drupalCreateUser([
      'configure any layout',
+6 −0
Original line number Diff line number Diff line
@@ -37,6 +37,12 @@ services:
    arguments: ['@current_route_match']
    tags:
      - { name: cache.context }
  layout_builder.extra_fields.invalidator:
    class: Drupal\layout_builder\Cache\ExtraFieldBlockCacheTagInvalidator
    arguments: ['@plugin.manager.block']
    public: false
    tags:
      - { name: cache_tags_invalidator }
  layout_builder.sample_entity_generator:
    class: Drupal\layout_builder\Entity\LayoutBuilderSampleEntityGenerator
    arguments: ['@tempstore.shared', '@entity_type.manager']
+37 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\layout_builder\Cache;

use Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface;
use Drupal\Core\Block\BlockManagerInterface;
use Drupal\Core\Cache\CacheTagsInvalidatorInterface;

/**
 * Provides a cache tag invalidator that clears the block cache.
 *
 * @internal
 *   Tagged services are internal.
 */
class ExtraFieldBlockCacheTagInvalidator implements CacheTagsInvalidatorInterface {

  /**
   * Constructs a new ExtraFieldBlockCacheTagInvalidator.
   *
   * @param \Drupal\Core\Block\BlockManagerInterface $blockManager
   *   The block manager.
   */
  public function __construct(protected BlockManagerInterface $blockManager) {
  }

  /**
   * {@inheritdoc}
   */
  public function invalidateTags(array $tags) {
    if (in_array('entity_field_info', $tags, TRUE)) {
      if ($this->blockManager instanceof CachedDiscoveryInterface) {
        $this->blockManager->clearCachedDefinitions();
      }
    }
  }

}