class DraggableListBuilder

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php \Drupal\Core\Config\Entity\DraggableListBuilder
  2. 10 core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php \Drupal\Core\Config\Entity\DraggableListBuilder
  3. 9 core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php \Drupal\Core\Config\Entity\DraggableListBuilder
  4. 8.9.x core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php \Drupal\Core\Config\Entity\DraggableListBuilder

Defines a class to build a draggable listing of configuration entities.

To enable this feature, the entity type must define a "weight" key in its entity keys annotation.

Hierarchy

Expanded class hierarchy of DraggableListBuilder

5 files declare their use of DraggableListBuilder
FilterFormatListBuilder.php in core/modules/filter/src/FilterFormatListBuilder.php
LanguageListBuilder.php in core/modules/language/src/LanguageListBuilder.php
RoleListBuilder.php in core/modules/user/src/RoleListBuilder.php
SearchPageListBuilder.php in core/modules/search/src/SearchPageListBuilder.php
VocabularyListBuilder.php in core/modules/taxonomy/src/VocabularyListBuilder.php

File

core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php, line 17

Namespace

Drupal\Core\Config\Entity
View source
abstract class DraggableListBuilder extends ConfigEntityListBuilder implements FormInterface {
  use DraggableListBuilderTrait;
  
  /**
   * {@inheritdoc}
   */
  public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage) {
    parent::__construct($entity_type, $storage);
    // Do not inject the form builder for backwards-compatibility.
    $this->formBuilder = \Drupal::formBuilder();
    // 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}
   */
  protected function getWeight(EntityInterface $entity) : int|float {
    /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
    return $entity->get($this->weightKey) ?: 0;
  }
  
  /**
   * {@inheritdoc}
   */
  protected function setWeight(EntityInterface $entity, int|float $weight) : EntityInterface {
    /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
    $entity->set($this->weightKey, $weight);
    return $entity;
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.