
| Current Path : /var/www/html/vendor/drush/drush/src/Drupal/Commands/field/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/vendor/drush/drush/src/Drupal/Commands/field/EntityTypeBundleValidationTrait.php |
<?php
namespace Drush\Drupal\Commands\field;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use function t;
/**
* @property EntityTypeManagerInterface $entityTypeManager
*/
trait EntityTypeBundleValidationTrait
{
protected function validateEntityType(string $entityTypeId): void
{
if (!$this->entityTypeManager->hasDefinition($entityTypeId)) {
throw new \InvalidArgumentException(
t("Entity type with id ':entityType' does not exist.", [':entityType' => $entityTypeId])
);
}
}
protected function validateBundle(string $entityTypeId, string $bundle): void
{
if (!$entityTypeDefinition = $this->entityTypeManager->getDefinition($entityTypeId)) {
return;
}
$bundleEntityType = $entityTypeDefinition->getBundleEntityType();
if ($bundleEntityType === null && $bundle === $entityTypeId) {
return;
}
$bundleDefinition = $this->entityTypeManager
->getStorage($bundleEntityType)
->load($bundle);
if (!$bundleDefinition) {
throw new \InvalidArgumentException(
t("Bundle ':bundle' does not exist on entity type with id ':entityType'.", [
':bundle' => $bundle,
':entityType' => $entityTypeId,
])
);
}
}
}