You are here

protected function ListPaymentStatuses::buildHierarchy in Payment 8.2

Returns a hierarchical representation of payment statuses.

Parameters

string[]|null $limit_plugin_ids: An array of plugin IDs to limit the statuses to, or NULL to allow all.

Return value

array[] A possibly infinitely nested associative array. Keys are plugin IDs and values are arrays of similar structure as this method's return value.

1 call to ListPaymentStatuses::buildHierarchy()
ListPaymentStatuses::execute in src/Controller/ListPaymentStatuses.php
Lists all payment statuses.

File

src/Controller/ListPaymentStatuses.php, line 115

Class

ListPaymentStatuses
Handles the "list payment methods" route.

Namespace

Drupal\payment\Controller

Code

protected function buildHierarchy(array $limit_plugin_ids = NULL) {
  static $hierarchy = NULL;
  if (is_null($hierarchy)) {
    $parents = [];
    $children = [];
    $definitions = $this->paymentStatusManager
      ->getDefinitions();
    if (is_array($limit_plugin_ids)) {
      $definitions = array_intersect_key($definitions, array_flip($limit_plugin_ids));
    }
    uasort($definitions, array(
      $this,
      'sort',
    ));
    foreach ($definitions as $plugin_id => $definition) {
      if (!empty($definition['parent_id'])) {
        $children[$definition['parent_id']][] = $plugin_id;
      }
      else {
        $parents[] = $plugin_id;
      }
    }
    $hierarchy = $this
      ->buildHierarchyLevel($parents, $children);
  }
  return $hierarchy;
}