function EntityDisplayModeBase::sort

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/EntityDisplayModeBase.php \Drupal\Core\Entity\EntityDisplayModeBase::sort()
  2. 8.9.x core/lib/Drupal/Core/Entity/EntityDisplayModeBase.php \Drupal\Core\Entity\EntityDisplayModeBase::sort()
  3. 10 core/lib/Drupal/Core/Entity/EntityDisplayModeBase.php \Drupal\Core\Entity\EntityDisplayModeBase::sort()

Overrides ConfigEntityBase::sort

File

core/lib/Drupal/Core/Entity/EntityDisplayModeBase.php, line 66

Class

EntityDisplayModeBase
Base class for config entity types with settings for form and view modes.

Namespace

Drupal\Core\Entity

Code

public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
    
    /** @var \Drupal\Core\Entity\EntityDisplayModeInterface $a */
    
    /** @var \Drupal\Core\Entity\EntityDisplayModeInterface $b */
    // Sort by the type of entity the view mode is used for.
    $a_type = $a->getTargetType();
    $b_type = $b->getTargetType();
    $type_order = strnatcasecmp($a_type, $b_type);
    return $type_order != 0 ? $type_order : parent::sort($a, $b);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.