diff --git a/core/modules/block/custom_block/custom_block.admin.inc b/core/modules/block/custom_block/custom_block.admin.inc deleted file mode 100644 index 8cb5c8c..0000000 --- a/core/modules/block/custom_block/custom_block.admin.inc +++ /dev/null @@ -1,36 +0,0 @@ -getForm($block_type); -} - -/** - * Page callback: Presents the custom block type edit form. - * - * @param \Drupal\custom_block\Plugin\Core\Entity\CustomBlockType $block_type - * The custom block type to edit. - * - * @return array - * A form array as expected by drupal_render(). - * - * @see custom_block_menu() - */ -function custom_block_type_edit(CustomBlockType $block_type) { - return Drupal::entityManager()->getForm($block_type); -} diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module index 4e55a85..2752ee8 100644 --- a/core/modules/block/custom_block/custom_block.module +++ b/core/modules/block/custom_block/custom_block.module @@ -37,21 +37,15 @@ function custom_block_menu() { 'route_name' => 'custom_block_type_list', ); $items['admin/structure/custom-blocks/add'] = array( - 'title' => 'Add custom block type', - 'page callback' => 'custom_block_type_add', - 'access arguments' => array('administer blocks'), - 'type' => MENU_LOCAL_ACTION, + 'route_name' => 'custom_block_type_add', + 'type' => MENU_SIBLING_LOCAL_TASK, 'weight' => 1, - 'file' => 'custom_block.admin.inc', ); $items['admin/structure/custom-blocks/manage/%custom_block_type'] = array( 'title' => 'Edit custom block type', 'title callback' => 'entity_page_label', 'title arguments' => array(4), - 'page callback' => 'custom_block_type_edit', - 'page arguments' => array(4), - 'access arguments' => array('administer blocks'), - 'file' => 'custom_block.admin.inc', + 'route_name' => 'custom_block_type_edit', ); $items['admin/structure/custom-blocks/manage/%custom_block_type/edit'] = array( 'title' => 'Edit', @@ -76,11 +70,7 @@ function custom_block_menu() { // There has to be a base-item in order for contextual links to work. $items['block/%custom_block'] = array( 'title' => 'Edit', - 'page callback' => 'custom_block_edit', - 'page arguments' => array(1), - 'access callback' => 'entity_page_access', - 'access arguments' => array(1, 'update'), - 'file' => 'custom_block.pages.inc', + 'route_name' => 'custom_block_edit', ); $items['block/%custom_block/edit'] = array( 'title' => 'Edit', @@ -103,6 +93,21 @@ function custom_block_menu() { } /** + * Implements hook_local_actions(). + */ +function custom_block_local_actions() { + return array( + array( + 'route_name' => 'custom_block_type_add', + 'title' => t('Add custom block type'), + 'appears_on' => array( + 'custom_block_type_list', + ), + ), + ); +} + +/** * Implements hook_theme(). */ function custom_block_theme($existing, $type, $theme, $path) { @@ -231,7 +236,7 @@ function custom_block_form_block_plugin_ui_alter(&$form, $form_state) { $custom_block = entity_load_by_uuid('custom_block', $derivative); $row['1']['data']['#links']['edit'] = array( 'title' => t('Edit'), - 'href' => 'block/' . $custom_block->id() . '/edit' + 'href' => 'block/' . $custom_block->id(), ); } } diff --git a/core/modules/block/custom_block/custom_block.pages.inc b/core/modules/block/custom_block/custom_block.pages.inc index f6c4076..ae7de30 100644 --- a/core/modules/block/custom_block/custom_block.pages.inc +++ b/core/modules/block/custom_block/custom_block.pages.inc @@ -30,22 +30,6 @@ function template_preprocess_custom_block_add_list(&$variables) { } /** - * Page callback: Presents the custom block edit form. - * - * @param Drupal\custom_block\Plugin\Core\Entity\CustomBlock $block - * The custom block to edit. - * - * @return array - * A form array as expected by drupal_render(). - * - * @see custom_block_menu() - */ -function custom_block_edit(CustomBlock $block) { - drupal_set_title(t('Edit custom block %label', array('%label' => $block->label())), PASS_THROUGH); - return Drupal::entityManager()->getForm($block); -} - -/** * Page callback: Form constructor for the custom block deletion form. * * @param Drupal\custom_block\Plugin\Core\Entity\CustomBlock $block diff --git a/core/modules/block/custom_block/custom_block.routing.yml b/core/modules/block/custom_block/custom_block.routing.yml index 2178d91..02bad13 100644 --- a/core/modules/block/custom_block/custom_block.routing.yml +++ b/core/modules/block/custom_block/custom_block.routing.yml @@ -6,7 +6,7 @@ custom_block_type_list: _permission: 'administer blocks' custom_block_add_page: - pattern: block/add + pattern: '/block/add' defaults: _content: 'Drupal\custom_block\Controller\CustomBlockController::add' requirements: @@ -24,4 +24,26 @@ custom_block_type_delete: defaults: _entity_form: 'custom_block_type.delete' requirements: + _entity_access: 'custom_block_type.delete' + +custom_block_edit: + pattern: '/block/{custom_block}' + defaults: + _entity_form: 'custom_block.edit' + requirements: + _entity_access: 'custom_block.update' + custom_block: \d+ + +custom_block_type_add: + pattern: '/admin/structure/custom-blocks/add' + defaults: + _entity_form: 'custom_block_type.add' + requirements: _permission: 'administer blocks' + +custom_block_type_edit: + pattern: '/admin/structure/custom-blocks/manage/{custom_block_type}' + defaults: + _entity_form: 'custom_block_type.edit' + requirements: + _entity_access: 'custom_block_type.update' 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 2f18d5b..9ccf371 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 @@ -41,6 +41,11 @@ protected function prepareEntity() { */ public function form(array $form, array &$form_state) { $block = $this->entity; + + if ($this->operation == 'edit') { + // @todo Remove this once https://drupal.org/node/1981644 is in. + drupal_set_title(t('Edit custom block %label', array('%label' => $block->label())), PASS_THROUGH); + } // Override the default CSS class name, since the user-defined custom block // type name in 'TYPE-block-form' potentially clashes with third-party class // names. diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeFormController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeFormController.php index cf88f5d..a98730e 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeFormController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeFormController.php @@ -21,6 +21,7 @@ public function form(array $form, array &$form_state) { $form = parent::form($form, $form_state); $block_type = $this->entity; + $form['label'] = array( '#type' => 'textfield', '#title' => t('Label'), diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlock.php index 74dfc25..6bc0f4d 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlock.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlock.php @@ -26,6 +26,8 @@ * "access" = "Drupal\custom_block\CustomBlockAccessController", * "render" = "Drupal\custom_block\CustomBlockRenderController", * "form" = { + * "add" = "Drupal\custom_block\CustomBlockFormController", + * "edit" = "Drupal\custom_block\CustomBlockFormController", * "default" = "Drupal\custom_block\CustomBlockFormController" * }, * "translation" = "Drupal\custom_block\CustomBlockTranslationController" @@ -34,6 +36,7 @@ * revision_table = "custom_block_revision", * route_base_path = "admin/structure/custom-blocks/manage/{bundle}", * menu_base_path = "block/%custom_block", + * menu_edit_path = "block/%custom_block", * fieldable = TRUE, * translatable = TRUE, * entity_keys = { diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlockType.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlockType.php index 0ceabd5..685e370 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlockType.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlockType.php @@ -25,6 +25,8 @@ * "access" = "Drupal\custom_block\CustomBlockTypeAccessController", * "form" = { * "default" = "Drupal\custom_block\CustomBlockTypeFormController", + * "add" = "Drupal\custom_block\CustomBlockTypeFormController", + * "edit" = "Drupal\custom_block\CustomBlockTypeFormController", * "delete" = "Drupal\custom_block\Form\CustomBlockTypeDeleteForm" * }, * "list" = "Drupal\custom_block\CustomBlockTypeListController" diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/PageEditTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/PageEditTest.php index e541c40..dab0eb6 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/PageEditTest.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/PageEditTest.php @@ -46,7 +46,7 @@ public function testPageEdit() { $this->assertTrue($block, 'Custom block found in database.'); // Load the edit page. - $this->drupalGet('block/' . $block->id() . '/edit'); + $this->drupalGet('block/' . $block->id()); $this->assertFieldByName($title_key, $edit[$title_key], 'Title field displayed.'); $this->assertFieldByName($body_key, $edit[$body_key], 'Body field displayed.'); @@ -58,7 +58,7 @@ public function testPageEdit() { $this->drupalPost(NULL, $edit, t('Save')); // Edit the same block, creating a new revision. - $this->drupalGet("block/" . $block->id() . "/edit"); + $this->drupalGet("block/" . $block->id()); $edit = array(); $edit['info'] = $this->randomName(8); $edit[$body_key] = $this->randomName(16); @@ -70,7 +70,7 @@ public function testPageEdit() { $this->assertNotIdentical($block->revision_id->value, $revised_block->revision_id->value, 'A new revision has been created.'); // Test deleting the block. - $this->drupalGet("block/" . $revised_block->id() . "/edit"); + $this->drupalGet("block/" . $revised_block->id()); $this->drupalPost(NULL, array(), t('Delete')); $this->assertText(format_string('Are you sure you want to delete !label?', array('!label' => $revised_block->label()))); }