Created
October 18, 2021 05:52
-
-
Save MatthieuScarset/cd9669e5c869992311c8c7876b6a752a to your computer and use it in GitHub Desktop.
Drupal - Check if a config entity type is a content entity type (or fieldable entity type...etc)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Drupal\Core\Entity\ContentEntityInterface; | |
use Drupal\Core\Entity\FieldableEntityInterface; | |
$entity_types = \Drupal::service('entity_type.manager')->getDefinitions(); | |
/** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity_type */ | |
foreach ($entity_types as $entity_type) { | |
// Stop now if entity type is not fieldable. | |
if (!$entity_type->entityClassImplements(FieldableEntityInterface::class)) { | |
continue; | |
} | |
// Stop now if entity type is not a cnntent entity type. | |
if (!$entity_type->entityClassImplements(ContentEntityInterface::class)) { | |
continue; | |
} | |
// Do your things now... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment