Implement ParentEntityHandler plugin system for extensible entity support

Replace hardcoded entity type checks with a plugin-based architecture using
PHP 8 attributes. This allows adding new parent entity types without modifying
core module files.

Changes:
- Add ParentEntityHandler attribute, interface, base class, and manager
- Create built-in handlers for taxonomy_term, user, and node entities
- Move Group support to site_structure_group submodule (fixes class not found
  error when Group module is not installed)
- Refactor SiteStructureSettingsForm to use handler manager
- Refactor SiteStructureMenuBlock to use handler manager
- Refactor SectionBreadcrumbBuilder to use handler manager
- Update site_structure.module to use handler manager for clearsSiteSection
- Update documentation and translations

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-04 08:35:04 -03:00
parent 43fa9208a9
commit 0c8f0fc778
17 changed files with 1153 additions and 117 deletions

View File

@@ -0,0 +1,8 @@
name: 'Site Structure Group Integration'
type: module
description: 'Provides Group entity support as parent type for Site Structure module.'
package: 'Site Structure'
core_version_requirement: ^10.3 || ^11
dependencies:
- site_structure:site_structure
- group:group

View File

@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace Drupal\site_structure_group\Plugin\ParentEntityHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\group\Entity\GroupInterface;
use Drupal\site_structure\Attribute\ParentEntityHandler;
use Drupal\site_structure\ParentEntityHandler\ParentEntityHandlerBase;
/**
* Handler for group entities.
*
* This handler is provided by the site_structure_group submodule and is only
* available when the Group module is installed.
*/
#[ParentEntityHandler(
id: 'group',
label: new TranslatableMarkup('Groups (group)'),
entity_type_id: 'group',
provider_module: 'group',
clears_site_section: TRUE,
sort_field: 'label',
weight: 15,
)]
class GroupHandler extends ParentEntityHandlerBase {
/**
* {@inheritdoc}
*/
public function getEntityFromRoute(RouteMatchInterface $route_match): ?EntityInterface {
$group = $route_match->getParameter('group');
if (!$group instanceof GroupInterface) {
return NULL;
}
return $group;
}
/**
* {@inheritdoc}
*/
public function handlesEntity(EntityInterface $entity): bool {
return $entity instanceof GroupInterface;
}
}