Newer
Older
<?php
/**
* @file
* Contains \Drupal\system\Entity\Action.
namespace Drupal\system\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Config\Entity\EntityWithPluginBagInterface;
use Drupal\system\ActionConfigEntityInterface;
use Drupal\Core\Action\ActionBag;
use Drupal\Component\Plugin\ConfigurablePluginInterface;
/**
* Defines the configured action entity.
*
Alex Pott
committed
* @ConfigEntityType(
* id = "action",
* label = @Translation("Action"),
* admin_permission = "administer actions",
* entity_keys = {
* "id" = "id",
Dries Buytaert
committed
* "label" = "label"
* }
* )
*/
class Action extends ConfigEntityBase implements ActionConfigEntityInterface, EntityWithPluginBagInterface {
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* The name (plugin ID) of the action.
*
* @var string
*/
public $id;
/**
* The label of the action.
*
* @var string
*/
public $label;
/**
* The action type.
*
* @var string
*/
protected $type;
/**
* The configuration of the action.
*
* @var array
*/
protected $configuration = array();
/**
* The plugin ID of the action.
*
* @var string
*/
protected $plugin;
/**
* The plugin bag that stores action plugins.
*
* @var \Drupal\Core\Action\ActionBag
*/
protected $pluginBag;
/**
* {@inheritdoc}
*/
protected $pluginConfigKey = 'configuration';
/**
* {@inheritdoc}
*/
public function getPluginBag() {
if (!$this->pluginBag) {
$this->pluginBag = new ActionBag(\Drupal::service('plugin.manager.action'), $this->plugin, $this->configuration);
}
return $this->pluginBag;
}
/**
* {@inheritdoc}
*/
public function getPlugin() {
return $this->getPluginBag()->get($this->plugin);
}
/**
* {@inheritdoc}
*/
public function setPlugin($plugin_id) {
$this->plugin = $plugin_id;
$this->getPluginBag()->addInstanceId($plugin_id);
}
/**
* {@inheritdoc}
*/
public function getPluginDefinition() {
Alex Pott
committed
return $this->getPlugin()->getPluginDefinition();
}
/**
* {@inheritdoc}
*/
public function execute(array $entities) {
return $this->getPlugin()->executeMultiple($entities);
}
/**
* {@inheritdoc}
*/
public function isConfigurable() {
return $this->getPlugin() instanceof ConfigurablePluginInterface;
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
}
/**
* {@inheritdoc}
*/
public function getType() {
return $this->type;
}
/**
* {@inheritdoc}
*/
public static function sort($a, $b) {
$a_type = $a->getType();
$b_type = $b->getType();
if ($a_type != $b_type) {
return strnatcasecmp($a_type, $b_type);
}
return parent::sort($a, $b);
}
/**
* {@inheritdoc}
*/
public function getExportProperties() {
$properties = parent::getExportProperties();
$names = array(
'type',
'plugin',
'configuration',
);
foreach ($names as $name) {
$properties[$name] = $this->get($name);
}
return $properties;
}
}