3 namespace Drupal\system\Entity;
5 use Drupal\Core\Config\Entity\ConfigEntityBase;
6 use Drupal\Core\Config\Entity\ConfigEntityInterface;
7 use Drupal\Core\Entity\EntityWithPluginCollectionInterface;
8 use Drupal\system\ActionConfigEntityInterface;
9 use Drupal\Core\Action\ActionPluginCollection;
10 use Drupal\Component\Plugin\ConfigurablePluginInterface;
13 * Defines the configured action entity.
17 * label = @Translation("Action"),
18 * label_collection = @Translation("Actions"),
19 * label_singular = @Translation("action"),
20 * label_plural = @Translation("actions"),
21 * label_count = @PluralTranslation(
22 * singular = "@count action",
23 * plural = "@count actions",
25 * admin_permission = "administer actions",
39 class Action extends ConfigEntityBase implements ActionConfigEntityInterface, EntityWithPluginCollectionInterface {
42 * The name (plugin ID) of the action.
49 * The label of the action.
63 * The configuration of the action.
67 protected $configuration = [];
70 * The plugin ID of the action.
77 * The plugin collection that stores action plugins.
79 * @var \Drupal\Core\Action\ActionPluginCollection
81 protected $pluginCollection;
84 * Encapsulates the creation of the action's LazyPluginCollection.
86 * @return \Drupal\Component\Plugin\LazyPluginCollection
87 * The action's plugin collection.
89 protected function getPluginCollection() {
90 if (!$this->pluginCollection) {
91 $this->pluginCollection = new ActionPluginCollection(\Drupal::service('plugin.manager.action'), $this->plugin, $this->configuration);
93 return $this->pluginCollection;
99 public function getPluginCollections() {
100 return ['configuration' => $this->getPluginCollection()];
106 public function getPlugin() {
107 return $this->getPluginCollection()->get($this->plugin);
113 public function setPlugin($plugin_id) {
114 $this->plugin = $plugin_id;
115 $this->getPluginCollection()->addInstanceId($plugin_id);
121 public function getPluginDefinition() {
122 return $this->getPlugin()->getPluginDefinition();
128 public function execute(array $entities) {
129 return $this->getPlugin()->executeMultiple($entities);
135 public function isConfigurable() {
136 return $this->getPlugin() instanceof ConfigurablePluginInterface;
142 public function getType() {
149 public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
150 /** @var \Drupal\system\ActionConfigEntityInterface $a */
151 /** @var \Drupal\system\ActionConfigEntityInterface $b */
152 $a_type = $a->getType();
153 $b_type = $b->getType();
154 if ($a_type != $b_type) {
155 return strnatcasecmp($a_type, $b_type);
157 return parent::sort($a, $b);