Allow adding interfaces per bundle.

Created on 3 May 2024, about 2 months ago
Updated 7 May 2024, about 2 months ago

Problem/Motivation

Want to add interface per bundle.

API changes

# GraphQLComposeEntityTypeInterface
# Add method
public function getEntityType(): EntityTypeInterface;

# Add optional bundle_id to getInterfaces
public function getInterfaces(?string $bundle_id = NULL): array;
# EntityTypeWrapper
# Set strict types on $entity
protected ConfigEntityInterface|EntityTypeInterface $entity;

#Add method
public function getEntityType(): EntityTypeInterface 
function hook_graphql_compose_entity_interfaces_alter(
  array &$interfaces, 
  GraphQLComposeEntityTypeInterface $plugin, 
  ?string $bundle_id
) {}

Proposed resolution

Add bundle information to existing interface hook graphql_compose_entity_interfaces_alter

Usage:

function hook_graphql_compose_entity_interfaces_alter(array &$interfaces, GraphQLComposeEntityTypeInterface $plugin, ?string $bundle_id) {
  if ($plugin->getEntityTypeId() === 'node') {
    $interfaces[] = 'TestNodes';
  }

  if ($plugin->getEntityType()->entityClassImplements(FieldableEntityInterface::class)) {
    $fields = \Drupal::service('entity_field.manager')
      ->getFieldDefinitions($plugin->getEntityTypeId(), $bundle_id);

    if (isset($fields['field_tags'])) {
      $interfaces[] = 'TaggableInterface';
    }
  }
}
✨ Feature request
Status

Fixed

Version

2.1

Component

Code

Created by

πŸ‡¦πŸ‡ΊAustralia AlMunnings Melbourne

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.69.0 2024