diff --git a/core/lib/Drupal/Core/Entity/EntityListController.php b/core/lib/Drupal/Core/Entity/EntityListController.php index 1fdb4ba..7335b40 100644 --- a/core/lib/Drupal/Core/Entity/EntityListController.php +++ b/core/lib/Drupal/Core/Entity/EntityListController.php @@ -64,6 +64,23 @@ public function load() { } /** + * Provides a operation link to add a new entity. + * @return array + * An associative array containing the following key-value-pairs: + * title: The localized title of the operation. + * - href: The path for the operation. + * - (optional) options: An array of URL options for the path. + */ + public function addOperation() { + if (isset($this->entityInfo['uri_prefix']) && isset($this->entityInfo['label'])) { + return array( + 'href' => $this->entityInfo['uri_prefix'] . '/add', + 'title' => t('Add @label', array('@label' => $this->entityInfo['label'])), + ); + } + } + + /** * Implements Drupal\Core\Entity\EntityListControllerInterface::getOperations(). */ public function getOperations(EntityInterface $entity) { @@ -147,11 +164,16 @@ public function buildOperations(EntityInterface $entity) { * @todo Add a link to add a new item to the #empty text. */ public function render() { + $add_link = ''; + // Provide an add link if the listing controller provides one. + if (method_exists($this, 'addOperation') && $link = $this->addOperation()) { + $add_link = l($link['title'], $link['href'], $link); + } $build = array( '#theme' => 'table', '#header' => $this->buildHeader(), '#rows' => array(), - '#empty' => t('There is no @label yet.', array('@label' => $this->entityInfo['label'])), + '#empty' => t('There is no @label yet. !add_link', array('@label' => $this->entityInfo['label'], '!add_link' => $add_link)), ); foreach ($this->load() as $entity) { $build['#rows'][$entity->id()] = $this->buildRow($entity); diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php index 13f5a76..08e795f 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php @@ -128,7 +128,7 @@ function testListUI() { $this->assertIdentical((string) $elements[1], 'default'); $this->assertTrue($elements[2]->children()->xpath('//ul'), 'Operations list found.'); - // Add a new entity using the operations link. + // Add a new entity using the local action link. $this->assertLink('Add test configuration'); $this->clickLink('Add test configuration'); $this->assertResponse(200); diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigTest.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigTest.php index 8690b2a..e1cfff5 100644 --- a/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigTest.php +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigTest.php @@ -24,6 +24,7 @@ * "default" = "Drupal\config_test\ConfigTestFormController" * }, * uri_callback = "config_test_uri", + * uri_prefix = "admin/structure/config_test", * config_prefix = "config_test.dynamic", * entity_keys = { * "id" = "id",