0

I have a very simple config entity with a few fields. In the list builder I want to sort the label field by creation date rather than by alphabetical order.

I originally thought this should be fairly easy, but it's proving way more difficult than I expected.

Can anybody point me in the right direction?

enter image description here

2

To answer my own question I guess.

Config entities list builder extends the ConfigEntityListBuilder class, which comes with a few built in methods, among which

  /**
   * Loads entity IDs using a pager sorted by the entity id.
   *
   * @return array
   *   An array of entity IDs.
   */
  protected function getEntityIds() {
    $query = $this->getStorage()->getQuery()
      ->sort($this->entityType->getKey('id'));

    // Only add the pager if a limit is specified.
    if ($this->limit) {
      $query->pager($this->limit);
    }
    return $query->execute();
  }

To sort, in whichever you ones desires, the display list itself all that needs to be done is overwrite the function in the child class.

In my case it was something like this:

protected function getEntityIds() {
  $query = $this
    ->getStorage()
    ->getQuery()
    ->sort('notification_creation_date', 'DESC');

  // Only add the pager if a limit is specified.
  if ($this->limit) {
    $query->pager($this->limit);
  }
  return $query->execute();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.