You are here

public function MongodbPathAliasStorage::getAliasesForAdminListing in MongoDB 8

Loads aliases for admin listing.

Parameters

array $header: Table header.

string $keys: Search keys.

Return value

array Array of items to be displayed on the current page.

Overrides AliasStorageInterface::getAliasesForAdminListing

File

src/MongodbPathAliasStorage.php, line 217
Contains Drupal\mongodb\Path.

Class

MongodbPathAliasStorage
Provides a class for CRUD operations on path aliases in MongoDB.

Namespace

Drupal\mongodb

Code

public function getAliasesForAdminListing($header, $keys = NULL) {
  if ($keys) {
    $criteria = array(
      // Replace wildcards with PCRE wildcards.
      // TODO check escaping reliability. Is should be more complex than this.
      // @see http://www.rgagnon.com/javadetails/java-0515.html
      'alias' => preg_replace('!\\*+!', '.*', $keys),
    );
  }
  else {
    $criteria = array();
  }

  // TODO PagerSelectExtender
  // TODO TableSortExtender: should be shorter than doing this every time.
  $order = array();
  foreach ($header as $order_element) {

    // This happens on Operations column.
    if (!is_array($order_element)) {
      continue;
    }
    $direction = isset($order_element['sort']) && strtolower($order_element['sort']) === 'desc' ? -1 : 1;
    $order[$order_element['field']] = $direction;
  }
  $alias_arrays = $this
    ->mongoCollection()
    ->find($criteria)
    ->limit(50)
    ->sort($order);
  $alias_objects = array();
  foreach ($alias_arrays as $alias_array) {

    // Code in core assumes the id is called "pid", not "_id".
    $alias_array['pid'] = $alias_array['_id'];
    $alias_objects[] = (object) $alias_array;
  }
  return $alias_objects;
}