Skip to content
Snippets Groups Projects

Resolve #3457688 "Support for core"

Closes #3457688

Merge request reports

Members who can merge are allowed to add commits.

Merge request pipeline passed with warnings for 71aa3b22

Code Quality is loading
Test summary results are being parsed
Ready to merge by members who can write to the target branch.
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
1 <?php
2
3 namespace Drupal\environment_indicator;
4
5 use Drupal\Core\Cache\Cache;
6 use Drupal\Core\Entity\EntityTypeManagerInterface;
7 use Drupal\Core\Render\RendererInterface;
8 use Drupal\Core\Security\TrustedCallbackInterface;
9 use Drupal\Core\Session\AccountInterface;
10 use Drupal\Core\Url;
11 use Drupal\environment_indicator\Entity\EnvironmentIndicator;
12 use Drupal\Core\StringTranslation\StringTranslationTrait;
  • Comment on lines +5 to +12

    These should be in alphabetical order.

    Suggested change
    5 use Drupal\Core\Cache\Cache;
    6 use Drupal\Core\Entity\EntityTypeManagerInterface;
    7 use Drupal\Core\Render\RendererInterface;
    8 use Drupal\Core\Security\TrustedCallbackInterface;
    9 use Drupal\Core\Session\AccountInterface;
    10 use Drupal\Core\Url;
    11 use Drupal\environment_indicator\Entity\EnvironmentIndicator;
    12 use Drupal\Core\StringTranslation\StringTranslationTrait;
    5 use Drupal\Core\Cache\Cache;
    6 use Drupal\Core\Entity\EntityTypeManagerInterface;
    7 use Drupal\Core\Render\RendererInterface;
    8 use Drupal\Core\Security\TrustedCallbackInterface;
    9 use Drupal\Core\Session\AccountInterface;
    10 use Drupal\Core\StringTranslation\StringTranslationTrait;
    11 use Drupal\Core\Url;
    12 use Drupal\environment_indicator\Entity\EnvironmentIndicator;
  • m4olivei changed this line in version 4 of the diff

    changed this line in version 4 of the diff

  • Please register or sign in to reply
  • 1 /* Active environment button background and font colors. */
    2 .admin-toolbar .toolbar-button.toolbar-button--environment-indicator,
    3 .admin-toolbar .toolbar-button.toolbar-button--environment-indicator-label{
  • 126 126 }
    127 127 }
    128 128
    129 /**
    130 * Implements hook_preprocess_navigation().
    131 */
    132 function environment_indicator_preprocess_navigation (&$variables) {
  • 294 $custom_block_id = 'environment_indicator_navigation';
    295 $definitions[$custom_block_id] = [
    296 'class' => 'Drupal\environment_indicator\Plugin\Block\EnvironmentIndicatorNavigationBlock',
    297 'provider' => 'environment_indicator_navigation',
    298 'admin_label' => t('Environment Indicator'),
    299 'category' => t('Navigation'),
    300 ];
    301 }
    302 }
    303
    304 /**
    305 * Implements hook_module_implements_alter().
    306 */
    307 function environment_indicator_module_implements_alter(&$implementations, $hook) {
    308 if ($hook === 'plugin_filter_block_alter' && isset($implementations['environment_indicator'])) {
    309 $group = $implementations['environment_indicator'] ?? false;
  • 134 157 'environment_indicator' => [
    135 158 'render element' => 'element',
    136 159 ],
    160 'navigation_menu__environment_indicator' => [
    161 'variables' => [
    162 'menu_name' => NULL,
    163 'items' => [],
    164 'attributes' => [],
    165 ],
    166 'base hook' => 'navigation_menu',
    167 ]
  • 6
    7 use Drupal\Core\Access\AccessResult;
    8 use Drupal\Core\Access\AccessResultInterface;
    9 use Drupal\Core\Block\Attribute\Block;
    10 use Drupal\Core\Block\BlockBase;
    11 use Drupal\Core\Extension\ModuleHandlerInterface;
    12 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
    13 use Drupal\Core\Session\AccountInterface;
    14 use Drupal\Core\StringTranslation\TranslatableMarkup;
    15 use Symfony\Component\DependencyInjection\ContainerInterface;
    16
    17 /**
    18 * Defines an environment indicator navigation block class.
    19 *
    20 * @internal
    21 *
  • 56
    57 /**
    58 * #lazy_builder callback; builds shortcut toolbar links.
    59 *
    60 * @param bool $show_configure_link
    61 * Boolean to indicate whether to include the configure link or not.
    62 *
    63 * @return array
    64 * A renderable array of shortcut links.
    65 */
    66 public function lazyLinks() {
    67 $active_environment = \Drupal::config('environment_indicator.indicator');
    68 $items = [
    69 'environment_indicator' => [
    70 'title' => $active_environment->get('name'),
    71 'below' => $this->getBelowLinks()
  • 66 public function lazyLinks() {
    67 $active_environment = \Drupal::config('environment_indicator.indicator');
    68 $items = [
    69 'environment_indicator' => [
    70 'title' => $active_environment->get('name'),
    71 'below' => $this->getBelowLinks()
    72 ],
    73 ];
    74
    75 return [
    76 '#theme' => 'navigation_menu__environment_indicator',
    77 '#menu_name' => 'environment_indicator',
    78 '#items' => $items,
    79 '#cache' => Cache::mergeTags(['config:environment_indicator.settings'], _environment_indicator_switcher_cache_tags()),
    80 ];
    81 }
  • 124 return $links;
    125 }
    126
    127 /**
    128 * Check if the current user has access to the given environment.
    129 *
    130 * @param string $environment
    131 * The environment to check access for.
    132 *
    133 * @return bool
    134 * TRUE if the user has access, FALSE otherwise.
    135 */
    136 protected function hasAccessEnvironment($environment) {
    137 return $this->currentUser->hasPermission('access environment indicator')
    138 || $this->currentUser->hasPermission('access environment indicator ' . $environment);
    139 }
  • 8 8 - '@state'
    9 9 - '@settings'
    10 10 - '@entity_type.manager'
    11 environment_indicator.lazy_builders:
    12 class: Drupal\environment_indicator\EnvironmentIndicatorLazyBuilder
    13 arguments: ['@renderer', '@entity_type.manager', '@current_user']
    14 Drupal\environment_indicator\EnvironmentIndicatorLazyBuilder: '@environment_indicator.lazy_builders'
    • Comment on lines +11 to +14
      Suggested change
      16 environment_indicator.lazy_builders:
      17 class: Drupal\environment_indicator\EnvironmentIndicatorLazyBuilder
      18 arguments: ['@renderer', '@entity_type.manager', '@current_user']
      19 Drupal\environment_indicator\EnvironmentIndicatorLazyBuilder: '@environment_indicator.lazy_builders'
      16 environment_indicator.lazy_builders:
      17 class: Drupal\environment_indicator\EnvironmentIndicatorLazyBuilder
      18 arguments:
      19 - '@renderer'
      20 - '@entity_type.manager'
      21 - '@current_user'
      22 Drupal\environment_indicator\EnvironmentIndicatorLazyBuilder: '@environment_indicator.lazy_builders'
    • Please register or sign in to reply
  • 10 10 dependencies:
    11 11 - core/jquery
    12 12 - core/once
    13 drupal.environment_indicator_navigation:
    14 version: '3.0'
  • 1 {{ attach_library('environment_indicator/drupal.environment_indicator_navigation') }}
    • Suggested change
      32 {{ attach_library('environment_indicator/drupal.environment_indicator_navigation') }}
      32 {#
      33 /**
      34 * @file
      35 * Twig template for the environment indicator navigation in the admin toolbar.
      36 *
      37 * Attaches the 'environment_indicator/drupal.environment_indicator_navigation' library.
      38 * Generates a structured navigation menu item within the Drupal admin toolbar.
      39 *
      40 * This template is rendered by the EnvironmentIndicatorNavigationBlock plugin.
      41 *
      42 * Available variables:
      43 * - menu_name: The name of the menu being rendered.
      44 * - title: The title of the menu block.
      45 * - items: An array of menu items to be rendered.
      46 *
      47 * Logic:
      48 * - Sets unique IDs for accessibility and identification purposes.
      49 * - Checks if the menu item has children (`below`), and renders appropriate HTML structure.
      50 * - Includes the '@navigation/toolbar-button.html.twig' template for rendering individual toolbar buttons.
      51 *
      52 * Attributes and Classes:
      53 * - Assigns various attributes and classes to HTML elements for styling and functionality.
      54 *
      55 * @see \Drupal\environment_indicator\Plugin\Block\EnvironmentIndicatorNavigationBlock
      56 */
      57 #}
      58 {{ attach_library('environment_indicator/drupal.environment_indicator_navigation') }}
    • Please register or sign in to reply
  • Bryan Heisler added 1 commit

    added 1 commit

    • 744aa5c4 - Issue #3457688: Accomedate toolbar button's move from template to component.

    Compare with previous version

  • m4olivei added 1 commit

    added 1 commit

    Compare with previous version

  • m4olivei added 4 commits

    added 4 commits

    Compare with previous version

  • m4olivei added 2 commits

    added 2 commits

    • a2a1a19e - Issue #3457688: Undo changes to libraries file that break patch
    • 160cf619 - Issue #3457688: Hide prefix icon replacement when expanded, adjust padding

    Compare with previous version

  • m4olivei added 11 commits

    added 11 commits

    Compare with previous version

  • m4olivei added 1 commit

    added 1 commit

    • 0b7d2b8e - Issue #3457688: Add modifier class for parent of navigation env indicator

    Compare with previous version

  • 24 * @var \Drupal\Core\Render\RendererInterface
    25 */
    26 protected $renderer;
    27
    28 /**
    29 * Constructs a new ShortcutLazyBuilders object.
    30 *
    31 * @param \Drupal\Core\Render\RendererInterface $renderer
    32 * The renderer service.
    33 * @param \Drupal\Core\Entity\EntityTypeManagerInterface|null $entityTypeManager
    34 * The entity type manager.
    35 * @param \Drupal\Core\Session\AccountInterface|null $currentUser
    36 * The current user.
    37 */
    38 public function __construct(RendererInterface $renderer, protected ?EntityTypeManagerInterface $entityTypeManager, protected ?AccountInterface $currentUser) {
    39 $this->renderer = $renderer;
  • 38 public function __construct(RendererInterface $renderer, protected ?EntityTypeManagerInterface $entityTypeManager, protected ?AccountInterface $currentUser) {
    39 $this->renderer = $renderer;
    40 if (!isset($this->entityTypeManager)) {
    41 @trigger_error('Calling ' . __METHOD__ . '() without the $entityTypeManager argument is deprecated in drupal:10.3.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3427050', E_USER_DEPRECATED);
    42 $this->entityTypeManager = \Drupal::entityTypeManager();
    43 }
    44 if (!isset($this->currentUser)) {
    45 @trigger_error('Calling ' . __METHOD__ . '() without the $currentUser argument is deprecated in drupal:10.3.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3427050', E_USER_DEPRECATED);
    46 $this->currentUser = \Drupal::currentUser();
    47 }
    48 }
    49
    50 /**
    51 * {@inheritdoc}
    52 */
    53 public static function trustedCallbacks() {
  • 49
    50 /**
    51 * {@inheritdoc}
    52 */
    53 public static function trustedCallbacks() {
    54 return ['lazyLinks'];
    55 }
    56
    57 /**
    58 * #lazy_builder callback; builds shortcut toolbar links.
    59 *
    60 * @return array
    61 * A renderable array of shortcut links.
    62 */
    63 public function lazyLinks() {
    64 $active_environment = \Drupal::config('environment_indicator.indicator');
  • 73 return [
    74 '#theme' => 'navigation_menu__environment_indicator',
    75 '#menu_name' => 'environment_indicator',
    76 '#items' => $items,
    77 '#cache' => Cache::mergeTags(['config:environment_indicator.settings'], _environment_indicator_switcher_cache_tags()),
    78 ];
    79 }
    80
    81 /**
    82 * Get all the links for the switcher.
    83 *
    84 * @return array
    85 * Array of links for each configured environment.
    86 */
    87 protected function getBelowLinks(): array {
    88 if (!$environment_entities = EnvironmentIndicator::loadMultiple()) {
  • 62 */
    63 public function lazyLinks() {
    64 $active_environment = \Drupal::config('environment_indicator.indicator');
    65 $items = [
    66 'environment_indicator' => [
    67 'title' => $active_environment->get('name'),
    68 'below' => $this->getBelowLinks(),
    69 'class' => $active_environment->get('name'),
    70 ],
    71 ];
    72
    73 return [
    74 '#theme' => 'navigation_menu__environment_indicator',
    75 '#menu_name' => 'environment_indicator',
    76 '#items' => $items,
    77 '#cache' => Cache::mergeTags(['config:environment_indicator.settings'], _environment_indicator_switcher_cache_tags()),
  • 57 * {@inheritdoc}
    58 */
    59 protected function blockAccess(AccountInterface $account): AccessResultInterface {
    60 return AccessResult::allowedIfHasPermission($account, 'access environment indicator');
    61 }
    62
    63 /**
    64 * {@inheritdoc}
    65 */
    66 public function build(): array {
    67
    68 return [
    69 '#lazy_builder' => ['environment_indicator.lazy_builders:lazyLinks', []],
    70 '#create_placeholder' => TRUE,
    71 '#cache' => [
    72 'contexts' => ['user'],
  • Pablo López added 1 commit

    added 1 commit

    Compare with previous version

  • m4olivei added 1 commit

    added 1 commit

    Compare with previous version

  • m4olivei added 1 commit

    added 1 commit

    Compare with previous version

  • m4olivei added 1 commit

    added 1 commit

    • ec437dcc - Issue #3457688: Address hiding env indicator top bar when navigation integration is setup

    Compare with previous version

  • 294 308 }
    295 309 }
    296 310 }
    311 elseif ($integration === 'navigation') {
    312 if ($this->moduleHandler->moduleExists('navigation')) {
    313 $cacheability = new CacheableMetadata();
  • m4olivei added 1 commit

    added 1 commit

    • 54936249 - Issue #3457688: Avoid using cacheability metadata in loading navigation layout section

    Compare with previous version

  • 8 8 - '@state'
    9 9 - '@settings'
    10 10 - '@entity_type.manager'
    11 - '@plugin.manager.layout_builder.section_storage'
  • m4olivei added 2 commits

    added 2 commits

    • 11ac1f15 - Issue #3457688: Make layout_builder a soft dependency for ToolbarHandler
    • a74198c2 - Issue #3457688: Refactor external integration checks, catch exception when...

    Compare with previous version

  • 284 285 * TRUE if integration is enabled. FALSE otherwise.
    285 286 */
    286 287 public function externalIntegration($integration): bool {
    288 if ($integration == 'toolbar') {
    289 return $this->hasExternalToolbarIntegration();
    290 }
    291 elseif ($integration == 'navigation') {
    292 return $this->hasExternalNavigationIntegration();
    293 }
    294 return FALSE;
    295
    287 296 if ($integration == 'toolbar') {
  • 353 438 return $links;
    354 439 }
    355 440
    356 }
    441 /**
    442 * Get the section storage manager from layout builder as soft dependency.
    443 *
    444 * @throws \RuntimeException
    445 * When layout_builder module is not enabled.
    446 *
    447 * @return \Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface
    448 * Layout builder section storage manager.
    449 */
    450 protected function getSectionStorageManager() {
  • 87 89 * The entity type manager.
    88 90 */
    89 91 public function __construct(
    90 92 ModuleHandlerInterface $module_handler,
    • While we're here and given that we're probably adding new items to the constructor, we could refactor it to use constructor promotion to reduce boilerplate code.

    • That might not be possible given as it is now, ^9.3 is still included in the core_version_requirement for this module, and the minimum PHP requirement for 9.3 is PHP 7.3. Constructor promotion isn't supported until PHP 8. Drupal 9 is EOL, so could probably update that, but maybe not here?

    • In that case all the other classes in this MR should be modified and remove the constructor promotion there.

      Then open a follow up to take advantage of PHP 8 goodies.

      Maybe dropping support here is simpler, since Navigation is 10.3+.

    • I believe dropping support for 9.3 would require a major version bump for the module. As we're planning a major version bump to support the hook method of including things in the Navigation, I think I'd like to avoid the major version bump on the basis of language features here. Will back out of the constructor promotion in other places in this MR.

    • Please register or sign in to reply
  • 76 77 * Implements hook_preprocess_HOOK() for page templates.
    77 78 */
    78 79 function environment_indicator_preprocess_html(&$variables) {
    79 80 if (_environment_indicator_external_integration_is_enabled('toolbar')) {
  • 270 296 ->getStorage('environment_indicator')
    271 297 ->load($environment_id);
    272 298 }
    299
    300 /**
    301 * Implements hook_plugin_filter_block__layout_builder_alter().
    302 *
    303 * Curate the blocks available in the Layout Builder "Add Block" UI.
    304 */
    305 function environment_indicator_plugin_filter_block__layout_builder_alter(array &$definitions, array $extra) {
  • m4olivei added 5 commits

    added 5 commits

    Compare with previous version

  • m4olivei added 1 commit

    added 1 commit

    Compare with previous version

  • m4olivei added 1 commit

    added 1 commit

    • 260695da - Issue #3457688: Avoid adding a top level environment-indicator CSS class when...

    Compare with previous version

  • m4olivei added 1 commit

    added 1 commit

    • 71aa3b22 - Issue #3457688: Avoid PHP attributes since we don't have that support in old Drupal

    Compare with previous version

  • Please register or sign in to reply
    Loading