ConfigEntityListBuilder.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Drupal\Core\Config\Entity;
  3. use Drupal\Core\Entity\EntityInterface;
  4. use Drupal\Core\Entity\EntityListBuilder;
  5. /**
  6. * Defines the default class to build a listing of configuration entities.
  7. *
  8. * @ingroup entity_api
  9. */
  10. class ConfigEntityListBuilder extends EntityListBuilder {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public function load() {
  15. $entity_ids = $this->getEntityIds();
  16. $entities = $this->storage->loadMultipleOverrideFree($entity_ids);
  17. // Sort the entities using the entity class's sort() method.
  18. // See \Drupal\Core\Config\Entity\ConfigEntityBase::sort().
  19. uasort($entities, [$this->entityType->getClass(), 'sort']);
  20. return $entities;
  21. }
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public function getDefaultOperations(EntityInterface $entity) {
  26. /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
  27. $operations = parent::getDefaultOperations($entity);
  28. if ($this->entityType->hasKey('status')) {
  29. if (!$entity->status() && $entity->hasLinkTemplate('enable')) {
  30. $operations['enable'] = [
  31. 'title' => t('Enable'),
  32. 'weight' => -10,
  33. 'url' => $this->ensureDestination($entity->toUrl('enable')),
  34. ];
  35. }
  36. elseif ($entity->hasLinkTemplate('disable')) {
  37. $operations['disable'] = [
  38. 'title' => t('Disable'),
  39. 'weight' => 40,
  40. 'url' => $this->ensureDestination($entity->toUrl('disable')),
  41. ];
  42. }
  43. }
  44. return $operations;
  45. }
  46. }