Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By tim.plunkett on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
Description:
Certain entity types, like user roles, filter formats, taxonomy vocabularies, and languages, all have a need for a specific ordering.
To make that easier, a specific subclass of EntityListBuilder
was added, \Drupal\Core\Config\Entity\DraggableListBuilder
.
In order for the controller to work properly, the entity type must have an weight
entity key set in their entity type annotation.
To use the draggable list controller, a subclass needs to be created and specified in the entity type annotation. That subclass needs to implement getFormId()
and very likely override buildHeader()
and buildRow()
.
/**
* Provides a listing of user roles.
*/
class RoleListBuilder extends DraggableListBuilder {
public function getFormId() {
return 'user_admin_roles_form';
}
public function buildHeader() {
$header['label'] = t('Name');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row['label'] = $this->getLabel($entity);
return $row + parent::buildRow($entity);
}
}
Impacts:
Module developers