From 3fe13aff2632c23fac1a7b4cfa446f6dd7d8a349 Mon Sep 17 00:00:00 2001 From: Santeri Hurnanen Date: Mon, 8 Apr 2024 07:05:02 +0300 Subject: [PATCH 1/5] UHF-9738: Remove deprecated code deprecated in helfi_platform_config:3.0.0 and is removed from helfi_platform_config:^4.3 --- .../hdbt_admin_tools/hdbt_admin_tools.module | 32 ------------------- 1 file changed, 32 deletions(-) diff --git a/modules/hdbt_admin_tools/hdbt_admin_tools.module b/modules/hdbt_admin_tools/hdbt_admin_tools.module index 1a6cae69d..fcebaec0c 100644 --- a/modules/hdbt_admin_tools/hdbt_admin_tools.module +++ b/modules/hdbt_admin_tools/hdbt_admin_tools.module @@ -267,21 +267,6 @@ function hdbt_admin_tools_get_page_entity(): ?EntityInterface { return NULL; } -// @codingStandardsIgnoreStart -/** - * Gets the current page main entity. - * - * @deprecated in helfi_platform_config:3.0.0 and is removed from helfi_platform_config:3.2.0. - * Use hdbt_admin_tools_get_page_entity() instead. - * - * @return \Drupal\Core\Entity\EntityInterface - * Current page main entity. - */ -function hdbt_content_get_page_entity(): ?EntityInterface { - return hdbt_admin_tools_get_page_entity(); -} -// @codingStandardsIgnoreEnd - /** * Implements hook_preprocess_HOOK(). */ @@ -405,23 +390,6 @@ function hdbt_admin_tools_handle_sidebar_visibility(array &$variables, ContentEn } } -// @codingStandardsIgnoreStart -/** - * Handle sidebar visibility based on current entity menu links. - * - * @deprecated in helfi_platform_config:3.0.0 and is removed from helfi_platform_config:3.2.0. - * Use hdbt_admin_tools_handle_sidebar_visibility() instead. - * - * @param array $variables - * Variables array. - * @param \Drupal\Core\Entity\ContentEntityInterface $entity - * Content entity, like tpr_service, tpr_unit or node. - */ -function _hdbt_content_handle_sidebar_visibility(array &$variables, ContentEntityInterface $entity): void { - hdbt_admin_tools_handle_sidebar_visibility($variables, $entity); -} -// @codingStandardsIgnoreEnd - /** * Implements hook_preprocess_HOOK(). */ From 5b471a5b57b5f2bdd760c21653b837469f2a6f0b Mon Sep 17 00:00:00 2001 From: Santeri Hurnanen Date: Mon, 8 Apr 2024 14:04:16 +0300 Subject: [PATCH 2/5] UHF-9738: Allow hero without field_has_hero --- helfi_platform_config.module | 12 +++++----- .../hdbt_admin_tools/hdbt_admin_tools.module | 8 ++++--- src/Plugin/Block/HeroBlock.php | 22 ++++++++++--------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/helfi_platform_config.module b/helfi_platform_config.module index 3d41d0ff1..68888a960 100644 --- a/helfi_platform_config.module +++ b/helfi_platform_config.module @@ -252,19 +252,21 @@ function helfi_platform_config_block_access(Block $block, $operation, AccountInt if ( !$entity instanceof ContentEntityInterface || - !$entity->hasField('field_has_hero') + !$entity->hasField('field_hero') ) { return AccessResult::neutral(); } // Show title block if the "has hero" checkbox is not checked (=false). - if (!$entity->get('field_has_hero')->value) { + if ( + $entity->hasField('field_has_hero') && + $entity->get('field_has_hero')->value + ) { return AccessResult::allowed()->addCacheableDependency($block); } - // Show title block if the "has hero" checkbox is checked (=true) and - // the Hero paragraph is not found. - return AccessResult::allowedIf(!$entity->get('field_hero')->entity) + // Show title block if the Hero paragraph is not found. + return AccessResult::forbiddenIf($entity->get('field_hero')->entity) ->addCacheableDependency($block); } diff --git a/modules/hdbt_admin_tools/hdbt_admin_tools.module b/modules/hdbt_admin_tools/hdbt_admin_tools.module index fcebaec0c..a40e202e6 100644 --- a/modules/hdbt_admin_tools/hdbt_admin_tools.module +++ b/modules/hdbt_admin_tools/hdbt_admin_tools.module @@ -279,9 +279,11 @@ function hdbt_admin_tools_preprocess_page(&$variables): void { // Set has_hero variable according to field_has_hero and existence of // field_hero reference. - if ($entity->hasField('field_has_hero')) { - $variables['has_hero'] = $entity->get('field_has_hero')->value && - !$entity->get('field_hero')->isEmpty(); + if ($entity->hasField('field_hero')) { + $variables['has_hero'] = !$entity->get('field_hero')->isEmpty() && ( + !$entity->hasField('field_has_hero') || + $entity->get('field_has_hero')->value + ); } // Handle sidebar visibility. diff --git a/src/Plugin/Block/HeroBlock.php b/src/Plugin/Block/HeroBlock.php index 030672b5a..b7846177d 100644 --- a/src/Plugin/Block/HeroBlock.php +++ b/src/Plugin/Block/HeroBlock.php @@ -27,16 +27,19 @@ public function build() : array { /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ ['entity' => $entity, 'entity_version' => $entity_version] = $this->getCurrentEntityVersion(); - // No need to continue if current entity doesn't have has_hero field. + // No need to continue if current entity doesn't have hero field. if ( !$entity instanceof ContentEntityInterface || - !$entity->hasField('field_has_hero') + !$entity->hasField('field_hero') ) { return $build; } // @todo Support preview on entity reference fields ie. paragraphs. - if (!$entity->get('field_has_hero')->isEmpty()) { + if ( + !$entity->hasField('field_has_hero') || + !$entity->get('field_has_hero')->isEmpty() + ) { $first_paragraph_grey = ''; // Handle only landing page. @@ -51,13 +54,12 @@ public function build() : array { 'unit_search', 'service_list_search', ]; - foreach ($paragraphs_with_grey_bg as $paragraph_with_grey_bg) { - if ( - $paragraph instanceof ParagraphInterface && - $paragraph->getType() === $paragraph_with_grey_bg - ) { - $first_paragraph_grey = 'has-first-gray-bg-block'; - } + + if ( + $paragraph instanceof ParagraphInterface && + in_array($paragraph->getType(), $paragraphs_with_grey_bg) + ) { + $first_paragraph_grey = 'has-first-gray-bg-block'; } } From 6b1fdf2ce39fb3df3336c30702293f6d758c4b8b Mon Sep 17 00:00:00 2001 From: Santeri Hurnanen Date: Mon, 8 Apr 2024 14:04:21 +0300 Subject: [PATCH 3/5] UHF-9738: Allow sidebar visibility override --- modules/hdbt_admin_tools/hdbt_admin_tools.module | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/hdbt_admin_tools/hdbt_admin_tools.module b/modules/hdbt_admin_tools/hdbt_admin_tools.module index a40e202e6..6cbc0e0b6 100644 --- a/modules/hdbt_admin_tools/hdbt_admin_tools.module +++ b/modules/hdbt_admin_tools/hdbt_admin_tools.module @@ -300,7 +300,6 @@ function hdbt_admin_tools_preprocess_page(&$variables): void { * Content entity, like tpr_service, tpr_unit or node. */ function hdbt_admin_tools_handle_sidebar_visibility(array &$variables, ContentEntityInterface $entity): void { - // The entities that need to be handled listed as content type => entity type. $allowed_entities = [ 'page' => 'node', @@ -309,10 +308,12 @@ function hdbt_admin_tools_handle_sidebar_visibility(array &$variables, ContentEn 'tpr_service' => 'tpr_service', ]; + /** @var \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler */ + $moduleHandler = Drupal::service('module_handler'); + // Trigger hook_sidebar_visibility_allowed_entities_alter(). // Allow modules to alter the list of allowed entities. - \Drupal::service('module_handler') - ->alter('sidebar_visibility_allowed_entities', $allowed_entities); + $moduleHandler->alter('sidebar_visibility_allowed_entities', $allowed_entities); // Get possible (node) content type. $content_type = $entity instanceof NodeInterface ? $entity->getType() : FALSE; @@ -327,6 +328,9 @@ function hdbt_admin_tools_handle_sidebar_visibility(array &$variables, ContentEn return; } + $variables['has_sidebar_first'] = FALSE; + $variables['has_sidebar_second'] = FALSE; + // Load menu links for the current page entity. $menu_link_manager = Drupal::service('plugin.manager.menu.link'); $menu_links = $menu_link_manager->loadLinksByRoute( @@ -335,9 +339,6 @@ function hdbt_admin_tools_handle_sidebar_visibility(array &$variables, ContentEn 'main' ); - $variables['has_sidebar_first'] = FALSE; - $variables['has_sidebar_second'] = FALSE; - // If there are links in current language, apply "has_sidebar_first" variable // to indicate twig templates how to render the sidebar. // However, if the menu link is set to first level, do not render the @@ -390,6 +391,9 @@ function hdbt_admin_tools_handle_sidebar_visibility(array &$variables, ContentEn if ($entity instanceof Service && !$entity->get('links')->isEmpty()) { $variables['has_sidebar_second'] = TRUE; } + + // Allow modules to override sidebar visibility. + $moduleHandler->alter('sidebar_visibility', $variables, $entity); } /** From 20e9e86997c39bf05ccdb569e046194856be0ea9 Mon Sep 17 00:00:00 2001 From: Santeri Hurnanen Date: Mon, 8 Apr 2024 16:20:49 +0300 Subject: [PATCH 4/5] UHF-9738: Pass field and entity to hook_helfi_hero_design_alter --- .../helfi_paragraphs_hero/helfi_paragraphs_hero.api.php | 7 ++++++- modules/helfi_paragraphs_hero/helfi_paragraphs_hero.module | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.api.php b/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.api.php index d289cb705..931ff18e3 100644 --- a/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.api.php +++ b/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.api.php @@ -10,6 +10,11 @@ * * @param array $designs * The designs for the hero. + * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $definition + * Hero design field. + * @param \Drupal\Core\Entity\FieldableEntityInterface|null $entity + * Current entity. */ -function hook_helfi_hero_design_alter(array &$designs) { +function hook_helfi_hero_design_alter(array &$designs, \Drupal\Core\Field\FieldStorageDefinitionInterface $definition, \Drupal\Core\Entity\FieldableEntityInterface|null $entity) { + } diff --git a/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.module b/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.module index b15d45573..de0958401 100644 --- a/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.module +++ b/modules/helfi_paragraphs_hero/helfi_paragraphs_hero.module @@ -26,7 +26,7 @@ function helfi_paragraphs_hero_entity_bundle_info_alter(array &$bundles): void { * @return int[] * Values to select. */ -function helfi_paragraphs_hero_design_allowed_values(FieldStorageDefinitionInterface $definition, FieldableEntityInterface $entity = NULL) : array { +function helfi_paragraphs_hero_design_allowed_values(FieldStorageDefinitionInterface $definition, ?FieldableEntityInterface $entity = NULL) : array { $designs = [ 'without-image-left' => t('Without image, align left'), 'with-image-right' => t('Image on the right'), @@ -38,6 +38,6 @@ function helfi_paragraphs_hero_design_allowed_values(FieldStorageDefinitionInter $moduleHandler = Drupal::service('module_handler'); // Let other modules alter the CKEditor link dialog form validation. - $moduleHandler->alter('helfi_hero_design', $designs); + $moduleHandler->alter('helfi_hero_design', $designs, $definition, $entity); return $designs; } From 7cb38fa99acf941b38fb7f45da7593f342799675 Mon Sep 17 00:00:00 2001 From: Santeri Hurnanen Date: Wed, 10 Apr 2024 09:31:52 +0300 Subject: [PATCH 5/5] UHF-9738: Sonarcloud: ignore .api.php files --- .sonarcloud.properties | 1 + 1 file changed, 1 insertion(+) create mode 100644 .sonarcloud.properties diff --git a/.sonarcloud.properties b/.sonarcloud.properties new file mode 100644 index 000000000..1e619621c --- /dev/null +++ b/.sonarcloud.properties @@ -0,0 +1 @@ +sonar.exclusions=**/*.api.php