public function NodeOrderManager::getTermMinMax in Node Order 8
Get min and max weight in the term.
Parameters
int $tid: Term id.
bool $reset: Ignore static data.
Return value
array Array with min and max weights.
Overrides NodeOrderManagerInterface::getTermMinMax
2 calls to NodeOrderManager::getTermMinMax()
- NodeOrderManager::addToList in src/NodeOrderManager.php 
- Push new or newly orderable node to the top of ordered list.
- NodeOrderManager::handleListsDecrease in src/NodeOrderManager.php 
- Reorder list in which the node is dropped.
File
- src/NodeOrderManager.php, line 117 
Class
- NodeOrderManager
- Defines a service that creates & manages node ordering within taxonomy terms.
Namespace
Drupal\nodeorderCode
public function getTermMinMax($tid, $reset = FALSE) {
  static $min_weights = [];
  static $max_weights = [];
  if ($reset) {
    $min_weights = [];
    $max_weights = [];
  }
  if (!isset($min_weights[$tid]) || !isset($max_weights[$tid])) {
    $query = \Drupal::database()
      ->select('taxonomy_index', 'i')
      ->fields('i', [
      'tid',
    ])
      ->condition('tid', $tid)
      ->groupBy('tid');
    $query
      ->addExpression('MAX(weight)', 'max_weight');
    $query
      ->addExpression('MIN(weight)', 'min_weight');
    $record = $query
      ->execute()
      ->fetch();
    $min_weights[$tid] = $record->min_weight;
    $max_weights[$tid] = $record->max_weight;
  }
  $weights['min'] = $min_weights[$tid];
  $weights['max'] = $max_weights[$tid];
  return $weights;
}