diff --git a/core/modules/block/block.module b/core/modules/block/block.module index 8eeb57f..f865060 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -142,11 +142,6 @@ function block_menu() { 'type' => $key == $default_theme ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK, 'route_name' => "block_admin_display.$key", ); - $items["admin/structure/block/list/$key/add"] = array( - 'title' => 'Place blocks', - 'type' => MENU_LOCAL_ACTION, - 'route_name' => "block_plugin_ui.$key", - ); $items["admin/structure/block/demo/$key"] = array( 'title' => check_plain($theme->info['name']), 'page callback' => 'block_admin_demo', diff --git a/core/modules/block/css/block.admin.css b/core/modules/block/css/block.admin.css index 831ad44..40c7a04 100644 --- a/core/modules/block/css/block.admin.css +++ b/core/modules/block/css/block.admin.css @@ -31,3 +31,20 @@ a.block-demo-backlink:visited { a.block-demo-backlink:hover { text-decoration: underline; } + +.block-list-region { + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; +} +.block-list-left { + float: left; + width: 65%; + padding-right: 2em; +} +.block-list-right { + float: right; + width: 35%; + background-color: #f7f7f7; + border-left: 1px solid #bfbfbf; +} diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module index 2752ee8..985a977 100644 --- a/core/modules/block/custom_block/custom_block.module +++ b/core/modules/block/custom_block/custom_block.module @@ -16,7 +16,7 @@ function custom_block_menu_local_tasks(&$data, $router_item, $root_path) { // listing page. // @todo This should just be $root_path == 'admin/structure/block/list/%/add' // but block_menu() registers static router paths instead of dynamic ones. - if (preg_match('@^admin/structure/block/list/(.*)/add$@', $root_path)) { + if ($root_path == 'admin/structure/block' || preg_match('@^admin/structure/block/list/(.*)$@', $root_path)) { $item = menu_get_item('block/add'); if ($item['access']) { $data['actions']['block/add'] = array( @@ -93,21 +93,6 @@ 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) { @@ -221,27 +206,6 @@ function custom_block_add_body_field($block_type_id, $label = 'Block body') { } /** - * Implements hook_form_FORM_ID_alter() for block_plugin_ui(). - */ -function custom_block_form_block_plugin_ui_alter(&$form, $form_state) { - foreach ($form['left']['plugin_library']['#rows'] as $plugin_id => &$row) { - // @todo Clean up when http://drupal.org/node/1874498 lands. - if (strpos($plugin_id, ':') === FALSE) { - continue; - } - list($base, $derivative) = explode(':', $plugin_id); - if ($base !== 'custom_block') { - continue; - } - $custom_block = entity_load_by_uuid('custom_block', $derivative); - $row['1']['data']['#links']['edit'] = array( - 'title' => t('Edit'), - 'href' => 'block/' . $custom_block->id(), - ); - } -} - -/** * Implements hook_admin_paths(). */ function custom_block_admin_paths() { diff --git a/core/modules/block/lib/Drupal/block/BlockListController.php b/core/modules/block/lib/Drupal/block/BlockListController.php index 9ba757b..57d93d4 100644 --- a/core/modules/block/lib/Drupal/block/BlockListController.php +++ b/core/modules/block/lib/Drupal/block/BlockListController.php @@ -81,8 +81,15 @@ public function buildForm(array $form, array &$form_state) { // Add a last region for disabled blocks. $block_regions_with_disabled = $this->regions + array(BLOCK_REGION_NONE => BLOCK_REGION_NONE); + $form['left']['#type'] = 'container'; + $form['left']['#attributes'] = array( + 'class' => array( + 'block-list-region', + 'block-list-left', + ), + ); - $form['block_regions'] = array( + $form['left']['block_regions'] = array( '#type' => 'value', '#value' => $block_regions_with_disabled, ); @@ -93,11 +100,11 @@ public function buildForm(array $form, array &$form_state) { $weight_delta = round(count($entities) / 2); // Build the form tree. - $form['edited_theme'] = array( + $form['left']['edited_theme'] = array( '#type' => 'value', '#value' => $this->theme, ); - $form['blocks'] = array( + $form['left']['blocks'] = array( '#type' => 'table', '#header' => array( t('Block'), @@ -123,7 +130,7 @@ public function buildForm(array $form, array &$form_state) { // Loop over each region and build blocks. foreach ($block_regions_with_disabled as $region => $title) { - $form['blocks']['#tabledrag'][] = array( + $form['left']['blocks']['#tabledrag'][] = array( 'match', 'sibling', 'block-region-select', @@ -131,27 +138,27 @@ public function buildForm(array $form, array &$form_state) { NULL, FALSE, ); - $form['blocks']['#tabledrag'][] = array( + $form['left']['blocks']['#tabledrag'][] = array( 'order', 'sibling', 'block-weight', 'block-weight-' . $region, ); - $form['blocks'][$region] = array( + $form['left']['blocks'][$region] = array( '#attributes' => array( 'class' => array('region-title', 'region-title-' . $region, 'odd'), 'no_striping' => TRUE, ), ); - $form['blocks'][$region]['title'] = array( + $form['left']['blocks'][$region]['title'] = array( '#markup' => $region != BLOCK_REGION_NONE ? $title : t('Disabled'), '#wrapper_attributes' => array( 'colspan' => 5, ), ); - $form['blocks'][$region . '-message'] = array( + $form['left']['blocks'][$region . '-message'] = array( '#attributes' => array( 'class' => array( 'region-message', @@ -160,7 +167,7 @@ public function buildForm(array $form, array &$form_state) { ), ), ); - $form['blocks'][$region . '-message']['message'] = array( + $form['left']['blocks'][$region . '-message']['message'] = array( '#markup' => '' . t('No blocks in this region') . '', '#wrapper_attributes' => array( 'colspan' => 5, @@ -171,19 +178,19 @@ public function buildForm(array $form, array &$form_state) { foreach ($blocks[$region] as $info) { $entity_id = $info['entity_id']; - $form['blocks'][$entity_id] = array( + $form['left']['blocks'][$entity_id] = array( '#attributes' => array( 'class' => array('draggable'), ), ); - $form['blocks'][$entity_id]['info'] = array( + $form['left']['blocks'][$entity_id]['info'] = array( '#markup' => check_plain($info['admin_label']), '#wrapper_attributes' => array( 'class' => array('block'), ), ); - $form['blocks'][$entity_id]['region-theme']['region'] = array( + $form['left']['blocks'][$entity_id]['region-theme']['region'] = array( '#type' => 'select', '#default_value' => $region, '#empty_value' => BLOCK_REGION_NONE, @@ -195,12 +202,12 @@ public function buildForm(array $form, array &$form_state) { ), '#parents' => array('blocks', $entity_id, 'region'), ); - $form['blocks'][$entity_id]['region-theme']['theme'] = array( + $form['left']['blocks'][$entity_id]['region-theme']['theme'] = array( '#type' => 'hidden', '#value' => $this->theme, '#parents' => array('blocks', $entity_id, 'theme'), ); - $form['blocks'][$entity_id]['weight'] = array( + $form['left']['blocks'][$entity_id]['weight'] = array( '#type' => 'weight', '#default_value' => $info['weight'], '#delta' => $weight_delta, @@ -210,29 +217,91 @@ public function buildForm(array $form, array &$form_state) { 'class' => array('block-weight', 'block-weight-' . $region), ), ); - $form['blocks'][$entity_id]['operations'] = $this->buildOperations($info['entity']); + $form['left']['blocks'][$entity_id]['operations'] = $this->buildOperations($info['entity']); } } } // Do not allow disabling the main system content block when it is present. - if (isset($form['blocks']['system_main']['region'])) { - $form['blocks']['system_main']['region']['#required'] = TRUE; + if (isset($form['left']['blocks']['system_main']['region'])) { + $form['left']['blocks']['system_main']['region']['#required'] = TRUE; } - $form['actions'] = array( + $form['left']['actions'] = array( '#tree' => FALSE, '#type' => 'actions', ); - $form['actions']['submit'] = array( + $form['left']['actions']['submit'] = array( '#type' => 'submit', '#value' => t('Save blocks'), '#button_type' => 'primary', ); + + $form['right']['#type'] = 'container'; + $form['right']['#attributes'] = array( + 'class' => array( + 'block-list-region', + 'block-list-right', + ), + ); + $form['right']['candidate_list'] = $this->getCandidateList(); return $form; } /** + * @todo. + * + * @return array + */ + protected function getCandidateList() { + $list['#type'] = 'container'; + $list['#attributes']['class'][] = 'entity-meta'; + + $list['title']['#type'] = 'container'; + $list['title']['#attributes']['class'][] = 'entity-meta-header'; + $list['title']['#children'] = '

' . t('Place blocks') . '

'; + + $plugins = \Drupal::service('plugin.manager.block')->getDefinitions(); + uasort($plugins, function ($a, $b) { + if ($a['category'] != $b['category']) { + return strnatcasecmp($a['category'], $b['category']); + } + return strnatcasecmp($a['admin_label'], $b['admin_label']); + }); + foreach ($plugins as $plugin_id => $plugin_definition) { + $category = $plugin_definition['category']; + if (!isset($list[$category])) { + $list[$category] = array( + '#type' => 'details', + '#title' => $category, + '#collapsed' => TRUE, + 'content' => array( + '#theme' => 'links', + '#links' => array(), + '#attributes' => array( + 'class' => array( + 'menu', + ), + ), + ), + ); + } + $list[$category]['content']['#links'][$plugin_id] = array( + 'title' => $plugin_definition['admin_label'], + 'href' => 'admin/structure/block/add/' . $plugin_id . '/' . $this->theme, + 'attributes' => array( + 'class' => array('use-ajax'), + 'data-accepts' => 'application/vnd.drupal-modal', + 'data-dialog-options' => json_encode(array( + 'width' => 700 + )), + ), + ); + } + return $list; + } + + /** * {@inheritdoc} */ public function getOperations(EntityInterface $entity) { diff --git a/core/modules/block/lib/Drupal/block/Form/PlaceBlocksForm.php b/core/modules/block/lib/Drupal/block/Form/PlaceBlocksForm.php deleted file mode 100644 index ffc4b9e..0000000 --- a/core/modules/block/lib/Drupal/block/Form/PlaceBlocksForm.php +++ /dev/null @@ -1,157 +0,0 @@ -manager = $manager; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('plugin.manager.block') - ); - } - - /** - * {@inheritdoc} - */ - public function getFormID() { - return 'block_plugin_ui'; - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, array &$form_state, $theme = NULL, $category = NULL) { - $this->theme = $theme; - $form['#theme'] = 'system_plugin_ui_form'; - $rows = array(); - $categories = array(); - foreach ($this->manager->getDefinitions() as $plugin_id => $plugin_definition) { - if (empty($category) || $plugin_definition['category'] == $category) { - $rows[$plugin_id] = $this->row($plugin_id, $plugin_definition); - } - $categories[$plugin_definition['category']] = array( - 'title' => $plugin_definition['category'], - 'href' => 'admin/structure/block/list/' . $this->theme . '/add/' . $plugin_definition['category'], - ); - } - - $form['right']['block'] = array( - '#type' => 'textfield', - '#title' => t('Search'), - '#autocomplete_path' => 'block/autocomplete', - ); - $form['right']['submit'] = array( - '#type' => 'submit', - '#button_type' => 'primary', - '#value' => t('Next'), - ); - $form['right']['all_plugins'] = array( - '#type' => 'link', - '#title' => t('All blocks'), - '#href' => 'admin/structure/block/list/' . $this->theme . '/add', - ); - if (!empty($categories)) { - $form['right']['categories'] = array( - '#theme' => 'links', - '#heading' => array( - 'text' => t('Categories'), - 'level' => 'h3', - ), - '#links' => $categories, - ); - } - - // Sort rows alphabetically. - asort($rows); - $form['left']['plugin_library'] = array( - '#theme' => 'table', - '#header' => array(t('Subject'), t('Operations')), - '#rows' => $rows, - ); - return $form; - } - - /** - * Generates the row data for a single block plugin. - * - * @param string $plugin_id - * The plugin ID. - * @param array $plugin_definition - * The plugin definition. - * - * @return array - * The row data for a single block plugin. - */ - protected function row($plugin_id, array $plugin_definition) { - $row = array(); - $row[] = String::checkPlain($plugin_definition['admin_label']); - $row[] = array('data' => array( - '#type' => 'operations', - '#links' => array( - 'configure' => array( - 'title' => t('Place block'), - 'href' => 'admin/structure/block/add/' . $plugin_id . '/' . $this->theme, - ), - ), - )); - return $row; - } - - /** - * {@inheritdoc} - */ - public function validateForm(array &$form, array &$form_state) { - if (!$this->manager->getDefinition($form_state['values']['block'])) { - form_set_error('block', t('You must select a valid block.')); - } - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, array &$form_state) { - $form_state['redirect'] = 'admin/structure/block/add/' . $form_state['values']['block'] . '/' . $this->theme; - } - -} diff --git a/core/modules/block/lib/Drupal/block/Routing/RouteSubscriber.php b/core/modules/block/lib/Drupal/block/Routing/RouteSubscriber.php index de32cd1..576ea80 100644 --- a/core/modules/block/lib/Drupal/block/Routing/RouteSubscriber.php +++ b/core/modules/block/lib/Drupal/block/Routing/RouteSubscriber.php @@ -50,18 +50,6 @@ public function routes(RouteBuildEvent $event) { ) ); $collection->add("block_admin_display.$key", $route); - - // The block plugin listing page. - $route = new Route( - "admin/structure/block/list/$key/add/{category}", - array( - '_form' => '\Drupal\block\Form\PlaceBlocksForm', - 'category' => NULL, - 'theme' => $key, - ), - array('_block_themes_access' => 'TRUE') - ); - $collection->add("block_plugin_ui.$key", $route); } } diff --git a/core/modules/system/css/system.plugin.ui.css b/core/modules/system/css/system.plugin.ui.css deleted file mode 100644 index c932788..0000000 --- a/core/modules/system/css/system.plugin.ui.css +++ /dev/null @@ -1,29 +0,0 @@ -#block-library .left-col, -#block-library .right-col { - float:left; - width:66%; - height:100%; - background-color:#ffffff; -} - -#block-library .right-col { - width:34%; - background-color:#f7f7f7; -} - -#block-library .right-col h3 { - margin: 1em -20px; - background-color:#d7d7d7; - color:#333333; - padding:8px 15px; - font-size:1.1em; -} - -#block-library .inside { - margin:0 20px; -} - -#block-library .bottom-bar { - width:100%; - clear:both; -} diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 1935f5c..7756051 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -190,10 +190,6 @@ function system_theme() { 'system_date_format_localize_form' => array( 'render element' => 'form', ), - 'system_plugin_ui_form' => array( - 'template' => 'system-plugin-ui-form', - 'render element' => 'form', - ), )); } @@ -2350,19 +2346,6 @@ function system_preprocess_block(&$variables) { } /** - * Prepares variables for system plugin UI form templates. - * - * Default template: system-plugin-ui-form.html.twig. - * - * @param array $variables - * An associative array containing: - * - form: The plugin form elements. -*/ -function template_preprocess_system_plugin_ui_form(&$variables) { - drupal_add_css(drupal_get_path('module', 'system') . '/css/system.plugin.ui.css'); -} - -/** * Provide a single block on the administration overview page. * * @param $item diff --git a/core/modules/system/templates/system-plugin-ui-form.html.twig b/core/modules/system/templates/system-plugin-ui-form.html.twig deleted file mode 100644 index 5987888..0000000 --- a/core/modules/system/templates/system-plugin-ui-form.html.twig +++ /dev/null @@ -1,30 +0,0 @@ -{# -/** - * @file - * Default theme implementation to configure blocks. - * - * Available variables: - * - form: The form elements which contains: - * - left: Form elements that appear in the left column. - * - right: Form elements that appear in the right column. - * - * @see template_preprocess_system_plugin_ui_form() - * - * @ingroup themeable - */ -#} -
-
-
- {{ form.left }} -
-
-
-
- {{ form.right }} -
-
- {% if form -%} -
{{ form }}
- {%- endif -%} -