Tôi ghi đè tự động hoàn thành thay đổi trong mô-đun tùy chỉnh của mình nhưng tôi không biết cách thay đổi thứ tự hiển thị (DESC hoặc ASC)
<?php
không gian tên Drupal\alter_entity_autocomplete;
sử dụng Drupal\Thành phần\Tiện ích\Html;
sử dụng Drupal\Thành phần\Tiện ích\Tags;
sử dụng Drupal\Core\Entity\EntityAutocompleteMatcherInterface;
sử dụng Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManagerInterface;
/**
 * Lớp đối sánh để nhận kết quả tự động hoàn thành để tham chiếu thực thể.
 */
lớp EntityAutocompleteMatcher thực hiện EntityAutocompleteMatcherInterface
{
  /**
   * Trình quản lý plugin trình xử lý lựa chọn tham chiếu thực thể.
   *
   * @var \Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManagerInterface
   */
  được bảo vệ $selectionManager;
  /**
   * Xây dựng một đối tượng EntityAutocompleteMatcher.
   *
   * @param \Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManagerInterface $selection_manager
   * Trình quản lý plugin trình xử lý lựa chọn tham chiếu thực thể.
   */
  chức năng công cộng __construct(SelectionPluginManagerInterface $selection_manager)
  {
    $this->selectionManager = $selection_manager;
  }
  /**
   * {@inheritDoc}
   */
  hàm công khai getMatches($target_type, $selection_handler, $selection_settings, $string = '')
  {
    $matches = [];
    $options = $selection_settings + [
        'loại_mục_tiêu' => $loại_mục_tiêu,
        'xử lý' => $selection_handler,
      ];
    $handler = $this->selectionManager->getInstance($options);
    if (isset($string)) {
      // Lấy một mảng các thực thể phù hợp.
      $match_operator = !empty($selection_settings['match_operator']) ? $selection_settings['match_operator'] : 'CHỨA';
      $match_limit = isset($selection_settings['match_limit']) ? (int)$selection_settings['match_limit'] : 50;
      $entity_labels = $handler->getReferenceableEntities($string, $match_operator, $match_limit);
      // Lặp qua các thực thể và chuyển đổi chúng thành đầu ra tự động hoàn thành.
      foreach ($entity_labels dưới dạng $values) {
        foreach ($values as $entity_id => $label) { 
          //->sắp xếp('id', 'DESC')
          $entity = \Drupal::entityTypeManager()->getStorage($target_type)->load($entity_id);
          $entity = \Drupal::service('entity.repository')->getTranslationFromContext($entity);
          $key = $label . ' (' . $entity_id . ')';
          // Loại bỏ những thứ như bắt đầu/dấu khoảng trắng, ngắt dòng và thẻ.
          $key = preg_replace('/\s\s+/', '', str_replace("\n", '', trim(Html::decodeEntities(strip_tags($key)))));
          // Tên chứa dấu phẩy hoặc dấu ngoặc kép phải được đặt trong dấu ngoặc kép.
          $key = Thẻ::encode($key);
          $nhãn = $nhãn . ' (' . $entity_id . ')';
          $matches[] = ['giá trị' => $key, 'nhãn' => $nhãn];
        }
      }
    }
    trả lại các trận đấu $;
  }
}
Bạn co thể giup tôi được không ?
Cảm ơn bạn.