Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
ffdefc67
Commit
ffdefc67
authored
Jul 6, 2014
by
Alex Pott
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2281325
by kim.pepper: NodeType condition should use EntityManager.
parent
0dc696df
No related branches found
No related tags found
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/modules/node/src/Plugin/Condition/NodeType.php
+48
-5
48 additions, 5 deletions
core/modules/node/src/Plugin/Condition/NodeType.php
with
48 additions
and
5 deletions
core/modules/node/src/Plugin/Condition/NodeType.php
+
48
−
5
View file @
ffdefc67
...
...
@@ -8,6 +8,9 @@
namespace
Drupal\node\Plugin\Condition
;
use
Drupal\Core\Condition\ConditionPluginBase
;
use
Drupal\Core\Entity\EntityStorageInterface
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* Provides a 'Node Type' condition.
...
...
@@ -21,18 +24,58 @@
* )
*
*/
class
NodeType
extends
ConditionPluginBase
{
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
);
$this
->
entityStorage
=
$entity_storage
;
}
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
$plugin_definition
)
{
return
new
static
(
$container
->
get
(
'entity.manager'
)
->
getStorage
(
'node_type'
),
$configuration
,
$plugin_id
,
$plugin_definition
);
}
/**
* {@inheritdoc}
*/
public
function
buildConfigurationForm
(
array
$form
,
array
&
$form_state
)
{
$options
=
array
();
foreach
(
node_type_get_types
()
as
$type
)
{
$node_types
=
$this
->
entityStorage
->
loadMultiple
();
foreach
(
$node_types
as
$type
)
{
$options
[
$type
->
type
]
=
$type
->
name
;
}
$form
[
'bundles'
]
=
array
(
'#title'
=>
t
(
'Node types'
),
'#title'
=>
$this
->
t
(
'Node types'
),
'#type'
=>
'checkboxes'
,
'#options'
=>
$options
,
'#default_value'
=>
$this
->
configuration
[
'bundles'
],
...
...
@@ -56,10 +99,10 @@ public function summary() {
$bundles
=
$this
->
configuration
[
'bundles'
];
$last
=
array_pop
(
$bundles
);
$bundles
=
implode
(
', '
,
$bundles
);
return
t
(
'The node bundle is @bundles or @last'
,
array
(
'@bundles'
=>
$bundles
,
'@last'
=>
$last
));
return
$this
->
t
(
'The node bundle is @bundles or @last'
,
array
(
'@bundles'
=>
$bundles
,
'@last'
=>
$last
));
}
$bundle
=
reset
(
$this
->
configuration
[
'bundles'
]);
return
t
(
'The node bundle is @bundle'
,
array
(
'@bundle'
=>
$bundle
));
return
$this
->
t
(
'The node bundle is @bundle'
,
array
(
'@bundle'
=>
$bundle
));
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment