Skip to content

Commit b3d7ed6

Browse files
bucefal91fubhy
authored andcommitted
Handling such content entities that do not support view modes. (#790)
1 parent 377d614 commit b3d7ed6

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

modules/graphql_core/src/Plugin/Deriver/Fields/EntityRenderedDeriver.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Drupal\Component\Plugin\Derivative\DeriverBase;
66
use Drupal\Core\Entity\ContentEntityTypeInterface;
7+
use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
78
use Drupal\Core\Entity\EntityTypeManagerInterface;
89
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
910
use Drupal\Core\StringTranslation\StringTranslationTrait;
@@ -20,29 +21,42 @@ class EntityRenderedDeriver extends DeriverBase implements ContainerDeriverInter
2021
*/
2122
protected $entityTypeManager;
2223

24+
/**
25+
* The entity display repository service.
26+
*
27+
* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
28+
*/
29+
protected $entityDisplayRepository;
30+
2331
/**
2432
* {@inheritdoc}
2533
*/
2634
public static function create(ContainerInterface $container, $basePluginId) {
27-
return new static($container->get('entity_type.manager'));
35+
return new static(
36+
$container->get('entity_type.manager'),
37+
$container->get('entity_display.repository')
38+
);
2839
}
2940

3041
/**
3142
* EntityRenderedDeriver constructor.
3243
*
3344
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
3445
* The entity type manager service.
46+
* @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entityDisplayRepository
47+
* The entity display repository service.
3548
*/
36-
public function __construct(EntityTypeManagerInterface $entityTypeManager) {
49+
public function __construct(EntityTypeManagerInterface $entityTypeManager, EntityDisplayRepositoryInterface $entityDisplayRepository) {
3750
$this->entityTypeManager = $entityTypeManager;
51+
$this->entityDisplayRepository = $entityDisplayRepository;
3852
}
3953

4054
/**
4155
* {@inheritdoc}
4256
*/
4357
public function getDerivativeDefinitions($basePluginDefinition) {
4458
foreach ($this->entityTypeManager->getDefinitions() as $id => $type) {
45-
if ($type instanceof ContentEntityTypeInterface) {
59+
if ($type instanceof ContentEntityTypeInterface && !empty($this->entityDisplayRepository->getViewModes($id))) {
4660
$derivative = [
4761
'parents' => [StringHelper::camelCase($id)],
4862
'description' => $this->t("Renders '@type' entities in the given view mode.", ['@type' => $type->getLabel()]),

0 commit comments

Comments
 (0)