diff --git a/core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php b/core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php index 5162aa12192b6fadb52b0ed7b0d37491313d5af2..bcec42c95a5855785f49180a4b45d4b36fd8efc6 100644 --- a/core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php +++ b/core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php @@ -9,14 +9,37 @@ use Drupal\Core\Form\FormInterface; /** - * Defines a class to build a draggable listing of configuration entities. + * Provides a base class for draggable list builders of configuration entities. + * + * This class enables drag-and-drop reordering of configuration entities in + * the admin UI. It requires that the entity type defines a "weight" entity key, + * which maps to a field that stores the position/order of the entity. + * + * Extend this class when you want to provide a sortable list of config entities, + * such as vocabularies, menus, or any other list where order matters. + * + * Requirements: + * - The entity type must define a 'weight' key in its entity_keys. + * - The weight field must exist and be accessible (get/set). + * + * @see \Drupal\Core\Entity\DraggableListBuilderTrait + * @see \Drupal\Core\Config\Entity\ConfigEntityListBuilder */ abstract class DraggableListBuilder extends ConfigEntityListBuilder implements FormInterface { use DraggableListBuilderTrait; /** - * {@inheritdoc} + * Constructs a new DraggableListBuilder. + * + * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type + * The entity type definition. + * @param \Drupal\Core\Entity\EntityStorageInterface $storage + * The storage handler for the entity type. + * + * This constructor sets up the form builder for compatibility, disables + * pagination (to allow full drag-and-drop), and stores the weight key + * if it is defined in the entity type. */ public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage) { parent::__construct($entity_type, $storage); @@ -24,15 +47,23 @@ public function __construct(EntityTypeInterface $entity_type, EntityStorageInter // Do not inject the form builder for backwards-compatibility. $this->formBuilder = \Drupal::formBuilder(); - // Check if the entity type supports weighting. + // Check if the entity type supports weighting and store the key. if ($this->entityType->hasKey('weight')) { $this->weightKey = $this->entityType->getKey('weight'); } + + // Disable limit to load all entities for full drag-and-drop support. $this->limit = FALSE; } /** - * {@inheritdoc} + * Gets the weight of a config entity. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * The configuration entity whose weight should be returned. + * + * @return int|float + * The weight value. Defaults to 0 if not set. */ protected function getWeight(EntityInterface $entity): int|float { /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */ @@ -40,7 +71,15 @@ protected function getWeight(EntityInterface $entity): int|float { } /** - * {@inheritdoc} + * Sets the weight of a config entity. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * The configuration entity whose weight should be updated. + * @param int|float $weight + * The new weight value to assign. + * + * @return \Drupal\Core\Entity\EntityInterface + * The updated entity object. */ protected function setWeight(EntityInterface $entity, int|float $weight): EntityInterface { /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */