}
}
- // Create the form element.
- $element = $this->metatagManager->form($values, $element, [$item->getEntity()->getentityTypeId()]);
+ // Retrieve configuration settings.
+ $settings = \Drupal::config('metatag.settings');
+ $entity_type_groups = $settings->get('entity_type_groups');
+
+ // Find the current entity type and bundle.
+ $entity_type = $item->getEntity()->getentityTypeId();
+ $entity_bundle = $item->getEntity()->bundle();
+
+ // See if there are requested groups for this entity type and bundle.
+ $groups = !empty($entity_type_groups[$entity_type]) && !empty($entity_type_groups[$entity_type][$entity_bundle]) ? $entity_type_groups[$entity_type][$entity_bundle] : [];
+ // Limit the form to requested groups, if any.
+ if (!empty($groups)) {
+ $element = $this->metatagManager->form($values, $element, [$entity_type], $groups);
+ }
+ // Otherwise, display all groups.
+ else {
+ $element = $this->metatagManager->form($values, $element, [$entity_type]);
+ }
// Put the form element into the form's "advanced" group.
$element['#group'] = 'advanced';
// Flatten the values array to remove the groups and then serialize all the
// meta tags into one value for storage.
$tag_manager = \Drupal::service('plugin.manager.metatag.tag');
- $tags = $tag_manager->getDefinitions();
foreach ($values as &$value) {
$flattened_value = [];
foreach ($value as $group) {