Skip to content
Snippets Groups Projects
Commit 02694be5 authored by Al Munnings's avatar Al Munnings
Browse files

Issue #3388494: Enabling metatags submodule generates error "Interface field...

Issue #3388494: Enabling metatags submodule generates error "Interface field MetaTagInterface.metatag expected.."
parent 97ceb189
No related branches found
No related tags found
No related merge requests found
Pipeline #36097 passed with warnings
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
declare(strict_types=1); declare(strict_types=1);
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\graphql_compose\Plugin\GraphQLCompose\GraphQLComposeEntityTypeInterface; use Drupal\graphql_compose\Plugin\GraphQLCompose\GraphQLComposeEntityTypeInterface;
...@@ -16,15 +17,27 @@ use Drupal\metatag\Form\MetatagDefaultsForm; ...@@ -16,15 +17,27 @@ use Drupal\metatag\Form\MetatagDefaultsForm;
* Implements hook_graphql_compose_entity_base_fields_alter(). * Implements hook_graphql_compose_entity_base_fields_alter().
*/ */
function graphql_compose_metatags_graphql_compose_entity_base_fields_alter(array &$fields, string $entity_type_id): void { function graphql_compose_metatags_graphql_compose_entity_base_fields_alter(array &$fields, string $entity_type_id): void {
static $supported_types; static $enabled_types;
if (!isset($enabled_types)) {
$enabled_types = [];
/** @var EntityFieldManagerInterface $manager */
$manager = \Drupal::service('entity_field.manager');
if (!isset($supported_types)) {
$supported_types = MetatagDefaultsForm::getSupportedEntityTypes(); $supported_types = MetatagDefaultsForm::getSupportedEntityTypes();
foreach (array_keys($supported_types) as $entity_type_id) {
$base_fields = $manager->getBaseFieldDefinitions($entity_type_id);
// Check the entity has a meta tag field.
if (array_key_exists('metatag', $base_fields)) {
$enabled_types[$entity_type_id] = $entity_type_id;
}
}
} }
if (array_key_exists($entity_type_id, $supported_types)) { // Enable and force multiple.
// Metatag field on the entity type is not multiple, force multiple. if (array_key_exists($entity_type_id, $enabled_types)) {
// 'metatag' field is a computed metatag_computed field type.
$fields['metatag'] = [ $fields['metatag'] = [
'multiple' => TRUE, 'multiple' => TRUE,
]; ];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment