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 * admin_permission = "administer actions",
32 class Action extends ConfigEntityBase implements ActionConfigEntityInterface, EntityWithPluginCollectionInterface {
35 * The name (plugin ID) of the action.
42 * The label of the action.
56 * The configuration of the action.
60 protected $configuration = [];
63 * The plugin ID of the action.
70 * The plugin collection that stores action plugins.
72 * @var \Drupal\Core\Action\ActionPluginCollection
74 protected $pluginCollection;
77 * Encapsulates the creation of the action's LazyPluginCollection.
79 * @return \Drupal\Component\Plugin\LazyPluginCollection
80 * The action's plugin collection.
82 protected function getPluginCollection() {
83 if (!$this->pluginCollection) {
84 $this->pluginCollection = new ActionPluginCollection(\Drupal::service('plugin.manager.action'), $this->plugin, $this->configuration);
86 return $this->pluginCollection;
92 public function getPluginCollections() {
93 return ['configuration' => $this->getPluginCollection()];
99 public function getPlugin() {
100 return $this->getPluginCollection()->get($this->plugin);
106 public function setPlugin($plugin_id) {
107 $this->plugin = $plugin_id;
108 $this->getPluginCollection()->addInstanceId($plugin_id);
114 public function getPluginDefinition() {
115 return $this->getPlugin()->getPluginDefinition();
121 public function execute(array $entities) {
122 return $this->getPlugin()->executeMultiple($entities);
128 public function isConfigurable() {
129 return $this->getPlugin() instanceof ConfigurablePluginInterface;
135 public function getType() {
142 public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
143 /** @var \Drupal\system\ActionConfigEntityInterface $a */
144 /** @var \Drupal\system\ActionConfigEntityInterface $b */
145 $a_type = $a->getType();
146 $b_type = $b->getType();
147 if ($a_type != $b_type) {
148 return strnatcasecmp($a_type, $b_type);
150 return parent::sort($a, $b);