class NodeType
Same name in this branch
- 9 core/modules/node/src/Entity/NodeType.php \Drupal\node\Entity\NodeType
- 9 core/modules/node/src/Plugin/migrate/source/d6/NodeType.php \Drupal\node\Plugin\migrate\source\d6\NodeType
- 9 core/modules/node/src/Plugin/migrate/source/d7/NodeType.php \Drupal\node\Plugin\migrate\source\d7\NodeType
Same name in other branches
- 8.9.x core/modules/node/src/Entity/NodeType.php \Drupal\node\Entity\NodeType
- 8.9.x core/modules/node/src/Plugin/migrate/source/d6/NodeType.php \Drupal\node\Plugin\migrate\source\d6\NodeType
- 8.9.x core/modules/node/src/Plugin/migrate/source/d7/NodeType.php \Drupal\node\Plugin\migrate\source\d7\NodeType
- 8.9.x core/modules/node/src/Plugin/Condition/NodeType.php \Drupal\node\Plugin\Condition\NodeType
- 10 core/modules/node/src/Entity/NodeType.php \Drupal\node\Entity\NodeType
- 10 core/modules/node/src/Plugin/migrate/source/d6/NodeType.php \Drupal\node\Plugin\migrate\source\d6\NodeType
- 10 core/modules/node/src/Plugin/migrate/source/d7/NodeType.php \Drupal\node\Plugin\migrate\source\d7\NodeType
- 11.x core/modules/node/src/Entity/NodeType.php \Drupal\node\Entity\NodeType
- 11.x core/modules/node/src/Plugin/migrate/source/d6/NodeType.php \Drupal\node\Plugin\migrate\source\d6\NodeType
- 11.x core/modules/node/src/Plugin/migrate/source/d7/NodeType.php \Drupal\node\Plugin\migrate\source\d7\NodeType
Provides a 'Node Type' condition.
Plugin annotation
@Condition(
id = "node_type",
label = @Translation("Node Bundle (Deprecated)"),
context_definitions = {
"node" = @ContextDefinition("entity:node", label = @Translation("Node"))
}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
- class \Drupal\Core\Executable\ExecutablePluginBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Executable\ExecutableInterface, \Drupal\Core\Cache\CacheableDependencyInterface, \Drupal\Core\Plugin\ContextAwarePluginInterface uses \Drupal\Core\Plugin\ContextAwarePluginTrait
- class \Drupal\Core\Condition\ConditionPluginBase extends \Drupal\Core\Executable\ExecutablePluginBase implements \Drupal\Core\Condition\ConditionInterface uses \Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait
- class \Drupal\node\Plugin\Condition\NodeType extends \Drupal\Core\Condition\ConditionPluginBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface
- class \Drupal\Core\Condition\ConditionPluginBase extends \Drupal\Core\Executable\ExecutablePluginBase implements \Drupal\Core\Condition\ConditionInterface uses \Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait
- class \Drupal\Core\Executable\ExecutablePluginBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Executable\ExecutableInterface, \Drupal\Core\Cache\CacheableDependencyInterface, \Drupal\Core\Plugin\ContextAwarePluginInterface uses \Drupal\Core\Plugin\ContextAwarePluginTrait
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
Expanded class hierarchy of NodeType
Deprecated
in drupal:9.3.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Entity\Plugin\Condition\EntityBundle instead.
See also
https://www.drupal.org/node/2983299
File
-
core/
modules/ node/ src/ Plugin/ Condition/ NodeType.php, line 27
Namespace
Drupal\node\Plugin\ConditionView source
class NodeType extends ConditionPluginBase implements ContainerFactoryPluginInterface {
/**
* The entity storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $entityStorage;
/**
* Creates a new NodeType instance.
*
* @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
* The entity storage.
* @param array $configuration
* The plugin configuration, i.e. an array with configuration values keyed
* by configuration option name. The special key 'context' may be used to
* initialize the defined contexts by setting it to an array of context
* values keyed by context names.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
*/
public function __construct(EntityStorageInterface $entity_storage, array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
@trigger_error('\\Drupal\\node\\Plugin\\Condition\\NodeType is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use \\Drupal\\Core\\Entity\\Plugin\\Condition\\EntityBundle instead. See https://www.drupal.org/node/2983299', E_USER_DEPRECATED);
$this->entityStorage = $entity_storage;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($container->get('entity_type.manager')
->getStorage('node_type'), $configuration, $plugin_id, $plugin_definition);
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$options = [];
$node_types = $this->entityStorage
->loadMultiple();
foreach ($node_types as $type) {
$options[$type->id()] = $type->label();
}
$form['bundles'] = [
'#title' => $this->t('Node types'),
'#type' => 'checkboxes',
'#options' => $options,
'#default_value' => $this->configuration['bundles'],
];
return parent::buildConfigurationForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['bundles'] = array_filter($form_state->getValue('bundles'));
parent::submitConfigurationForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function summary() {
if (count($this->configuration['bundles']) > 1) {
$bundles = $this->configuration['bundles'];
$last = array_pop($bundles);
$bundles = implode(', ', $bundles);
return $this->t('The node bundle is @bundles or @last', [
'@bundles' => $bundles,
'@last' => $last,
]);
}
$bundle = reset($this->configuration['bundles']);
return $this->t('The node bundle is @bundle', [
'@bundle' => $bundle,
]);
}
/**
* {@inheritdoc}
*/
public function evaluate() {
if (empty($this->configuration['bundles']) && !$this->isNegated()) {
return TRUE;
}
$node = $this->getContextValue('node');
return !empty($this->configuration['bundles'][$node->getType()]);
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'bundles' => [],
] + parent::defaultConfiguration();
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.