Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/GraphQL/Execution/ExecutionResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,16 @@
class ExecutionResult extends LibraryExecutionResult implements CacheableDependencyInterface {
use RefinableCacheableDependencyTrait;

/**
* PHP Serialization: skip some class members when serializing during tests.
*/
public function __sleep(): array {
// PHPUnit error: Fatal error: Uncaught Exception: Serialization of
// 'Closure' is not allowed.
// Remove some closure-containing members before serializing.
$vars = get_object_vars($this);
unset($vars['extensions']);
return array_keys($vars);
}

}
18 changes: 8 additions & 10 deletions src/Plugin/GraphQL/DataProducer/EntityDefinition/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Drupal\graphql\Plugin\GraphQL\DataProducer\EntityDefinition;

use Drupal\Core\Entity\ContentEntityType;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityFieldManager;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManager;
Expand Down Expand Up @@ -121,24 +121,22 @@ public function resolve(
?array $field_types_context = NULL,
FieldContext $field_context
): \Iterator {
$entity_definition->getBundleEntityType();
if ($entity_definition instanceof ContentEntityType) {

if ($entity_definition instanceof ContentEntityTypeInterface) {
$entity_type_id = $entity_definition->id();
if ($bundle_context) {
$key = $bundle_context['key'];
$id = $entity_definition->id();
$fields = $this->entityFieldManager->getFieldDefinitions($id, $key);
$fields = $this->entityFieldManager->getFieldDefinitions($entity_type_id, $key);

// Set entity form default display as context.
$entity_id = $id . '.' . $key . '.default';
/** @var \Drupal\Core\Config\Entity\ConfigEntityStorage $form_display_context */
$form_display_id = $entity_type_id . '.' . $key . '.default';
$form_display_context = $this->entityTypeManager
->getStorage('entity_form_display')
->load($entity_id);
->load($form_display_id);
$field_context->setContextValue('entity_form_display', $form_display_context);
}
else {
$id = $entity_definition->id();
$fields = $this->entityFieldManager->getFieldDefinitions($id, $id);
$fields = $this->entityFieldManager->getFieldDefinitions($entity_type_id, $entity_type_id);
}

if ($field_types_context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Drupal\graphql\Plugin\GraphQL\DataProducer\EntityDefinition\Fields;

use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase;

/**
Expand Down Expand Up @@ -34,6 +35,9 @@ class Multiple extends DataProducerPluginBase {
* If the field contains multiple values or just single value.
*/
public function resolve(FieldDefinitionInterface $entity_definition_field): bool {
if ($entity_definition_field instanceof FieldStorageDefinitionInterface) {
return $entity_definition_field->isMultiple();
}
return $entity_definition_field->isList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

namespace Drupal\graphql\Plugin\GraphQL\DataProducer\EntityDefinition\Fields;

use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\Entity\BaseFieldOverride;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase;

/**
Expand Down Expand Up @@ -37,36 +34,7 @@ class Reference extends DataProducerPluginBase {
* If the field is referencing entities (is the entity reference type).
*/
public function resolve(FieldDefinitionInterface $entity_definition_field): bool {
if ($entity_definition_field instanceof BaseFieldDefinition) {
/** @var \Drupal\Core\Field\BaseFieldDefinition $entity_definition_field */
if ($entity_definition_field->getType() === 'entity_reference') {
return TRUE;
}
else {
return FALSE;
}
}
elseif ($entity_definition_field instanceof FieldConfig) {
/** @var \Drupal\field\Entity\FieldConfig $entity_definition_field */
if ($entity_definition_field->getType() === 'entity_reference') {
return TRUE;
}
else {
return FALSE;
}
}
elseif ($entity_definition_field instanceof BaseFieldOverride) {
/** @var \Drupal\field\Entity\FieldConfig $entity_definition_field */
if ($entity_definition_field->getType() === 'entity_reference') {
return TRUE;
}
else {
return FALSE;
}
}
else {
return FALSE;
}
return $entity_definition_field->getType() === 'entity_reference';
}

}
Loading