diff --git a/core/modules/block/css/block.admin.css b/core/modules/block/css/block.admin.css index da2a7d3..59f1332 100644 --- a/core/modules/block/css/block.admin.css +++ b/core/modules/block/css/block.admin.css @@ -55,6 +55,9 @@ a.block-demo-backlink:hover { .block-list-secondary .form-type-search { padding: 0 1em; } +#block-placed { + background-color: #ffd; +} /* Wide screens */ @media diff --git a/core/modules/block/js/block.admin.js b/core/modules/block/js/block.admin.js index 93d9229..5c657d4 100644 --- a/core/modules/block/js/block.admin.js +++ b/core/modules/block/js/block.admin.js @@ -68,4 +68,22 @@ Drupal.behaviors.blockFilterByText = { } }; +/** + * Highlights the block that was just placed into the block listing. + */ +Drupal.behaviors.blockHighlightPlacement = { + attach: function (context, settings) { + if (settings.blockPlacement) { + $('#blocks').once('block-highlight', function () { + var $container = $(this); + // Just scrolling the document.body will not work in Firefox. The html + // element is needed as well. + $('html, body').animate({ + scrollTop: $('#block-placed').offset().top - $container.offset().top + $container.scrollTop() + }, 500); + }); + } + } +}; + }(jQuery, Drupal)); diff --git a/core/modules/block/lib/Drupal/block/BlockFormController.php b/core/modules/block/lib/Drupal/block/BlockFormController.php index c3812dc..e873888 100644 --- a/core/modules/block/lib/Drupal/block/BlockFormController.php +++ b/core/modules/block/lib/Drupal/block/BlockFormController.php @@ -293,7 +293,9 @@ public function submit(array $form, array &$form_state) { drupal_set_message($this->t('The block configuration has been saved.')); Cache::invalidateTags(array('content' => TRUE)); - $form_state['redirect'] = 'admin/structure/block/list/' . $entity->get('theme'); + $form_state['redirect'] = array('admin/structure/block/list/' . $entity->get('theme'), array( + 'query' => array('block-placement' => drupal_html_class($this->entity->id())), + )); } /** diff --git a/core/modules/block/lib/Drupal/block/BlockListController.php b/core/modules/block/lib/Drupal/block/BlockListController.php index 32735e5..f4e2a5e 100644 --- a/core/modules/block/lib/Drupal/block/BlockListController.php +++ b/core/modules/block/lib/Drupal/block/BlockListController.php @@ -16,6 +16,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\Request; /** * Defines the block list controller. @@ -37,6 +38,13 @@ class BlockListController extends ConfigEntityListController implements FormInte protected $theme; /** + * The current request. + * + * @var \Symfony\Component\HttpFoundation\Request + */ + protected $request; + + /** * The block manager. * * @var \Drupal\Component\Plugin\PluginManagerInterface @@ -98,8 +106,18 @@ public function load() { /** * Overrides \Drupal\Core\Entity\EntityListController::render(). + * + * @param string|null $theme + * (optional) The theme to display the blocks for. If NULL, the current + * theme will be used. + * @param \Symfony\Component\HttpFoundation\Request $request + * The current request. + * + * @return array + * The block list as a renderable array. */ - public function render($theme = NULL) { + public function render($theme = NULL, Request $request = NULL) { + $this->request = $request; // If no theme was specified, use the current theme. $this->theme = $theme ?: $GLOBALS['theme_key']; @@ -119,6 +137,14 @@ public function getFormID() { * Form constructor for the main block administration form. */ public function buildForm(array $form, array &$form_state) { + $placement = FALSE; + if ($this->request->query->has('block-placement')) { + $placement = $this->request->query->get('block-placement'); + $form['#attached']['js'][] = array( + 'type' => 'setting', + 'data' => array('blockPlacement' => $placement), + ); + } $entities = $this->load(); $form['#theme'] = array('block_list'); $form['#attached']['library'][] = array('system', 'drupal.tableheader'); @@ -222,6 +248,9 @@ public function buildForm(array $form, array &$form_state) { 'class' => array('draggable'), ), ); + if ($placement && $placement == drupal_html_class($entity_id)) { + $form['blocks'][$entity_id]['#attributes']['id'] = 'block-placed'; + } $form['blocks'][$entity_id]['info'] = array( '#markup' => check_plain($info['admin_label']), diff --git a/core/modules/block/lib/Drupal/block/Controller/BlockListController.php b/core/modules/block/lib/Drupal/block/Controller/BlockListController.php index f31e652..2852970 100644 --- a/core/modules/block/lib/Drupal/block/Controller/BlockListController.php +++ b/core/modules/block/lib/Drupal/block/Controller/BlockListController.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\Controller\EntityListController; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\Request; /** * Defines a controller to list blocks. @@ -20,13 +21,15 @@ class BlockListController extends EntityListController { * * @param string|null $theme * Theme key of block list. + * @param \Symfony\Component\HttpFoundation\Request $request + * The current request. * * @return array * A render array as expected by drupal_render(). */ - public function listing($theme = NULL) { + public function listing($theme = NULL, Request $request = NULL) { $theme = $theme ?: $this->config('system.theme')->get('default'); - return $this->entityManager()->getListController('block')->render($theme); + return $this->entityManager()->getListController('block')->render($theme, $request); } }