Namespace
Drupal\rules\TypedData\Options
File
-
src/TypedData/Options/EntityTypeOptions.php
View source
<?php
namespace Drupal\rules\TypedData\Options;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class EntityTypeOptions extends OptionsProviderBase implements ContainerInjectionInterface {
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
public static function create(ContainerInterface $container) {
return new static($container->get('entity_type.manager'));
}
public function getPossibleOptions(AccountInterface $account = NULL) {
$options = [];
$entity_types = $this->entityTypeManager
->getDefinitions();
foreach ($entity_types as $entity_type) {
if (!$entity_type instanceof ContentEntityTypeInterface) {
continue;
}
$options[$entity_type->id()] = (string) $entity_type->getLabel();
if (strtolower(str_replace('_', ' ', $entity_type->id())) != strtolower($entity_type->getLabel())) {
$options[$entity_type->id()] .= ' (' . $entity_type->id() . ')';
}
}
asort($options);
return $options;
}
}
Classes
| Title |
Deprecated |
Summary |
| EntityTypeOptions |
|
Options provider to list all entity types. |