diff --git a/core/modules/block_place/block_place.install b/core/modules/block_place/block_place.install index c51492f..ca9cdb6 100644 --- a/core/modules/block_place/block_place.install +++ b/core/modules/block_place/block_place.install @@ -22,4 +22,3 @@ function block_place_install() { // @todo Remove when that is fixed in https://www.drupal.org/node/2773591. \Drupal::service('cache.discovery')->deleteAll(); } - diff --git a/core/modules/block_place/block_place.module b/core/modules/block_place/block_place.module index e5a9ff1..04caeac 100644 --- a/core/modules/block_place/block_place.module +++ b/core/modules/block_place/block_place.module @@ -5,6 +5,7 @@ * Controls the placement of blocks from all pages. */ +use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; use Drupal\block\Entity\Block; @@ -97,10 +98,15 @@ function block_place_page_attachments(array &$attachments) { $query = \Drupal::request()->query; if ($region_sort = $query->get('block-place-region-sort')) { $attachments['#attached']['library'][] = 'block_place/drupal.block_place.js'; - $destination = \Drupal::destination()->get(); - $destination = explode('?', $destination)[0]; + + // Remove block-place-region-sort from the query string. + $destination_parts = UrlHelper::parse(\Drupal::destination()->get()); + unset($destination_parts['query']['block-place-region-sort']); + $destination = $destination_parts['path'] . ($destination_parts['query'] ? ('?' . UrlHelper::buildQuery($destination_parts['query'])) : ''); + $theme = \Drupal::theme()->getActiveTheme(); $url = Url::fromRoute('block_place.sort', ['region' => $region_sort, 'theme' => $theme->getName()], ['query' => ['destination' => $destination]]); + $attachments['#attached']['drupalSettings']['block_place'] = [ 'dialog_url' => $url->setAbsolute()->toString(), // @todo Always use 'off_canvas' in https://www.drupal.org/node/2784443. diff --git a/core/modules/block_place/src/Form/BlockRegionSorterForm.php b/core/modules/block_place/src/Form/BlockRegionSorterForm.php index af61c46..1623184 100644 --- a/core/modules/block_place/src/Form/BlockRegionSorterForm.php +++ b/core/modules/block_place/src/Form/BlockRegionSorterForm.php @@ -2,8 +2,7 @@ namespace Drupal\block_place\Form; -use Drupal\block\Entity\Block; -use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -14,20 +13,20 @@ class BlockRegionSorterForm extends FormBase { /** - * The entity type manager. + * The block storage. * - * @var \Drupal\Core\Entity\EntityTypeManagerInterface + * @var \Drupal\Core\Entity\EntityStorageInterface */ - protected $entityTypeManager; + protected $blockStorage; /** * Constructs a new BlockRegionSorterForm. * - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. + * @param \Drupal\Core\Entity\EntityStorageInterface $block_storage + * The block storage. */ - public function __construct(EntityTypeManagerInterface $entity_type_manager) { - $this->entityTypeManager = $entity_type_manager; + public function __construct(EntityStorageInterface $block_storage) { + $this->blockStorage = $block_storage; } /** @@ -35,7 +34,7 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager) { */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity_type.manager') + $container->get('entity_type.manager')->getStorage('block') ); } @@ -43,7 +42,7 @@ public static function create(ContainerInterface $container) { * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, $theme = NULL, $region = NULL) { - $blocks = $this->entityTypeManager->getStorage('block')->loadByProperties(['region' => $region, 'theme' => $theme]); + $blocks = $this->blockStorage->loadByProperties(['region' => $region, 'theme' => $theme]); // Make sure the blocks are in the correct order. uasort($assignment, 'Drupal\block\Entity\Block::sort'); $form['#tree'] = TRUE; @@ -100,10 +99,11 @@ public function getFormId() { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - foreach ($form_state->getValue('blocks') as $block_id => $block_weight) { - /** @var \Drupal\block\Entity\Block $block */ - $block = $this->entityTypeManager->getStorage('block')->load($block_id); - $block->setWeight($block_weight['weight']); + /** @var \Drupal\block\BlockInterface[] $blocks */ + $blocks = $this->blockStorage->loadMultiple(array_keys($form_state->getValue('blocks'))); + foreach ($blocks as $block_id => $block) { + $weight = $form_state->getValue(['blocks', $block_id, 'weight']); + $block->setWeight($weight); $block->save(); } drupal_set_message('The block order has been saved.'); diff --git a/core/modules/block_place/src/Plugin/DisplayVariant/PlaceBlockPageVariant.php b/core/modules/block_place/src/Plugin/DisplayVariant/PlaceBlockPageVariant.php index 989b38e..72a0c2e 100644 --- a/core/modules/block_place/src/Plugin/DisplayVariant/PlaceBlockPageVariant.php +++ b/core/modules/block_place/src/Plugin/DisplayVariant/PlaceBlockPageVariant.php @@ -5,6 +5,7 @@ use Drupal\block\BlockRepositoryInterface; use Drupal\block\Plugin\DisplayVariant\BlockPageVariant; use Drupal\Component\Serialization\Json; +use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityViewBuilderInterface; use Drupal\Core\Extension\ModuleHandlerInterface; @@ -123,11 +124,14 @@ public function build() { if ($destination) { - $query['destination'] = $destination; if ($this->blockStorage->loadByProperties(['theme' => $theme_name, 'region' => $region])) { - $query['destination'] .= "?block-place-region-sort=$region"; + $destination_parts = UrlHelper::parse($destination); + $destination_parts['query']['block-place-region-sort'] = $region; + $query['destination'] = $destination_parts['path'] . '?' . UrlHelper::buildQuery($destination_parts['query']); + } + else { + $query['destination'] = $destination; } - } $title = $this->t('Place block in the %region region', ['%region' => $region_name]); // @todo Remove module exists check when off_canvas library moved into diff --git a/core/modules/outside_in/js/outside_in.es6.js b/core/modules/outside_in/js/outside_in.es6.js index 077ad3b..91b7f06 100644 --- a/core/modules/outside_in/js/outside_in.es6.js +++ b/core/modules/outside_in/js/outside_in.es6.js @@ -193,7 +193,7 @@ function setEditModeState(editMode) { attach() { const editMode = localStorage.getItem('Drupal.contextualToolbar.isViewing') === 'false'; if (editMode) { - // Do turn on edit mode when on block + // Do not turn on edit mode when in block place mode. if (!drupalSettings.hasOwnProperty('block_place') || !drupalSettings.block_place.isInBlockPlaceMode) { setEditModeState(true); }