diff --git a/core/modules/block_content/src/Entity/BlockContentType.php b/core/modules/block_content/src/Entity/BlockContentType.php index 7c8f111de3..f4e126f4b4 100644 --- a/core/modules/block_content/src/Entity/BlockContentType.php +++ b/core/modules/block_content/src/Entity/BlockContentType.php @@ -2,8 +2,9 @@ namespace Drupal\block_content\Entity; -use Drupal\Core\Config\Entity\ConfigEntityBundleBase; use Drupal\block_content\BlockContentTypeInterface; +use Drupal\Core\Config\Entity\ConfigEntityBundleBase; +use Drupal\Core\Url; /** * Defines the custom block type entity. @@ -85,4 +86,23 @@ public function shouldCreateNewRevision() { return $this->revision; } + /** + * {@inheritdoc} + */ + public function toUrl($rel = 'edit-form', array $options = []) { + // When the 'add-form' link template is requested, return the legacy route. + // This route was created before we had structured entity paths so it is not + // discovered by the parent method. + if ($rel === 'add-form') { + $uri = new Url('block_content.type_add'); + $options += [ + 'language' => NULL, + 'entity_type' => $this->getEntityTypeId(), + 'entity' => $this, + ]; + return $uri->setOptions($options); + } + return parent::toUrl($rel, $options); + } + } diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php index ad68e2df68..8068cb7dc4 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Access\AccessResult; use Drupal\Core\DependencyInjection\ContainerBuilder; +use Drupal\Core\Entity\EntityAccessControlHandlerInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityListBuilder; use Drupal\Core\Routing\RedirectDestinationInterface; @@ -70,6 +71,13 @@ class EntityListBuilderTest extends UnitTestCase { */ protected $redirectDestination; + /** + * The access control handler. + * + * @var \Drupal\Core\Entity\EntityAccessControlHandlerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $accessControlHandler; + /** * The EntityListBuilder object to test. * @@ -88,7 +96,8 @@ protected function setUp() { $this->moduleHandler = $this->getMock('\Drupal\Core\Extension\ModuleHandlerInterface'); $this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface'); $this->translationManager = $this->getMock('\Drupal\Core\StringTranslation\TranslationInterface'); - $this->entityListBuilder = new TestEntityListBuilder($this->entityType, $this->roleStorage); + $this->accessControlHandler = $this->getMock(EntityAccessControlHandlerInterface::class); + $this->entityListBuilder = new TestEntityListBuilder($this->entityType, $this->roleStorage, $this->accessControlHandler); $this->redirectDestination = $this->getMock(RedirectDestinationInterface::class); $this->container = new ContainerBuilder(); \Drupal::setContainer($this->container); @@ -137,7 +146,7 @@ public function testGetOperations() { ->method('getAsArray') ->willReturn(['destination' => '/foo/bar']); - $list = new EntityListBuilder($this->entityType, $this->roleStorage); + $list = new EntityListBuilder($this->entityType, $this->roleStorage, $this->accessControlHandler); $list->setStringTranslation($this->translationManager); $list->setRedirectDestination($this->redirectDestination);