Namespace
Drupal\rules\TypedData\Options
File
-
src/TypedData/Options/NodeTypeOptions.php
View source
<?php
namespace Drupal\rules\TypedData\Options;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class NodeTypeOptions 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 = [];
$node_types = $this->entityTypeManager
->getStorage('node_type')
->loadMultiple();
foreach ($node_types as $node_type) {
$options[$node_type->id()] = $node_type->label();
if (strtolower(str_replace('_', ' ', $node_type->id())) != strtolower($node_type->label())) {
$options[$node_type->id()] .= ' (' . $node_type->id() . ')';
}
}
asort($options);
return $options;
}
}
Classes
| Title |
Deprecated |
Summary |
| NodeTypeOptions |
|
Options provider to list all node types. |