commit afbe97ddb595050647cecdc9569c87ee031b3800 Author: Lee Rowlands Date: Mon Aug 12 06:48:04 2013 +1000 Patch 21 diff --git a/core/modules/block/block.module b/core/modules/block/block.module index 5be7c27..75cf58c 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -59,10 +59,6 @@ function block_help($path, $arg) { $output .= '
' . t('When working with blocks, remember that all themes do not implement the same regions, or display regions in the same way. Blocks are positioned on a per-theme basis. Users with the Administer blocks permission can disable blocks. Disabled blocks are listed on the Blocks administration page, but are not displayed in any region.', array('@block' => 'http://drupal.org/documentation/modules/block', '@blocks' => url('admin/structure/block'))) . '
'; $output .= '
' . t('Controlling visibility') . '
'; $output .= '
' . t('Blocks can be configured to be visible only on certain pages, only to users of certain roles, or only on pages displaying certain content types. Some dynamic blocks, such as those generated by modules, will be displayed only on certain pages.', array('@content-type' => url('admin/structure/types'), '@user' => url('user'))) . '
'; - if (module_exists('custom_block')) { - $output .= '
' . t('Creating custom blocks') . '
'; - $output .= '
' . t('Users with the Administer blocks permission can add custom blocks, which are then listed on the Blocks administration page. Once created, custom blocks behave just like default and module-generated blocks.', array('@blocks' => url('admin/structure/block'), '@block-add' => url('admin/structure/block/list/' . config('system.theme')->get('default') . '/add/custom_blocks'))) . '
'; - } $output .= ''; return $output; } diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module index 555f2d1..4b3dad973 100644 --- a/core/modules/block/custom_block/custom_block.module +++ b/core/modules/block/custom_block/custom_block.module @@ -8,6 +8,37 @@ use Drupal\custom_block\Plugin\Core\Entity\CustomBlockType; use Drupal\custom_block\Plugin\Core\Entity\CustomBlock; + +/** + * Implements hook_help(). + */ +function custom_block_help($path, $arg) { + switch ($path) { + case 'admin/help#custom_block': + $output = ''; + $output .= '

' . t('About') . '

'; + $output .= '

' . t('The Custom Block module allows you to create boxes of content, which can be placed in regions throughout the website. The Custom Blocks administration page lets you view the custom block content on your site.', array('@blocks' => url('admin/structure/custom-blocks'))) . '

'; + $output .= '

' . t('Uses') . '

'; + $output .= '
'; + $output .= '
' . t('Creating custom block types') . '
'; + $output .= '
' . t('You can create different custom block types, each with different fields and display settings from the Custom block types administration pages.', array('@types' => url('admin/structure/custom-blocks/types'))) . '
'; + $output .= '
' . t('Creating custom blocks') . '
'; + $output .= '
' . t('Users with the Administer blocks permission can add custom blocks, which are then listed on the Blocks administration page. Once created, custom blocks behave just like default and module-generated blocks.', array('@blocks' => url('admin/structure/block'), '@block-add' => url('admin/structure/block/list/' . config('system.theme')->get('default') . '/add/custom_blocks'))) . '
'; + $output .= '
'; + return $output; + + case 'admin/structure/custom-blocks': + case 'admin/structure/custom-blocks/list': + $output = '

This page provides a list of all custom-block content on your site. From here you can add, edit or delete custom block content.

'; + return $output; + + case 'admin/structure/custom-blocks/types': + $output = '

This page provides a list of all custom-block types on your site. Each custom-block type can consists of different fields and display settings. From here you can manage the fields on each custom-block type as well as create new custom-block types.

'; + return $output; + + } +} + /** * Implements hook_menu_local_tasks(). */ @@ -25,6 +56,19 @@ function custom_block_menu_local_tasks(&$data, $router_item, $root_path) { ); } } + if ($router_item['route_name'] == 'custom_block_list') { + // @todo Move to a LocalAction plugin when https://drupal.org/node/2045267 + // allows local actions to work with query strings. + $item = menu_get_item('block/add'); + if ($item['access']) { + // Add a destination parameter. + $item['localized_options']['query']['destination'] = 'admin/structure/custom-blocks'; + $data['actions']['block/add/o'] = array( + '#theme' => 'menu_local_action', + '#link' => $item, + ); + } + } } /** diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php index fda13cd..20d748d 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php @@ -182,7 +182,17 @@ public function save(array $form, array &$form_state) { if ($block->id->value) { $form_state['values']['id'] = $block->id->value; $form_state['id'] = $block->id->value; - $form_state['redirect'] = 'admin/structure/custom-blocks'; + if ($insert) { + if ($theme = $block->getTheme()) { + $form_state['redirect'] = 'admin/structure/block/add/custom_block:' . $block->uuid->value . '/' . $theme; + } + else { + $form_state['redirect'] = 'admin/structure/block/add/custom_block:' . $block->uuid->value . '/' . config('system.theme')->get('default'); + } + } + else { + $form_state['redirect'] = 'admin/structure/custom-blocks'; + } } else { // In the unlikely case something went wrong on save, the block will be diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockListController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockListController.php index 8bf08f6..d4b37da 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockListController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockListController.php @@ -42,9 +42,20 @@ public function getOperations(EntityInterface $entity) { if (isset($operations['edit'])) { $uri = $entity->uri(); $operations['edit']['href'] = $uri['path']; - + $operations['edit']['query']['destination'] = 'admin/structure/custom-blocks'; } return $operations; } + /** + * {@inheritdoc} + */ + public function render() { + $build = parent::render(); + // Override the default 'There is no Custom Block yet' to 'There are no + // Custom Blocks yet'. + $build['#empty'] = t('There are no @labels yet.', array('@label' => $this->entityInfo['label'])); + return $build; + } + } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Menu/LocalAction/CustomBlockAdd.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Menu/LocalAction/CustomBlockAdd.php deleted file mode 100644 index cfd307f..0000000 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Menu/LocalAction/CustomBlockAdd.php +++ /dev/null @@ -1,24 +0,0 @@ -assertFieldByXpath('//td', 'Antelope', "Label found for added block."); - // Check the number of table row cells. $elements = $this->xpath('//div[@class="l-content"]//table/tbody/tr[@class="odd"]/td'); $this->assertEqual(count($elements), 2, 'Correct number of table row cells found.'); @@ -78,25 +77,34 @@ public function testListing() { // the second contains the machine name, and the third contains the // operations list. $this->assertIdentical((string) $elements[0], 'Antelope'); - //$this->assertTrue($elements[1]->children()->xpath('//ul'), 'Operations list found.'); // Edit the entity using the operations link. - $this->assertLinkByHref('block/1'); - $this->clickLink('Edit'); - $this->assertResponse(200); - $this->assertTitle('Edit custom block Antelope | Drupal'); - $edit = array('info' => 'Albatross'); - $this->drupalPost(NULL, $edit, t('Save')); + $blocks = $this->container + ->get('plugin.manager.entity') + ->getStorageController('custom_block') + ->loadByProperties(array('info' => 'Antelope')); + $block = reset($blocks); + if (!empty($block)) { + $this->assertLinkByHref('block/' . $block->id()); + $this->clickLink('Edit'); + $this->assertResponse(200); + $this->assertTitle(t('Edit custom block Antelope | Drupal')); + $edit = array('info' => 'Albatross'); + $this->drupalPost(NULL, $edit, t('Save')); + } + else { + $this->fail('Did not find Albatross block in the database.'); + } // Confirm that once the user returns to the listing, the text of the label // (versus elsewhere on the page). $this->assertFieldByXpath('//td', 'Albatross', "Label found for updated 'Albatross' entity."); // Delete the added entity using the operations link. - $this->assertLinkByHref('block/1/delete'); + $this->assertLinkByHref('block/' . $block->id() . '/delete'); $this->clickLink('Delete'); $this->assertResponse(200); - $this->assertTitle('Are you sure you want to delete Albatross? | Drupal'); + $this->assertTitle(t('Are you sure you want to delete Albatross? | Drupal')); $this->drupalPost(NULL, array(), t('Delete')); // Verify that the text of the label and machine name does not appear in @@ -104,7 +112,7 @@ public function testListing() { $this->assertNoFieldByXpath('//td', 'Albatross', "No label found for deleted 'Albatross' entity."); // Confirm that the empty text is displayed. - $this->assertText('There is no Custom Block yet.'); + $this->assertText(t('There are no Custom Blocks yet.')); } }