Skip to content
Snippets Groups Projects

Creating top bar item plugin to display the preview editable areas.

Closes #3465295

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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()) {
  • 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'],
  • 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',
    • Should this button be hidden by default and displayed via JS if there's at least one element that could be modified using contextual?

      If I'm not mistaken that's the behavior used with toolbar integration.

    • We can do that. But we will add in the js a logic to control the visibility of the entire toolbar, because in some cases where only the Editable areas are available but there are no contextual links we have to hide the toolbar, right? Otherwise, we will have a blank toolbar

    • 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ópez
    • Joao Paulo Constantino changed this line in version 10 of the diff

      changed this line in version 10 of the diff

    • Please register or sign in to reply
  • 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) =>
  • added 1 commit

    • 7cf273d4 - Creating top bar item plugin to display the preview editable areas.

    Compare with previous version

  • Pablo López
    Pablo López @plopesc started a thread on an outdated change in commit 7cf273d4
  • 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'),
  • Pablo López
    Pablo López @plopesc started a thread on an outdated change in commit 7cf273d4
  • 71 74 ],
    72 75 ],
    73 76 ];
    74
    77 $build['#attached'] = [
  • added 1 commit

    • ab7007ed - Creating top bar item plugin to display the preview editable areas.

    Compare with previous version

  • added 1 commit

    • cbd40222 - Creating top bar item plugin to display the preview editable areas.

    Compare with previous version

  • added 1 commit

    • b3c71e5d - Creating top bar item plugin to display the preview editable areas.

    Compare with previous version

  • 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 = {
  • 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 or toolbarToolsSection.children[0]
      • Need to take into account that plugin could be altered and placed in a different region, like TopBarRegion::Actions
    • Joao Paulo Constantino changed this line in version 7 of the diff

      changed this line in version 7 of the diff

    • Please register or sign in to reply
  • added 1 commit

    • 6b03caed - Creating top bar item plugin to display the preview editable areas.

    Compare with previous version

  • added 1 commit

    • b3376ba8 - Creating top bar item plugin to display the preview editable areas.

    Compare with previous version

  • Pablo López
    Pablo López @plopesc started a thread on commit 6b03caed
  • 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')) {
  • Pablo López
    Pablo López @plopesc started a thread on commit 6b03caed
  • 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.

    Compare with previous version

  • added 1 commit

    • c7941a54 - Creating top bar item plugin to display the preview editable areas.

    Compare with previous version

  • added 1 commit

    • f531d79a - Creating top bar item plugin to display the preview editable areas.

    Compare with previous version

  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading