You are here

public function MetatagManager::sortedGroups in Metatag 8

Returns an array of group plugin information sorted by weight.

Return value

array Array of groups, sorted by weight.

Overrides MetatagManagerInterface::sortedGroups

1 call to MetatagManager::sortedGroups()
MetatagManager::sortedGroupsWithTags in src/MetatagManager.php
Returns a weighted array of groups containing their weighted tags.

File

src/MetatagManager.php, line 181

Class

MetatagManager
Class MetatagManager.

Namespace

Drupal\metatag

Code

public function sortedGroups() {
  $metatag_groups = $this
    ->groupDefinitions();

  // Pull the data from the definitions into a new array.
  $groups = [];
  foreach ($metatag_groups as $group_name => $group_info) {
    $groups[$group_name]['id'] = $group_info['id'];
    $groups[$group_name]['label'] = $group_info['label']
      ->render();
    $groups[$group_name]['description'] = $group_info['description'];
    $groups[$group_name]['weight'] = $group_info['weight'];
  }

  // Create the 'sort by' array.
  $sort_by = [];
  foreach ($groups as $group) {
    $sort_by[] = $group['weight'];
  }

  // Sort the groups by weight.
  array_multisort($sort_by, SORT_ASC, $groups);
  return $groups;
}