You are here

public function MetatagManager::sortedTags in Metatag 8

Returns an array of tag plugin information sorted by group then weight.

Return value

array Array of tags, sorted by weight.

Overrides MetatagManagerInterface::sortedTags

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

File

src/MetatagManager.php, line 208

Class

MetatagManager
Class MetatagManager.

Namespace

Drupal\metatag

Code

public function sortedTags() {
  $metatag_tags = $this
    ->tagDefinitions();

  // Pull the data from the definitions into a new array.
  $tags = [];
  foreach ($metatag_tags as $tag_name => $tag_info) {
    $tags[$tag_name]['id'] = $tag_info['id'];
    $tags[$tag_name]['label'] = $tag_info['label']
      ->render();
    $tags[$tag_name]['group'] = $tag_info['group'];
    $tags[$tag_name]['weight'] = $tag_info['weight'];
  }

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

  // Sort the tags by weight.
  array_multisort($sort_by['group'], SORT_ASC, $sort_by['weight'], SORT_ASC, $tags);
  return $tags;
}