Resolve #3457688 "Support for core"
Closes #3457688
Merge request reports
Activity
added 4 commits
-
a000e6db...c5e053da - 3 commits from branch
project:4.x
- dfba4766 - Merge branch '4.x' into 3457688-support-for-core
-
a000e6db...c5e053da - 3 commits from branch
- src/EnvironmentIndicatorLazyBuilder.php 0 → 100644
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.
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; changed this line in version 4 of the diff
- css/environment_indicator-navigation.css 0 → 100644
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; changed this line in version 4 of the diff
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 ] changed this line in version 4 of the diff
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 * changed this line in version 4 of the diff
- src/EnvironmentIndicatorLazyBuilder.php 0 → 100644
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() changed this line in version 4 of the diff
- src/EnvironmentIndicatorLazyBuilder.php 0 → 100644
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 } - src/EnvironmentIndicatorLazyBuilder.php 0 → 100644
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
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'
10 10 dependencies: 11 11 - core/jquery 12 12 - core/once 13 drupal.environment_indicator_navigation: 14 version: '3.0' Set this to
VERSION
so it can update for us automatically.Edited by Chris Greenchanged this line in version 4 of the diff
1 {{ attach_library('environment_indicator/drupal.environment_indicator_navigation') }} 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') }}
added 1 commit
added 4 commits
- b3c1a659 - Issue #3457688: Fix a PHP error for an invalid component prop type
- 9687e564 - Issue #3457688: Use modifiers prop where applicable
- 4569945e - Issue #3457688: Avoid style overrides to align with navigation styling
- da8e66c6 - Issue #3457688: Remove unused argument to lazy builder, and code style
Toggle commit listadded 11 commits
-
160cf619...520137b4 - 10 commits from branch
project:4.x
- 29be5a26 - Merge branch '4.x' into 3457688-support-for-core
-
160cf619...520137b4 - 10 commits from branch
added 1 commit
- src/EnvironmentIndicatorLazyBuilder.php 0 → 100644
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; changed this line in version 9 of the diff
- src/EnvironmentIndicatorLazyBuilder.php 0 → 100644
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() { We could use annotations instead. See https://www.drupal.org/node/3349470
changed this line in version 9 of the diff
- src/EnvironmentIndicatorLazyBuilder.php 0 → 100644
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'); changed this line in version 9 of the diff
- src/EnvironmentIndicatorLazyBuilder.php 0 → 100644
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()) { changed this line in version 9 of the diff
- src/EnvironmentIndicatorLazyBuilder.php 0 → 100644
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()), 77 '#cache' => Cache::mergeTags(['config:environment_indicator.settings'], _environment_indicator_switcher_cache_tags()), 77 '#cache' => [ 78 'tags' => Cache::mergeTags(['config:environment_indicator.settings'], _environment_indicator_switcher_cache_tags()), 79 'contexts' => ['route', 'user.permissions'], 80 ] changed this line in version 9 of the diff
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'], changed this line in version 9 of the diff
294 308 } 295 309 } 296 310 } 311 elseif ($integration === 'navigation') { 312 if ($this->moduleHandler->moduleExists('navigation')) { 313 $cacheability = new CacheableMetadata(); Found this logic in
AddNavigationBlock
class:$navigation_storage = $this->sectionStorageManager->load('navigation', [ 'navigation' => new Context(new ContextDefinition('string'), 'navigation'), ]);
That would solve the CacheableMetadata concerns.
changed this line in version 13 of the diff
added 1 commit
8 8 - '@state' 9 9 - '@settings' 10 10 - '@entity_type.manager' 11 - '@plugin.manager.layout_builder.section_storage' This implicitly adds a dependency on
layout_builder
. If you enable onlyenvironment_indicator
without also enablingnavigation
, you get this error:The service "environment_indicator.toolbar_handler" has a dependency on a non-existent service "plugin.manager.layout_builder.section_storage".
Need to make it a soft dependency.
Edited by m4oliveichanged this line in version 14 of the diff
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') { changed this line in version 15 of the diff
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() { changed this line in version 15 of the diff
87 89 * The entity type manager. 88 90 */ 89 91 public function __construct( 90 92 ModuleHandlerInterface $module_handler, That might not be possible given as it is now,
^9.3
is still included in thecore_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?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.
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')) { Have not tested it, but seems reasonable to add this check here too.
changed this line in version 17 of the diff
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) { This is not the cleanest way to add a new block... But we need to live with it to give support to 10.3.
11.x will give full support using the different navigation hooks
Edited by Pablo López
added 5 commits
Toggle commit listadded 1 commit
added 1 commit
added 1 commit