diff --git a/core/modules/block_content/block_content.links.action.yml b/core/modules/block_content/block_content.links.action.yml index 4772a6f..b0900a6 100644 --- a/core/modules/block_content/block_content.links.action.yml +++ b/core/modules/block_content/block_content.links.action.yml @@ -8,6 +8,4 @@ block_content_add_action: route_name: block_content.add_page title: 'Add custom block' appears_on: - - block.admin_library - entity.block_content.collection - class: \Drupal\block_content\Plugin\Menu\LocalAction\BlockContentAddLocalAction diff --git a/core/modules/block_content/block_content.links.menu.yml b/core/modules/block_content/block_content.links.menu.yml index 03209f9..26fb0a1 100644 --- a/core/modules/block_content/block_content.links.menu.yml +++ b/core/modules/block_content/block_content.links.menu.yml @@ -1,5 +1,10 @@ +entity.block_content.collection: + title: 'Custom blocks' + route_name: entity.block_content.collection + parent: system.admin_content + description: 'Create and manage custom blocks that can be placed in theme regions.' entity.block_content_type.collection: - title: Block types + title: 'Block types' route_name: entity.block_content_type.collection parent: system.admin_structure - description: 'List and edit custom block types.' + description: 'Manage form and display settings for custom blocks.' diff --git a/core/modules/block_content/block_content.module b/core/modules/block_content/block_content.module index 5a8c222..e88e60f 100644 --- a/core/modules/block_content/block_content.module +++ b/core/modules/block_content/block_content.module @@ -18,22 +18,22 @@ function block_content_help($route_name, RouteMatchInterface $route_match) { $field_ui = \Drupal::moduleHandler()->moduleExists('field_ui') ? \Drupal::url('help.page', array('name' => 'field_ui')) : '#'; $output = ''; $output .= '

' . t('About') . '

'; - $output .= '

' . t('The Custom Block module allows you to create custom block types and content-containing blocks, and provides a page listing all of them. Custom block types have fields; see the Field module help for more information. Once created, custom blocks can be placed in regions just like blocks provided by other modules; see the Block module help page for details. For more information, see the online documentation for the Custom Block module.', array('!block-list' => \Drupal::url('entity.block_content.collection'), '!block-content' => \Drupal::url('entity.block_content.collection'), '!field-help' => \Drupal::url('help.page', array('name' => 'field')), '!blocks' => \Drupal::url('help.page', array('name' => 'block')), '!online-help' => 'https://www.drupal.org/documentation/modules/block_content')) . '

'; + $output .= '

' . t('The Custom Block module allows you to create custom block types and block content based on those types. Once created, these custom blocks can be placed in regions just like blocks provided by other modules. For more information, see the online documentation for the Custom Block module.', array('!block-types' => \Drupal::url('entity.block_content_type.collection'), '!block-list' => \Drupal::url('entity.block_content.collection'), '!online-help' => 'https://www.drupal.org/documentation/modules/block_content')) . '

'; $output .= '

' . t('Uses') . '

'; $output .= '
'; $output .= '
' . t('Creating and managing custom block types') . '
'; - $output .= '
' . t('Users with the Administer blocks permission can create and edit custom block types with fields and display settings, from the Block types page. For more information about managing fields and display settings, see the Field UI module help.', array('!types' => \Drupal::url('entity.block_content_type.collection'), '!field-ui' => $field_ui)) . '
'; + $output .= '
' . t('Users with the Administer blocks permission can create and edit custom block types, each with their own set of fields and display settings, from the Block types page. For more information about managing fields and display settings, see Field module help and Field UI module help.', array('!types' => \Drupal::url('entity.block_content_type.collection'), '!field-help' => \Drupal::url('help.page', ['name' => 'field']), '!field-ui' => $field_ui)) . '
'; $output .= '
' . t('Creating custom blocks') . '
'; - $output .= '
' . t('Users with the Administer blocks permission can create, edit, and delete custom blocks of each custom block type you have defined, from the Custom blocks page. Custom blocks are shown in the Place blocks list on the Block layout page; see the Block module help for more information about placing blocks.', array('!blocks' => \Drupal::url('block.admin_display'), '!block-list' => \Drupal::url('entity.block_content.collection'), '!block_help' => \Drupal::url('help.page', array('name' => 'block')))) . '
'; + $output .= '
' . t('Users with the Administer blocks permission can create, edit, and delete custom blocks from the Block content page. These custom blocks can then be added to a region of your site theme on the Block layout page. See the Block module help for more information about placing blocks.', array('!blocks' => \Drupal::url('block.admin_display'), '!block-list' => \Drupal::url('entity.block_content.collection'), '!block_help' => \Drupal::url('help.page', array('name' => 'block')))) . '
'; $output .= '
'; return $output; case 'entity.block_content.collection': - $output = '

' . t('Blocks belong to block types, each with its own fields and display settings. After creating a block, place it in a region from the Block layout page.', array('!types' => \Drupal::url('entity.block_content_type.collection'), '!blocks' => \Drupal::url('block.admin_display'))) . '

'; + $output = '

' . t('Every custom block is based on a block type, each with its own fields and display settings. After creating a block, place it in a region from the Block layout page.', array('!types' => \Drupal::url('entity.block_content_type.collection'), '!blocks' => \Drupal::url('block.admin_display'))) . '

'; return $output; case 'entity.block_content_type.collection': - $output = '

' . t('Each block type has its own fields and display settings. Create blocks of each type on the Custom blocks page.', array('!block-list' => \Drupal::url('entity.block_content.collection'))) . '

'; + $output = '

' . t('After creating a block type, you can create a block based on it from the Block content page. Each block type has its own fields and display settings.', array('!block-list' => \Drupal::url('entity.block_content.collection'))) . '

'; return $output; } diff --git a/core/modules/block_content/block_content.routing.yml b/core/modules/block_content/block_content.routing.yml index 957349d..6752a2e 100644 --- a/core/modules/block_content/block_content.routing.yml +++ b/core/modules/block_content/block_content.routing.yml @@ -30,7 +30,7 @@ entity.block_content_type.delete_form: path: '/admin/structure/block-content/manage/{block_content_type}/delete' defaults: _entity_form: 'block_content_type.delete' - _title: 'Delete' + _title: 'Delete block type' requirements: _entity_access: 'block_content_type.delete' options: @@ -39,6 +39,7 @@ entity.block_content_type.delete_form: entity.block_content.canonical: path: '/block/{block_content}' defaults: + _title_callback: '\Drupal\block_content\Controller\BlockContentController::blockContentTitle' _entity_form: 'block_content.edit' options: _admin_route: TRUE @@ -68,7 +69,7 @@ block_content.type_add: path: '/admin/structure/block-content/add' defaults: _entity_form: 'block_content_type.add' - _title: 'Add' + _title: 'Add block type' requirements: _permission: 'administer blocks' @@ -76,7 +77,7 @@ entity.block_content_type.edit_form: path: '/admin/structure/block-content/manage/{block_content_type}' defaults: _entity_form: 'block_content_type.edit' - _title: 'Edit' + _title: 'Edit block type' requirements: _entity_access: 'block_content_type.update' diff --git a/core/modules/block_content/config/optional/views.view.block_content.yml b/core/modules/block_content/config/optional/views.view.block_content.yml index 9ab5b83..2ed048a 100644 --- a/core/modules/block_content/config/optional/views.view.block_content.yml +++ b/core/modules/block_content/config/optional/views.view.block_content.yml @@ -163,7 +163,7 @@ display: click_sort_column: value type: string settings: - link_to_entity: true + link_to_entity: false group_column: value group_columns: { } group_rows: true diff --git a/core/modules/block_content/src/BlockContentForm.php b/core/modules/block_content/src/BlockContentForm.php index ec267cc..53c8723 100644 --- a/core/modules/block_content/src/BlockContentForm.php +++ b/core/modules/block_content/src/BlockContentForm.php @@ -182,11 +182,11 @@ public function save(array $form, FormStateInterface $form_state) { $context = array('@type' => $block->bundle(), '%info' => $block->label()); $logger = $this->logger('block_content'); $block_type = $this->blockContentTypeStorage->load($block->bundle()); - $t_args = array('@type' => $block_type->label(), '%info' => $block->label()); + $t_args = array('@type' => $block_type->label(), '%info' => $block->label(), '@layout-url' => \Drupal::url('block.admin_display')); if ($insert) { $logger->notice('@type: added %info.', $context); - drupal_set_message($this->t('@type %info has been created.', $t_args)); + drupal_set_message($this->t('@type %info has been created. Visit the Block layout page to add it to a region.', $t_args)); } else { $logger->notice('@type: updated %info.', $context); @@ -194,23 +194,7 @@ public function save(array $form, FormStateInterface $form_state) { } if ($block->id()) { - $form_state->setValue('id', $block->id()); - $form_state->set('id', $block->id()); - if ($insert) { - if (!$theme = $block->getTheme()) { - $theme = $this->config('system.theme')->get('default'); - } - $form_state->setRedirect( - 'block.admin_add', - array( - 'plugin_id' => 'block_content:' . $block->uuid(), - 'theme' => $theme, - ) - ); - } - else { - $form_state->setRedirectUrl($block->urlInfo('collection')); - } + $form_state->setRedirectUrl($block->urlInfo('collection')); } else { // In the unlikely case something went wrong on save, the block will be diff --git a/core/modules/block_content/src/Controller/BlockContentController.php b/core/modules/block_content/src/Controller/BlockContentController.php index f712367..f9874fc 100644 --- a/core/modules/block_content/src/Controller/BlockContentController.php +++ b/core/modules/block_content/src/Controller/BlockContentController.php @@ -7,10 +7,11 @@ namespace Drupal\block_content\Controller; +use Drupal\block_content\BlockContentInterface; +use Drupal\block_content\BlockContentTypeInterface; use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Entity\EntityStorageInterface; -use Drupal\block_content\BlockContentTypeInterface; use Drupal\Core\Extension\ThemeHandlerInterface; use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -120,6 +121,19 @@ public function addForm(BlockContentTypeInterface $block_content_type, Request $ } /** + * A title callback for block content entities. + * + * @param \Drupal\block_content\BlockContentInterface $block_content + * The current custom block. + * + * @return string + * The title of the custom block. + */ + public function blockContentTitle(BlockContentInterface $block_content) { + return $this->entityManager()->getTranslationFromContext($block_content)->label(); + } + + /** * Provides the page title for this controller. * * @param \Drupal\block_content\BlockContentTypeInterface $block_content_type diff --git a/core/modules/block_content/src/Plugin/Menu/LocalAction/BlockContentAddLocalAction.php b/core/modules/block_content/src/Plugin/Menu/LocalAction/BlockContentAddLocalAction.php deleted file mode 100644 index 62e0c3c..0000000 --- a/core/modules/block_content/src/Plugin/Menu/LocalAction/BlockContentAddLocalAction.php +++ /dev/null @@ -1,36 +0,0 @@ -getParameter('theme')) { - $options['query']['theme'] = $theme; - } - // Adds a destination on custom block listing. - if ($route_match->getRouteName() == 'entity.block_content.collection') { - $options['query']['destination'] = $this->url(''); - } - return $options; - } - -} diff --git a/core/modules/block_content/src/Tests/BlockContentCreationTest.php b/core/modules/block_content/src/Tests/BlockContentCreationTest.php index 6bf250c..43c5c1a 100644 --- a/core/modules/block_content/src/Tests/BlockContentCreationTest.php +++ b/core/modules/block_content/src/Tests/BlockContentCreationTest.php @@ -100,6 +100,10 @@ public function testBlockContentCreationMultipleViewModes() { '%name' => $edit['info[0][value]'] )), 'Basic block created.'); + $blocks = entity_load_multiple_by_properties('block_content', ['info' => $edit['info[0][value]']]); + $block = reset($blocks); + $this->drupalGet('admin/structure/block/add/block_content:' . $block->uuid() . '/classy'); + // Check that the view mode setting is shown because more than one exists. $this->assertFieldByXPath('//select[@name="settings[view_mode]"]', NULL, 'View mode setting shown because multiple exist'); diff --git a/core/modules/block_content/src/Tests/BlockContentTypeTest.php b/core/modules/block_content/src/Tests/BlockContentTypeTest.php index 08c92e7..d7c0723 100644 --- a/core/modules/block_content/src/Tests/BlockContentTypeTest.php +++ b/core/modules/block_content/src/Tests/BlockContentTypeTest.php @@ -156,80 +156,4 @@ public function testBlockContentTypeDeletion() { $this->assertText(t('This action cannot be undone.'), 'The custom block type deletion confirmation form is available.'); } - /** - * Tests that redirects work as expected when multiple block types exist. - */ - public function testsBlockContentAddTypes() { - // Now create an initial block-type. - $this->createBlockContentType('basic', TRUE); - - $this->drupalLogin($this->adminUser); - // Create two block types programmatically. - $type = $this->createBlockContentType('foo'); - $type = $this->createBlockContentType('bar'); - - // Get the custom block storage. - $storage = $this->container - ->get('entity.manager') - ->getStorage('block_content'); - - // Install all themes. - \Drupal::service('theme_handler')->install(array('bartik', 'seven')); - $themes = array('bartik', 'seven', 'classy'); - $theme_settings = $this->config('system.theme'); - foreach ($themes as $default_theme) { - // Change the default theme. - $theme_settings->set('default', $default_theme)->save(); - \Drupal::service('router.builder')->rebuild(); - - // For each installed theme, go to its block page and test the redirects. - $themes = array('bartik', 'classy', 'seven'); - foreach ($themes as $theme) { - // Test that adding a block from the 'place blocks' form sends you to the - // block configure form. - $path = $theme == $default_theme ? 'admin/structure/block' : "admin/structure/block/list/$theme"; - $this->drupalGet($path); - $this->clickLinkPartialName('Place block'); - $this->clickLink(t('Add custom block')); - // The seven theme has markup inside the link, we cannot use clickLink(). - if ($default_theme == 'seven') { - $options = $theme != $default_theme ? array('query' => array('theme' => $theme)) : array(); - $this->assertLinkByHref(\Drupal::url('block_content.add_form', array('block_content_type' => 'foo'), $options)); - $this->drupalGet('block/add/foo', $options); - } - else { - $this->clickLink('foo'); - } - // Create a new block. - $edit = array('info[0][value]' => $this->randomMachineName(8)); - $this->drupalPostForm(NULL, $edit, t('Save')); - $blocks = $storage->loadByProperties(array('info' => $edit['info[0][value]'])); - if (!empty($blocks)) { - $block = reset($blocks); - $this->assertUrl(\Drupal::url('block.admin_add', array('plugin_id' => 'block_content:' . $block->uuid(), 'theme' => $theme), array('absolute' => TRUE))); - $this->drupalPostForm(NULL, array(), t('Save block')); - $this->assertUrl(\Drupal::url('block.admin_display_theme', array('theme' => $theme), array('absolute' => TRUE, 'query' => array('block-placement' => Html::getClass($edit['info[0][value]']))))); - } - else { - $this->fail('Could not load created block.'); - } - } - } - - // Test that adding a block from the 'custom blocks list' doesn't send you - // to the block configure form. - $this->drupalGet('admin/content/block-content'); - $this->clickLink(t('Add custom block')); - $this->clickLink('foo'); - $edit = array('info[0][value]' => $this->randomMachineName(8)); - $this->drupalPostForm(NULL, $edit, t('Save')); - $blocks = $storage->loadByProperties(array('info' => $edit['info[0][value]'])); - if (!empty($blocks)) { - $this->assertUrl(\Drupal::url('entity.block_content.collection', array(), array('absolute' => TRUE))); - } - else { - $this->fail('Could not load created block.'); - } - } - }