diff --git a/core/modules/block_content/config/install/views.view.block_content.yml b/core/modules/block_content/config/install/views.view.block_content.yml index 19d0b7d..2ed9764 100644 --- a/core/modules/block_content/config/install/views.view.block_content.yml +++ b/core/modules/block_content/config/install/views.view.block_content.yml @@ -418,8 +418,19 @@ display: admin_label: '' empty: true tokenize: false - content: 'No custom blocks available.' + content: 'There are no custom blocks available.' plugin_id: text_custom + block_content_listing_empty: + admin_label: '' + empty: true + field: block_content_listing_empty + group_type: group + id: block_content_listing_empty + label: '' + relationship: none + table: block_content + plugin_id: block_content_listing_empty + entity_type: block_content relationships: { } arguments: { } display_extenders: { } diff --git a/core/modules/block_content/src/BlockContentViewsData.php b/core/modules/block_content/src/BlockContentViewsData.php index 200d18f..d2d2680 100644 --- a/core/modules/block_content/src/BlockContentViewsData.php +++ b/core/modules/block_content/src/BlockContentViewsData.php @@ -40,6 +40,13 @@ public function getViewsData() { ); } + $data['block_content']['block_content_listing_empty'] = array( + 'title' => t('Empty block library behavior'), + 'help' => t('Provides a link to the add a new block.'), + 'area' => array( + 'id' => 'block_content_listing_empty', + ), + ); // Advertise this table as a possible base table. $data['block_content_revision']['table']['base']['help'] = $this->t('Block Content revision is a history of changes to block content.'); $data['block_content_revision']['table']['base']['defaults']['title'] = 'info'; diff --git a/core/modules/block_content/src/Plugin/views/area/ListingEmpty.php b/core/modules/block_content/src/Plugin/views/area/ListingEmpty.php new file mode 100644 index 0000000..681f664 --- /dev/null +++ b/core/modules/block_content/src/Plugin/views/area/ListingEmpty.php @@ -0,0 +1,91 @@ +accessManager = $access_manager; + $this->currentUser = $current_user; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('access_manager'), + $container->get('current_user') + ); + } + + /** + * {@inheritdoc} + */ + public function render($empty = FALSE) { + if (!$empty || !empty($this->options['empty'])) { + $element = array( + '#theme' => 'links', + '#links' => array( + array( + 'url' => Url::fromRoute('block_content.add_page'), + 'title' => $this->t('Add a custom block'), + ), + ), + '#access' => $this->accessManager->checkNamedRoute('block_content.add_page', array(), $this->currentUser), + ); + return $element; + } + return array(); + } + +} diff --git a/core/modules/block_content/src/Tests/BlockContentListViewsTest.php b/core/modules/block_content/src/Tests/BlockContentListViewsTest.php index 0edee1f..6bdadac 100644 --- a/core/modules/block_content/src/Tests/BlockContentListViewsTest.php +++ b/core/modules/block_content/src/Tests/BlockContentListViewsTest.php @@ -6,6 +6,7 @@ */ namespace Drupal\block_content\Tests; +use Drupal\Core\Url; /** * Tests the Views-powered listing of custom blocks. @@ -111,7 +112,8 @@ public function testListing() { $this->assertNoFieldByXpath('//td', $new_label, 'No label found for deleted custom block.'); // Confirm that the empty text is displayed. - $this->assertText(t('No custom blocks available.')); + $this->assertText('There are no custom blocks available.'); + $this->assertLink('Add a custom block'); } }