Commit dac7e246 authored by Dries's avatar Dries

Issue #2078951 by tim.plunkett, jessebeach: Highlight the row of block that was just placed.

parent 8e7a80ad
......@@ -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
......
......@@ -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));
......@@ -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())),
));
}
/**
......
......@@ -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.
......@@ -36,6 +37,13 @@ class BlockListController extends ConfigEntityListController implements FormInte
*/
protected $theme;
/**
* The current request.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
* The block manager.
*
......@@ -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']),
......
......@@ -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);
}
}
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