Commit c2e0cda7 authored by alexpott's avatar alexpott

Issue #1983682 by tim.plunkett, h3rj4n, larowlan: Convert applicable...

Issue #1983682 by tim.plunkett, h3rj4n, larowlan: Convert applicable custom_block_menu() entries to use _entity_form() in routing.yml.
parent c6157d8f
<?php
/**
* @file
* Admin page callbacks for the custom block module.
*/
use Drupal\custom_block\Plugin\Core\Entity\CustomBlockType;
/**
* Page callback: Presents the custom block type creation form.
*
* @return array
* A form array as expected by drupal_render().
*
* @see custom_block_menu()
*/
function custom_block_type_add() {
$block_type = entity_create('custom_block_type', array());
return Drupal::entityManager()->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);
}
......@@ -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',
......@@ -102,6 +92,21 @@ function custom_block_menu() {
return $items;
}
/**
* 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().
*/
......@@ -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(),
);
}
}
......
......@@ -29,22 +29,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.
*
......
......@@ -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:
......@@ -23,5 +23,27 @@ custom_block_type_delete:
pattern: '/admin/structure/custom-blocks/manage/{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'
......@@ -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.
......
......@@ -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'),
......
......@@ -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 = {
......
......@@ -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"
......
......@@ -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())));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment