Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / metatag / src / Plugin / Field / FieldWidget / MetatagFirehose.php
index 0acbb2b71f162b4d8f353812882f38a4e20dccf4..6797f59ae6a4d181ba79120144ce89d5a2ee5d45 100644 (file)
@@ -74,8 +74,24 @@ class MetatagFirehose extends WidgetBase implements ContainerFactoryPluginInterf
       }
     }
 
-    // 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';
@@ -90,7 +106,6 @@ class MetatagFirehose extends WidgetBase implements ContainerFactoryPluginInterf
     // 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) {