You are here

public function EntityDisplayBase::getHighestWeight in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/EntityDisplayBase.php \Drupal\Core\Entity\EntityDisplayBase::getHighestWeight()

Gets the highest weight of the components in the display.

Return value

int|null The highest weight of the components in the display, or NULL if the display is empty.

Overrides EntityDisplayInterface::getHighestWeight

1 call to EntityDisplayBase::getHighestWeight()
EntityDisplayBase::setComponent in core/lib/Drupal/Core/Entity/EntityDisplayBase.php
Sets the display options for a component.

File

core/lib/Drupal/Core/Entity/EntityDisplayBase.php, line 409

Class

EntityDisplayBase
Provides a common base class for entity view and form displays.

Namespace

Drupal\Core\Entity

Code

public function getHighestWeight() {
  $weights = [];

  // Collect weights for the components in the display.
  foreach ($this->content as $options) {
    if (isset($options['weight'])) {
      $weights[] = $options['weight'];
    }
  }

  // Let other modules feedback about their own additions.
  $weights = array_merge($weights, \Drupal::moduleHandler()
    ->invokeAll('field_info_max_weight', [
    $this->targetEntityType,
    $this->bundle,
    $this->displayContext,
    $this->mode,
  ]));
  return $weights ? max($weights) : NULL;
}