diff --git a/core/modules/views/src/Plugin/views/display/Attachment.php b/core/modules/views/src/Plugin/views/display/Attachment.php index dbc773c..4679a47 100644 --- a/core/modules/views/src/Plugin/views/display/Attachment.php +++ b/core/modules/views/src/Plugin/views/display/Attachment.php @@ -296,4 +296,11 @@ public function renderPager() { return $this->usesPager() && $this->getOption('render_pager'); } + /** + * {@inheritdoc} + */ + public function mainDisplaySection() { + return 'displays'; + } + } diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php index 2c49b66..bb3e468 100644 --- a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php @@ -2731,6 +2731,18 @@ protected function isBaseTableTranslatable() { } return FALSE; } + + /** + * Returns a section which is the main one for a display type. + * + * For example for a route related display its the path section. + * + * @return string|NULL + */ + public function mainDisplaySection() { + return NULL; + } + } /** diff --git a/core/modules/views/src/Plugin/views/display/PathPluginBase.php b/core/modules/views/src/Plugin/views/display/PathPluginBase.php index fd93c3c..453517c 100644 --- a/core/modules/views/src/Plugin/views/display/PathPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/PathPluginBase.php @@ -486,5 +486,11 @@ public function validate() { return $errors; } + /** + * {@inheritdoc} + */ + public function mainDisplaySection() { + return 'path'; + } } diff --git a/core/modules/views_ui/js/views-admin.js b/core/modules/views_ui/js/views-admin.js index c3c5b8d..01332a4 100644 --- a/core/modules/views_ui/js/views-admin.js +++ b/core/modules/views_ui/js/views-admin.js @@ -791,6 +791,38 @@ }; /** + * Fetch the value of a given query parameter. + * + * @param name + * @returns {string} + */ + Drupal.views.getParameterByName = function (name) { + name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); + var regexString = "[\\?&]" + name + "=([^&#]*)"; + var regex = new RegExp(regexString); + var found = regex.exec(window.location.search); + if(found == null) + return ""; + else + return decodeURIComponent(found[1].replace(/\+/g, " ")); + }; + + Drupal.behaviors.urlModalOpen = { + attach: function (context) { + jQuery(".views-edit-view", context).once('mainSectionModal', function() { + var modalLink = Drupal.views.getParameterByName('modal'); + if (modalLink !== "") { + // Remove the modal from the current url. + var href = window.location.href.replace('modal=' + modalLink, ''); + href = href.substr(-1) == '?' ? href.substr(0, href.length - 1) : href; + window.history.pushState(null, null, href); + jQuery("a#" + modalLink, context).click(); + } + }); + } + }; + + /** * Remove icon class from elements that are themed as buttons or dropbuttons. */ Drupal.behaviors.viewsRemoveIconClass = { diff --git a/core/modules/views_ui/src/ViewEditForm.php b/core/modules/views_ui/src/ViewEditForm.php index 428775f..b201725 100644 --- a/core/modules/views_ui/src/ViewEditForm.php +++ b/core/modules/views_ui/src/ViewEditForm.php @@ -20,6 +20,7 @@ use Drupal\Core\Render\Element; use Drupal\Core\Url; use Drupal\user\TempStoreFactory; +use Drupal\views\Plugin\ViewsPluginManager; use Drupal\views\Views; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; @@ -52,6 +53,13 @@ class ViewEditForm extends ViewFormBase { protected $dateFormatter; /** + * The display plugin manager. + * + * @var \Drupal\views\Plugin\ViewsPluginManager + */ + protected $displayPluginManager; + + /** * Constructs a new ViewEditForm object. * * @param \Drupal\user\TempStoreFactory $temp_store_factory @@ -60,11 +68,14 @@ class ViewEditForm extends ViewFormBase { * The request stack object. * @param \Drupal\Core\Datetime\DateFormatter $date_formatter * The date Formatter service. + * @param \Drupal\views\Plugin\ViewsPluginManager $display_plugin_manager + * The views plugin manager. */ - public function __construct(TempStoreFactory $temp_store_factory, RequestStack $requestStack, DateFormatter $date_formatter) { + public function __construct(TempStoreFactory $temp_store_factory, RequestStack $requestStack, DateFormatter $date_formatter, ViewsPluginManager $display_plugin_manager) { $this->tempStore = $temp_store_factory->get('views'); $this->requestStack = $requestStack; $this->dateFormatter = $date_formatter; + $this->displayPluginManager = $display_plugin_manager; } /** @@ -74,7 +85,8 @@ public static function create(ContainerInterface $container) { return new static( $container->get('user.tempstore'), $container->get('request_stack'), - $container->get('date.formatter') + $container->get('date.formatter'), + $container->get('plugin.manager.views.display') ); } @@ -843,13 +855,23 @@ public function submitDisplayAdd($form, FormStateInterface $form_state) { // A new display got added so the asterisks symbol should appear on the new // display. $view->getExecutable()->current_display = $display_id; + $view->cacheSet(); + $options = []; + // Ask the display handler to provide some modal link. + $executable = $view->getExecutable(); + $executable->setDisplay($display_id); + + if ($display_section = $executable->display_handler->mainDisplaySection()) { + $options['query']['modal'] = 'views-' . str_replace('_', '-', $display_id) . '-' . $display_section; + } + // Redirect to the new display's edit page. - $form_state->setRedirect('entity.view.edit_display_form', array( + $form_state->setRedirect('entity.view.edit_display_form', [ 'view' => $view->id(), 'display_id' => $display_id, - )); + ], $options); } /** diff --git a/core/modules/views_ui/src/ViewFormBase.php b/core/modules/views_ui/src/ViewFormBase.php index 4da7f8b..04f93e0 100644 --- a/core/modules/views_ui/src/ViewFormBase.php +++ b/core/modules/views_ui/src/ViewFormBase.php @@ -25,6 +25,11 @@ protected $displayID; /** + * @var \Drupal\views\Entity\View + */ + protected $entity; + + /** * {@inheritdoc} */ public function init(FormStateInterface $form_state) {