diff --git a/core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php b/core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php index 3729f2d..0f5cf79 100644 --- a/core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php +++ b/core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php @@ -7,10 +7,12 @@ namespace Drupal\Core\Config\Entity; +use Drupal\Core\Entity\EntityAccessControllerInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Form\FormInterface; +use Drupal\Core\Utility\LinkGeneratorInterface; /** * Defines a class to build a draggable listing of configuration entities. @@ -48,8 +50,8 @@ /** * {@inheritdoc} */ - public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage) { - parent::__construct($entity_type, $storage); + public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, EntityAccessControllerInterface $entity_access, LinkGeneratorInterface $link_generator) { + parent::__construct($entity_type, $storage, $entity_access, $link_generator); // Check if the entity type supports weighting. if ($this->entityType->hasKey('weight')) { diff --git a/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php b/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php index 6bc8a23..e6608d7 100644 --- a/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php @@ -45,8 +45,8 @@ public function access(EntityInterface $entity, $operation, $langcode = Language * Checks access to create an entity. * * @param string $entity_bundle - * (optional) The bundle of the entity. Required if the entity supports - * bundles, defaults to NULL otherwise. + * (optional) The bundle of the entity. If no bundle has been given, access + * is checked for any available bundle. * @param \Drupal\Core\Session\AccountInterface $account * (optional) The user session for which to check access, or NULL to check * access for the current user. Defaults to NULL. diff --git a/core/lib/Drupal/Core/Entity/EntityListBuilder.php b/core/lib/Drupal/Core/Entity/EntityListBuilder.php index ca5025c..b0b7d7d 100644 --- a/core/lib/Drupal/Core/Entity/EntityListBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityListBuilder.php @@ -8,6 +8,8 @@ namespace Drupal\Core\Entity; use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\Core\Utility\LinkGeneratorInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Component\Utility\String; @@ -17,6 +19,13 @@ class EntityListBuilder extends EntityControllerBase implements EntityListBuilderInterface, EntityControllerInterface { /** + * The entity access controller. + * + * @var \Drupal\Core\Entity\EntityAccessControllerInterface + */ + protected $entityAccess; + + /** * The entity storage class. * * @var \Drupal\Core\Entity\EntityStorageInterface @@ -38,12 +47,24 @@ class EntityListBuilder extends EntityControllerBase implements EntityListBuilde protected $entityType; /** + * The link generator. + * + * @var \Drupal\Core\Utility\LinkGeneratorInterface + */ + protected $linkGenerator; + + /** * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { + /** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */ + $entity_manager = $container->get('entity.manager'); + return new static( $entity_type, - $container->get('entity.manager')->getStorage($entity_type->id()) + $entity_manager->getStorage($entity_type->id()), + $entity_manager->getAccessController($entity_type->id()), + $container->get('link_generator') ); } @@ -54,11 +75,17 @@ public static function createInstance(ContainerInterface $container, EntityTypeI * The entity type definition. * @param \Drupal\Core\Entity\EntityStorageInterface $storage * The entity storage class. + * @param \Drupal\Core\Entity\EntityAccessControllerInterface $entity_access + * The entity access controller. + * @param \Drupal\Core\Utility\LinkGeneratorInterface $link_generator + * The link generator. */ - public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage) { + public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, EntityAccessControllerInterface $entity_access, LinkGeneratorInterface $link_generator) { + $this->entityAccess = $entity_access; $this->entityTypeId = $entity_type->id(); $this->storage = $storage; $this->entityType = $entity_type; + $this->linkGenerator = $link_generator; } /** @@ -181,16 +208,19 @@ public function buildOperations(EntityInterface $entity) { * {@inheritdoc} * * Builds the entity listing as renderable array for theme_table(). - * - * @todo Add a link to add a new item to the #empty text. */ public function render() { + $empty_text = $this->getEmptyText(); + $add_link = $this->createAddLink(); + if ($add_link) { + $empty_text .= ' ' . $add_link; + } $build = array( '#type' => 'table', '#header' => $this->buildHeader(), '#title' => $this->getTitle(), '#rows' => array(), - '#empty' => $this->t('There is no @label yet.', array('@label' => $this->entityType->getLabel())), + '#empty' => $empty_text, ); foreach ($this->load() as $entity) { if ($row = $this->buildRow($entity)) { @@ -201,6 +231,44 @@ public function render() { } /** + * Gets the text to display when the list is empty. + * + * @return string + */ + protected function getEmptyText() { + return $this->t('There is no @label yet.', array( + '@label' => $this->entityType->getLabel(), + )); + } + + /** + * Gets the text for the "Add new entity" link. + * + * @return string + */ + protected function getAddLinkText() { + return $this->t('Add one.'); + } + + /** + * Creates a link to add a new entity. + * + * @return string|false + * The HTML link or FALSE if no link is available. + */ + protected function createAddLink() { + if ($this->entityType->hasLinkTemplate('add-entity-form') && $this->entityAccess->createAccess()) { + return $this->linkGenerator->generate( + $this->getAddLinkText(), + $this->entityType->getLinkTemplate('add-entity-form') + ); + } + else { + return FALSE; + } + } + + /** * Returns the title of the page. * * @return string diff --git a/core/modules/action/lib/Drupal/action/ActionListBuilder.php b/core/modules/action/lib/Drupal/action/ActionListBuilder.php index 2d3af86..302c99c 100644 --- a/core/modules/action/lib/Drupal/action/ActionListBuilder.php +++ b/core/modules/action/lib/Drupal/action/ActionListBuilder.php @@ -8,10 +8,12 @@ namespace Drupal\action; use Drupal\Core\Action\ActionManager; +use Drupal\Core\Entity\EntityAccessControllerInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Config\Entity\ConfigEntityListBuilder; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Utility\LinkGeneratorInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -41,11 +43,15 @@ class ActionListBuilder extends ConfigEntityListBuilder { * The entity type definition. * @param \Drupal\Core\Entity\EntityStorageInterface $storage * The action storage. + * @param \Drupal\Core\Entity\EntityAccessControllerInterface $entity_access + * The entity access controller. + * @param \Drupal\Core\Utility\LinkGeneratorInterface $link_generator + * The link generator. * @param \Drupal\Core\Action\ActionManager $action_manager * The action plugin manager. */ - public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ActionManager $action_manager) { - parent::__construct($entity_type, $storage); + public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, EntityAccessControllerInterface $entity_access, LinkGeneratorInterface $link_generator, ActionManager $action_manager) { + parent::__construct($entity_type, $storage, $entity_access, $link_generator); $this->actionManager = $action_manager; } @@ -54,9 +60,14 @@ public function __construct(EntityTypeInterface $entity_type, EntityStorageInter * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { + /** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */ + $entity_manager = $container->get('entity.manager'); + return new static( $entity_type, - $container->get('entity.manager')->getStorage($entity_type->id()), + $entity_manager->getStorage($entity_type->id()), + $entity_manager->getAccessController($entity_type->id()), + $container->get('link_generator'), $container->get('plugin.manager.action') ); } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php index 71913b7..dab73c6 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php @@ -39,7 +39,8 @@ * "canonical" = "custom_block.edit", * "delete-form" = "custom_block.delete", * "edit-form" = "custom_block.edit", - * "admin-form" = "custom_block.type_edit" + * "admin-form" = "custom_block.type_edit", + * "add-entity-form" = "custom_block.add_page" * }, * fieldable = TRUE, * translatable = TRUE, diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlockType.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlockType.php index a7674d0..013ea95 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlockType.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlockType.php @@ -35,7 +35,8 @@ * }, * links = { * "delete-form" = "custom_block.type_delete", - * "edit-form" = "custom_block.type_edit" + * "edit-form" = "custom_block.type_edit", + * "add-entity-form" = "custom_block.type_add" * } * ) */ diff --git a/core/modules/block/lib/Drupal/block/BlockListBuilder.php b/core/modules/block/lib/Drupal/block/BlockListBuilder.php index 113e8be..29b0d0d 100644 --- a/core/modules/block/lib/Drupal/block/BlockListBuilder.php +++ b/core/modules/block/lib/Drupal/block/BlockListBuilder.php @@ -12,10 +12,12 @@ use Drupal\Component\Utility\String; use Drupal\Core\Cache\Cache; use Drupal\Core\Config\Entity\ConfigEntityListBuilder; +use Drupal\Core\Entity\EntityAccessControllerInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Form\FormInterface; +use Drupal\Core\Utility\LinkGeneratorInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -61,11 +63,15 @@ class BlockListBuilder extends ConfigEntityListBuilder implements FormInterface * The entity type definition. * @param \Drupal\Core\Entity\EntityStorageInterface $storage * The entity storage class. + * @param \Drupal\Core\Entity\EntityAccessControllerInterface $entity_access + * The entity access controller. + * @param \Drupal\Core\Utility\LinkGeneratorInterface $link_generator + * The link generator. * @param \Drupal\block\BlockManagerInterface $block_manager * The block manager. */ - public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, BlockManagerInterface $block_manager) { - parent::__construct($entity_type, $storage); + public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, EntityAccessControllerInterface $entity_access, LinkGeneratorInterface $link_generator, BlockManagerInterface $block_manager) { + parent::__construct($entity_type, $storage, $entity_access, $link_generator); $this->blockManager = $block_manager; } @@ -74,9 +80,14 @@ public function __construct(EntityTypeInterface $entity_type, EntityStorageInter * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { + /** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */ + $entity_manager = $container->get('entity.manager'); + return new static( $entity_type, - $container->get('entity.manager')->getStorage($entity_type->id()), + $entity_manager->getStorage($entity_type->id()), + $entity_manager->getAccessController($entity_type->id()), + $container->get('link_generator'), $container->get('plugin.manager.block') ); } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FieldInstanceConfigListBuilder.php b/core/modules/field_ui/lib/Drupal/field_ui/FieldInstanceConfigListBuilder.php index b801f4c..623c186 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FieldInstanceConfigListBuilder.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldInstanceConfigListBuilder.php @@ -9,9 +9,6 @@ use Drupal\Core\Config\Entity\ConfigEntityListBuilder; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\Entity\EntityTypeInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides lists of field instance config entities. @@ -19,33 +16,6 @@ class FieldInstanceConfigListBuilder extends ConfigEntityListBuilder { /** - * The entity manager. - * - * @var \Drupal\Core\Entity\EntityManagerInterface - */ - protected $entityManager; - - /** - * Constructs a new class instance. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type definition. - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager. - */ - public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager) { - parent::__construct($entity_type, $entity_manager->getStorage($entity_type->id())); - $this->entityManager = $entity_manager; - } - - /** - * {@inheritdoc} - */ - public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static($entity_type, $container->get('entity.manager')); - } - - /** * {@inheritdoc} */ public function render() { diff --git a/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php b/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php index 4eaa2ec..034b406 100644 --- a/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php +++ b/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php @@ -43,7 +43,8 @@ * links = { * "flush-form" = "image.style_flush", * "edit-form" = "image.style_edit", - * "delete-form" = "image.style_delete" + * "delete-form" = "image.style_delete", + * "add-entity-form" = "image.style_add" * } * ) */ diff --git a/core/modules/image/lib/Drupal/image/ImageStyleListBuilder.php b/core/modules/image/lib/Drupal/image/ImageStyleListBuilder.php index 73dfe6c..98f6740 100644 --- a/core/modules/image/lib/Drupal/image/ImageStyleListBuilder.php +++ b/core/modules/image/lib/Drupal/image/ImageStyleListBuilder.php @@ -85,15 +85,4 @@ public function getDefaultOperations(EntityInterface $entity) { ); } - /** - * {@inheritdoc} - */ - public function render() { - $build = parent::render(); - $build['#empty'] = $this->t('There are currently no styles. Add a new one.', array( - '!url' => $this->urlGenerator->generateFromPath('admin/config/media/image-styles/add'), - )); - return $build; - } - } diff --git a/core/modules/node/lib/Drupal/node/Entity/Node.php b/core/modules/node/lib/Drupal/node/Entity/Node.php index 1fc6f03..060dcca 100644 --- a/core/modules/node/lib/Drupal/node/Entity/Node.php +++ b/core/modules/node/lib/Drupal/node/Entity/Node.php @@ -55,7 +55,8 @@ * "delete-form" = "node.delete_confirm", * "edit-form" = "node.page_edit", * "version-history" = "node.revision_overview", - * "admin-form" = "node.type_edit" + * "admin-form" = "node.type_edit", + * "add-entity-form" = "node.add_page" * } * ) */ diff --git a/core/modules/node/lib/Drupal/node/Entity/NodeType.php b/core/modules/node/lib/Drupal/node/Entity/NodeType.php index 1c3a839..3640b5b 100644 --- a/core/modules/node/lib/Drupal/node/Entity/NodeType.php +++ b/core/modules/node/lib/Drupal/node/Entity/NodeType.php @@ -37,7 +37,8 @@ * links = { * "add-form" = "node.add", * "edit-form" = "node.type_edit", - * "delete-form" = "node.type_delete_confirm" + * "delete-form" = "node.type_delete_confirm", + * "add-entity-form" = "node.type_add" * } * ) */ diff --git a/core/modules/node/lib/Drupal/node/NodeListBuilder.php b/core/modules/node/lib/Drupal/node/NodeListBuilder.php index fc9c0ba..2a30077 100644 --- a/core/modules/node/lib/Drupal/node/NodeListBuilder.php +++ b/core/modules/node/lib/Drupal/node/NodeListBuilder.php @@ -9,11 +9,13 @@ use Drupal\Component\Utility\String; use Drupal\Core\Datetime\Date; +use Drupal\Core\Entity\EntityAccessControllerInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityListBuilder; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Language\Language; +use Drupal\Core\Utility\LinkGeneratorInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -37,11 +39,15 @@ class NodeListBuilder extends EntityListBuilder { * The entity type definition. * @param \Drupal\Core\Entity\EntityStorageInterface $storage * The entity storage class. + * @param \Drupal\Core\Entity\EntityAccessControllerInterface $entity_access + * The entity access controller. + * @param \Drupal\Core\Utility\LinkGeneratorInterface $link_generator + * The link generator. * @param \Drupal\Core\Datetime\Date $date_service * The date service. */ - public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, Date $date_service) { - parent::__construct($entity_type, $storage); + public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, EntityAccessControllerInterface $entity_access, LinkGeneratorInterface $link_generator, Date $date_service) { + parent::__construct($entity_type, $storage, $entity_access, $link_generator); $this->dateService = $date_service; } @@ -50,9 +56,14 @@ public function __construct(EntityTypeInterface $entity_type, EntityStorageInter * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { + /** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */ + $entity_manager = $container->get('entity.manager'); + return new static( $entity_type, - $container->get('entity.manager')->getStorage($entity_type->id()), + $entity_manager->getStorage($entity_type->id()), + $entity_manager->getAccessController($entity_type->id()), + $container->get('link_generator'), $container->get('date') ); } @@ -60,6 +71,20 @@ public static function createInstance(ContainerInterface $container, EntityTypeI /** * {@inheritdoc} */ + protected function getEmptyText() { + return $this->t('There is no content yet.'); + } + + /** + * {@inheritdoc} + */ + protected function getAddLinkText() { + return $this->t('Add new content.'); + } + + /** + * {@inheritdoc} + */ public function buildHeader() { // Enable language column and filter if multiple languages are added. $header = array( diff --git a/core/modules/node/lib/Drupal/node/NodeTypeListBuilder.php b/core/modules/node/lib/Drupal/node/NodeTypeListBuilder.php index 779672a..8aeac3f 100644 --- a/core/modules/node/lib/Drupal/node/NodeTypeListBuilder.php +++ b/core/modules/node/lib/Drupal/node/NodeTypeListBuilder.php @@ -8,13 +8,8 @@ namespace Drupal\node; use Drupal\Core\Config\Entity\ConfigEntityListBuilder; -use Drupal\Core\Entity\EntityTypeInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Drupal\Core\Entity\EntityStorageInterface; -use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Component\Utility\Xss; -use Drupal\Component\Utility\String; /** * Defines a class to build a listing of node type entities. @@ -24,39 +19,6 @@ class NodeTypeListBuilder extends ConfigEntityListBuilder { /** - * The url generator service. - * - * @var \Drupal\Core\Routing\UrlGeneratorInterface - */ - protected $urlGenerator; - - /** - * Constructs a NodeTypeForm object. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type definition. - * @param \Drupal\Core\Entity\EntityStorageInterface $storage - * The entity storage class. - * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator - * The url generator service. - */ - public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, UrlGeneratorInterface $url_generator) { - parent::__construct($entity_type, $storage); - $this->urlGenerator = $url_generator; - } - - /** - * {@inheritdoc} - */ - public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $entity_type, - $container->get('entity.manager')->getStorage($entity_type->id()), - $container->get('url_generator') - ); - } - - /** * {@inheritdoc} */ public function buildHeader() { @@ -93,15 +55,5 @@ public function getDefaultOperations(EntityInterface $entity) { return $operations; } - /** - * {@inheritdoc} - */ - public function render() { - $build = parent::render(); - $build['#empty'] = t('No content types available. Add content type.', array( - '@link' => $this->urlGenerator->generateFromPath('admin/structure/types/add'), - )); - return $build; - } } diff --git a/core/modules/responsive_image/lib/Drupal/responsive_image/Entity/ResponsiveImageMapping.php b/core/modules/responsive_image/lib/Drupal/responsive_image/Entity/ResponsiveImageMapping.php index d94d376..1eb8375 100644 --- a/core/modules/responsive_image/lib/Drupal/responsive_image/Entity/ResponsiveImageMapping.php +++ b/core/modules/responsive_image/lib/Drupal/responsive_image/Entity/ResponsiveImageMapping.php @@ -34,7 +34,8 @@ * }, * links = { * "edit-form" = "responsive_image.mapping_page_edit", - * "duplicate-form" = "responsive_image.mapping_page_duplicate" + * "duplicate-form" = "responsive_image.mapping_page_duplicate", + * "add-entity-form" = "responsive_image.mapping_page_add" * } * ) */ diff --git a/core/modules/system/lib/Drupal/system/Entity/DateFormat.php b/core/modules/system/lib/Drupal/system/Entity/DateFormat.php index a3d6ece..d7d6d35 100644 --- a/core/modules/system/lib/Drupal/system/Entity/DateFormat.php +++ b/core/modules/system/lib/Drupal/system/Entity/DateFormat.php @@ -33,7 +33,8 @@ * admin_permission = "administer site configuration", * links = { * "delete-form" = "system.date_format_delete", - * "edit-form" = "system.date_format_edit" + * "edit-form" = "system.date_format_edit", + * "add-entity-form" = "system.date_format_add" * } * ) */ diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewListBuilder.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewListBuilder.php index 68ad5b0..e1c7138 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewListBuilder.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewListBuilder.php @@ -9,10 +9,12 @@ use Drupal\Component\Utility\String; use Drupal\Component\Plugin\PluginManagerInterface; +use Drupal\Core\Entity\EntityAccessControllerInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Config\Entity\ConfigEntityListBuilder; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Utility\LinkGeneratorInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -33,9 +35,14 @@ class ViewListBuilder extends ConfigEntityListBuilder { * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { + /** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */ + $entity_manager = $container->get('entity.manager'); + return new static( $entity_type, - $container->get('entity.manager')->getStorage($entity_type->id()), + $entity_manager->getStorage($entity_type->id()), + $entity_manager->getAccessController($entity_type->id()), + $container->get('link_generator'), $container->get('plugin.manager.views.display') ); } @@ -47,11 +54,15 @@ public static function createInstance(ContainerInterface $container, EntityTypeI * The entity type definition. * @param \Drupal\Core\Entity\EntityStorageInterface $storage. * The entity storage class. + * @param \Drupal\Core\Entity\EntityAccessControllerInterface $entity_access + * The entity access controller. + * @param \Drupal\Core\Utility\LinkGeneratorInterface $link_generator + * The link generator. * @param \Drupal\Component\Plugin\PluginManagerInterface $display_manager * The views display plugin manager to use. */ - public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, PluginManagerInterface $display_manager) { - parent::__construct($entity_type, $storage); + public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, EntityAccessControllerInterface $entity_access, LinkGeneratorInterface $link_generator, PluginManagerInterface $display_manager) { + parent::__construct($entity_type, $storage, $entity_access, $link_generator); $this->displayManager = $display_manager; } diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php index 121d745..53a218d 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php @@ -23,6 +23,13 @@ class EntityListBuilderTest extends UnitTestCase { /** + * The entity access controller. + * + * @var \Drupal\Core\Entity\EntityAccessControllerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $entityAccess; + + /** * The entity type used for testing. * * @var \Drupal\Core\Entity\EntityTypeInterface|\PHPUnit_Framework_MockObject_MockObject @@ -30,6 +37,13 @@ class EntityListBuilderTest extends UnitTestCase { protected $entityType; /** + * The link generator. + * + * @var \Drupal\Core\Utility\LinkGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $linkGenerator; + + /** * The module handler used for testing. * * @var \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit_Framework_MockObject_MockObject @@ -87,10 +101,12 @@ protected function setUp() { $this->role = $this->getMock('Drupal\user\RoleInterface'); $this->roleStorage = $this->getMock('\Drupal\user\RoleStorageInterface'); + $this->entityAccess = $this->getMock('\Drupal\Core\Entity\EntityAccessControllerInterface'); + $this->linkGenerator = $this->getMock('\Drupal\Core\Utility\LinkGeneratorInterface'); $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->moduleHandler); + $this->entityListBuilder = new TestEntityListBuilder($this->entityType, $this->roleStorage, $this->entityAccess, $this->linkGenerator); $this->container = new ContainerBuilder(); \Drupal::setContainer($this->container); } @@ -131,7 +147,7 @@ public function testGetOperations() { ->method('urlInfo') ->will($this->returnValue($url)); - $list = new EntityListBuilder($this->entityType, $this->roleStorage, $this->moduleHandler); + $list = new EntityListBuilder($this->entityType, $this->roleStorage, $this->entityAccess, $this->linkGenerator); $list->setStringTranslation($this->translationManager); $operations = $list->getOperations($this->role);