diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module index 1bcf414..6d21b73 100644 --- a/core/modules/block/custom_block/custom_block.module +++ b/core/modules/block/custom_block/custom_block.module @@ -77,13 +77,9 @@ function custom_block_menu() { 'route_name' => 'custom_block_add_page', ); $items['block/add/%custom_block_type'] = array( - 'title callback' => 'entity_page_label', - 'title arguments' => array(2), - 'page callback' => 'custom_block_add', - 'page arguments' => array(2), - 'access arguments' => array('administer blocks'), + 'title' => 'Add custom block', 'description' => 'Add custom block', - 'file' => 'custom_block.pages.inc', + 'route_name' => 'custom_block_add_form' ); // There has to be a base-item in order for contextual links to work. $items['block/%custom_block'] = array( diff --git a/core/modules/block/custom_block/custom_block.pages.inc b/core/modules/block/custom_block/custom_block.pages.inc index 9c802c4..7b7d4b4 100644 --- a/core/modules/block/custom_block/custom_block.pages.inc +++ b/core/modules/block/custom_block/custom_block.pages.inc @@ -35,36 +35,6 @@ function theme_custom_block_add_list($variables) { return $output; } - -/** - * Page callback: Presents the custom block creation form. - * - * @param Drupal\custom_block\Plugin\Core\Entity\CustomBlockType $block_type - * The custom block type to add. - * - * @return array - * A form array as expected by drupal_render(). - * - * @see custom_block_menu() - */ -function custom_block_add(CustomBlockType $block_type) { - drupal_set_title(t('Add %type custom block', array( - '%type' => $block_type->label() - )), PASS_THROUGH); - $block = entity_create('custom_block', array( - 'type' => $block_type->id() - )); - $options = array(); - $request = drupal_container()->get('request'); - if (($theme = $request->attributes->get('theme')) && in_array($theme, array_keys(list_themes()))) { - // We have navigated to this page from the block library and will keep track - // of the theme for redirecting the user to the configuration page for the - // newly created block in the given theme. - $block->setTheme($theme); - } - return entity_get_form($block); -} - /** * Page callback: Presents the custom block edit form. * diff --git a/core/modules/block/custom_block/custom_block.routing.yml b/core/modules/block/custom_block/custom_block.routing.yml index ed4ab92..76e104c 100644 --- a/core/modules/block/custom_block/custom_block.routing.yml +++ b/core/modules/block/custom_block/custom_block.routing.yml @@ -4,3 +4,9 @@ custom_block_add_page: _content: 'Drupal\custom_block\Controller\CustomBlockController::add' requirements: _permission: 'administer blocks' +custom_block_add_form: + pattern: block/add/{custom_block_type} + defaults: + _content: 'Drupal\custom_block\Controller\CustomBlockController::addForm' + requirements: + _permission: 'administer blocks' diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Controller/CustomBlockController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Controller/CustomBlockController.php index 783ef84..4264100 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Controller/CustomBlockController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Controller/CustomBlockController.php @@ -9,7 +9,7 @@ use Drupal\Core\ControllerInterface; use Drupal\Core\Entity\EntityManager; -use Drupal\Core\Extension\ModuleHandler; +use Drupal\custom_block\Plugin\Core\Entity\CustomBlockType; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -30,20 +30,12 @@ class CustomBlockController implements ControllerInterface { protected $entityManager; /** - * Module handler service. - * - * @var \Drupal\Core\Extension\ModuleHandler - */ - protected $moduleHandler; - - /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( $container->get('request'), - $container->get('plugin.manager.entity'), - $container->get('module_handler') + $container->get('plugin.manager.entity') ); } @@ -54,13 +46,10 @@ public static function create(ContainerInterface $container) { * Current request. * @param \Drupal\Core\Entity\EntityManager $entity_manager * Entity manager service. - * @param \Drupal\Core\Extension\ModuleHandler $module_handler - * Module Handler service. */ - public function __construct(Request $request, EntityManager $entity_manager, ModuleHandler $module_handler) { + public function __construct(Request $request, EntityManager $entity_manager) { $this->request = $request; $this->entityManager = $entity_manager; - $this->moduleHandler = $module_handler; } /** @@ -84,13 +73,36 @@ public function add() { $types = $this->entityManager->getStorageController('custom_block_type')->load(); if ($types && count($types) == 1) { $type = reset($types); - // @todo convert this to OO once block/add/%type uses a Controller. Will - // be fixed in http://drupal.org/node/1978166. - $this->moduleHandler->loadInclude('custom_block', 'pages.inc'); - return custom_block_add($type); + return $this->addForm($type); } return array('#theme' => 'custom_block_add_list', '#content' => $types); } + /** + * Presents the custom block creation form. + * + * @param Drupal\custom_block\Plugin\Core\Entity\CustomBlockType $custom_block_type + * The custom block type to add. + * + * @return array + * A form array as expected by drupal_render(). + */ + public function addForm(CustomBlockType $custom_block_type) { + // @todo Remove this when https://drupal.org/node/1981644 is in. + drupal_set_title(t('Add %type custom block', array( + '%type' => $custom_block_type->label() + )), PASS_THROUGH); + $block = $this->entityManager->getStorageController('custom_block')->create(array( + 'type' => $custom_block_type->id() + )); + $options = array(); + if (($theme = $this->request->attributes->get('theme')) && in_array($theme, array_keys(list_themes()))) { + // We have navigated to this page from the block library and will keep track + // of the theme for redirecting the user to the configuration page for the + // newly created block in the given theme. + $block->setTheme($theme); + } + return entity_get_form($block); + } }