diff --git a/src/MetatagManager.php b/src/MetatagManager.php index 9123713..91916d1 100644 --- a/src/MetatagManager.php +++ b/src/MetatagManager.php @@ -91,10 +91,10 @@ public function sortedGroups() { // Pull the data from the definitions into a new array. $groups = []; foreach ($metatag_groups as $group_name => $group_info) { - $id = $group_info['id']; - $groups[$id]['label'] = $group_info['label']->render(); - $groups[$id]['description'] = $group_info['description']; - $groups[$id]['weight'] = $group_info['weight']; + $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. @@ -117,11 +117,12 @@ public function sortedTags() { // Pull the data from the definitions into a new array. $tags = []; - foreach ($metatag_tags as $tag_name => $tag_info) { - $id = $tag_info['id']; - $tags[$id]['label'] = $tag_info['label']->render(); - $tags[$id]['group'] = $tag_info['group']; - $tags[$id]['weight'] = $tag_info['weight']; + foreach ($metatag_tags as $plugin => $tag_info) { + $name = $tag_info['name']; + $tags[$name]['id'] = $plugin; + $tags[$name]['label'] = $tag_info['label']->render(); + $tags[$name]['group'] = $tag_info['group']; + $tags[$name]['weight'] = $tag_info['weight']; } // Create the 'sort by' array. @@ -165,7 +166,6 @@ public function sortedGroupsWithTags() { * {@inheritdoc} */ public function form(array $values, array $element, array $token_types = [], array $included_groups = NULL, array $included_tags = NULL) { - // Add the outer fieldset. $element += [ '#type' => 'details', @@ -176,18 +176,19 @@ public function form(array $values, array $element, array $token_types = [], arr $groups_and_tags = $this->sortedGroupsWithTags(); $first = TRUE; - foreach ($groups_and_tags as $group_id => $group) { + foreach ($groups_and_tags as $group_name => $group) { // Only act on groups that have tags and are in the list of included // groups (unless that list is null). - if (isset($group['tags']) && (is_null($included_groups) || in_array($group_id, $included_groups))) { + if (isset($group['tags']) && (is_null($included_groups) || in_array($group['id'], $included_groups))) { // Create the fieldset. - $element[$group_id]['#type'] = 'details'; - $element[$group_id]['#title'] = $group['label']; - $element[$group_id]['#description'] = $group['description']; - $element[$group_id]['#open'] = $first; + $element[$group_name]['#type'] = 'details'; + $element[$group_name]['#title'] = $group['label']; + $element[$group_name]['#description'] = $group['description']; + $element[$group_name]['#open'] = $first; $first = FALSE; - foreach ($group['tags'] as $tag_id => $tag) { + foreach ($group['tags'] as $tag_name => $tag) { + $tag_id = $tag['id']; // Only act on tags in the included tags list, unless that is null. if (is_null($included_tags) || in_array($tag_id, $included_tags)) { // Make an instance of the tag. @@ -198,7 +199,7 @@ public function form(array $values, array $element, array $token_types = [], arr $tag->setValue($tag_value); // Create the bit of form for this tag. - $element[$group_id][$tag_id] = $tag->form($element); + $element[$group_name][$tag_id] = $tag->form($element); } } }