
| Current Path : /var/www/html/rocksensor/vendor/chi-teck/drupal-code-generator/src/Command/PhpStormMeta/ |
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/rocksensor/vendor/chi-teck/drupal-code-generator/src/Command/PhpStormMeta/Fields.php |
<?php
declare(strict_types=1);
namespace DrupalCodeGenerator\Command\PhpStormMeta;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use DrupalCodeGenerator\Asset\File;
use DrupalCodeGenerator\Utils;
/**
* Generates PhpStorm meta-data for entity fields.
*/
final class Fields {
/**
* Constructs the object.
*/
public function __construct(
private readonly EntityTypeManagerInterface $entityTypeManager,
private readonly EntityFieldManagerInterface $entityFieldManager,
private readonly \Closure $entityInterface,
) {}
/**
* Generator callback.
*/
public function __invoke(): File {
$definitions = [];
foreach ($this->entityTypeManager->getDefinitions() as $entity_type => $definition) {
if (!$definition->entityClassImplements(FieldableEntityInterface::class)) {
continue;
}
$definitions[] = [
'type' => $entity_type,
'label' => $definition->getLabel(),
'class' => Utils::addLeadingSlash($definition->getClass()),
'interface' => ($this->entityInterface)($definition),
'fields' => \array_keys($this->entityFieldManager->getFieldStorageDefinitions($entity_type)),
];
}
return File::create('.phpstorm.meta.php/fields.php')
->template('fields.php.twig')
->vars(['definitions' => $definitions]);
}
}