Namespace
Drupal\action_example\Plugin\Action
File
-
modules/action_example/src/Plugin/Action/BasicExample.php
View source
<?php
namespace Drupal\action_example\Plugin\Action;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Action\ActionBase;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class BasicExample extends ActionBase implements ContainerFactoryPluginInterface {
public function __construct(array $configuration, $plugin_id, $plugin_definition, MessengerInterface $messenger) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->setMessenger($messenger);
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container->get('messenger'));
}
public function execute($object = NULL) {
$this->messenger()
->addMessage($this->t('action_example_basic_action fired'));
}
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
$result = AccessResult::allowed();
return $return_as_object ? $result : $result->isAllowed();
}
}
Classes
| Title |
Deprecated |
Summary |
| BasicExample |
|
A basic example action that does nothing. |