Creating top bar item plugin to display the preview editable areas.
Closes #3465295
Merge request reports
Activity
added 1 commit
- a317cbea - Creating top bar item plugin to display the preview editable areas.
42 $plugin_definition, 43 $container->get(EntityRouteHelper::class) 44 ); 45 } 46 47 /** 48 * {@inheritdoc} 49 */ 50 public function build(): array { 51 $build = [ 52 '#cache' => [ 53 'contexts' => ['route'], 54 ], 55 ]; 56 57 if (!$this->entityRouteHelper->getContentEntityFromRoute()) { changed this line in version 3 of the diff
38 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { 39 return new static( 40 $configuration, 41 $plugin_id, 42 $plugin_definition, 43 $container->get(EntityRouteHelper::class) 44 ); 45 } 46 47 /** 48 * {@inheritdoc} 49 */ 50 public function build(): array { 51 $build = [ 52 '#cache' => [ 53 'contexts' => ['route'], changed this line in version 3 of the diff
48 * {@inheritdoc} 49 */ 50 public function build(): array { 51 $build = [ 52 '#cache' => [ 53 'contexts' => ['route'], 54 ], 55 ]; 56 57 if (!$this->entityRouteHelper->getContentEntityFromRoute()) { 58 return $build; 59 } 60 61 $build += [ 62 [ 63 '#type' => 'component', We should try to replicate the same behavior we already have for contextual in the original toolbar. In order to replace the old toolbar with navigation, the user experience should not have any regression.
Let's address the button visibility issue first, and then we could discuss with finnsky how we could fix the top bar visibility logic for empty items.
Edited by Pablo Lópezchanged this line in version 10 of the diff
132 132 }, 133 133 }; 134 135 /** 136 * Toggle contextual menu links. 137 * 138 * @type {Drupal~behavior} 139 * 140 * @prop {Drupal~behaviorAttach} attach 141 * Attach event into the navigation contextual link. 142 */ 143 Drupal.behaviors.toggleContextualLinks = { 144 attach: (context) => { 145 const showText = Drupal.t('Editable areas'); 146 const hideText = Drupal.t('Hide editable areas'); 147 const toggleContextualItems = (el) => changed this line in version 3 of the diff
added 1 commit
- 7cf273d4 - Creating top bar item plugin to display the preview editable areas.
40 42 $configuration, 41 43 $plugin_id, 42 44 $plugin_definition, 43 $container->get(EntityRouteHelper::class) 45 $container->get(EntityRouteHelper::class), 46 $container->get('current_user'), changed this line in version 4 of the diff
71 74 ], 72 75 ], 73 76 ]; 74 77 $build['#attached'] = [ changed this line in version 4 of the diff
added 1 commit
- ab7007ed - Creating top bar item plugin to display the preview editable areas.
added 1 commit
- cbd40222 - Creating top bar item plugin to display the preview editable areas.
added 1 commit
- b3c71e5d - Creating top bar item plugin to display the preview editable areas.
131 131 }); 132 132 }, 133 133 }; 134 135 /** 136 * Toggle contextual menu links. 137 * 138 * @type {Drupal~behavior} 139 * 140 * @prop {Drupal~behaviorAttach} attach 141 * Attach event into the navigation contextual link. 142 */ 143 Drupal.behaviors.toggleContextualLinks = { changed this line in version 7 of the diff
140 * @prop {Drupal~behaviorAttach} attach 141 * Attach event into the navigation contextual link. 142 */ 143 Drupal.behaviors.toggleContextualLinks = { 144 attach: (context) => { 145 const editableAreaBtn = document.querySelector( 146 'button.navigation-contextual-link', 147 ); 148 if (!editableAreaBtn) { 149 return; 150 } 151 152 const contextualLinks = document.querySelectorAll('.contextual-region'); 153 // If no contextual links are present and only the "Editable Areas" button appears in the top bar tools section, 154 // remove the button and clear the tools section to ensure the toolbar keep hidden. 155 if (contextualLinks.length === 0) { This part of the JS could be more specific to affect only to instances of the contextual links top bar item plugin.
- Need to take into account that other items could be in the region, hence we cannot just
toolbarToolsSection.innerHTML = '';
- The button should be removed even if there are other items in the region as is not in the 1st position, so we cannot rely on
toolbarToolsSection.children.length === 1
ortoolbarToolsSection.children[0]
- Need to take into account that plugin could be altered and placed in a different region, like
TopBarRegion::Actions
- Need to take into account that other items could be in the region, hence we cannot just
changed this line in version 7 of the diff
added 1 commit
- 6b03caed - Creating top bar item plugin to display the preview editable areas.
added 1 commit
- b3376ba8 - Creating top bar item plugin to display the preview editable areas.
25 attach: (context) => { 26 const editableAreaBtn = document.querySelector( 27 'button.navigation-contextual-link', 28 ); 29 if (!editableAreaBtn) { 30 return; 31 } 32 33 const editableAreaBtnRegion = editableAreaBtn.parentElement; 34 const contextualLinks = document.querySelectorAll('.contextual-region'); 35 // If no contextual links are present and only the "Editable Areas" button appears in the top bar tools section, 36 // remove the button and clear the tools section to ensure the toolbar keep hidden. 37 if (contextualLinks.length === 0) { 38 // Determine the toolbar region selector based on the button's parent class. 39 let toolbarRegionSelector = 'top-bar__tools'; 40 if (editableAreaBtnRegion.classList.contains('top-bar__actions')) { 37 if (contextualLinks.length === 0) { 38 // Determine the toolbar region selector based on the button's parent class. 39 let toolbarRegionSelector = 'top-bar__tools'; 40 if (editableAreaBtnRegion.classList.contains('top-bar__actions')) { 41 toolbarRegionSelector = 'top-bar__actions'; 42 } else if ( 43 editableAreaBtnRegion.classList.contains('top-bar__context') 44 ) { 45 toolbarRegionSelector = 'top-bar__context'; 46 } 47 const toolbarSection = document.querySelector( 48 `.${toolbarRegionSelector}`, 49 ); 50 // If the toolbar section contains only the "Editable Areas" button, remove the button and clear the section. 51 if ( 52 toolbarSection.children.length === 1 && added 1 commit
- f1f1daf6 - Creating top bar item plugin to display the preview editable areas.
added 1 commit
- c7941a54 - Creating top bar item plugin to display the preview editable areas.
added 1 commit
- f531d79a - Creating top bar item plugin to display the preview editable areas.