Sends a message to the current user's screen.
@Action(
id = "action_message_action",
label = @Translation("Display a message to the user"),
type = "system"
)
Expanded class hierarchy of MessageAction
class MessageAction extends ConfigurableActionBase {
/**
* @var \Drupal\Core\Utility\Token
*/
protected $token;
/**
* Constructs a MessageAction object.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, Token $token) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->token = $token;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('token'));
}
/**
* {@inheritdoc}
*/
public function execute($entity = NULL) {
if (empty($this->configuration['node'])) {
$this->configuration['node'] = $entity;
}
$message = $this->token
->replace(Xss::filterAdmin($this->configuration['message']), $this->configuration);
drupal_set_message($message);
}
/**
* {@inheritdoc}
*/
protected function getDefaultConfiguration() {
return array(
'message' => '',
);
}
/**
* {@inheritdoc}
*/
public function form(array $form, array &$form_state) {
$form['message'] = array(
'#type' => 'textarea',
'#title' => t('Message'),
'#default_value' => $this->configuration['message'],
'#required' => TRUE,
'#rows' => '8',
'#description' => t('The message to be displayed to the current user. You may include placeholders like [node:title], [user:name], and [comment:body] to represent data that will be different each time message is sent. Not all placeholders will be available in all contexts.'),
);
return $form;
}
/**
* {@inheritdoc}
*/
public function submit(array &$form, array &$form_state) {
$this->configuration['message'] = $form_state['values']['message'];
unset($this->configuration['node']);
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ActionBase:: |
public | function |
Executes the plugin for an array of objects. Overrides ActionInterface:: |
2 |
ConfigurableActionBase:: |
public | function |
Returns this plugin's configuration. Overrides ConfigurableActionInterface:: |
|
ConfigurableActionBase:: |
public | function |
Form validation handler. Overrides ConfigurableActionInterface:: |
2 |
MessageAction:: |
protected | property | ||
MessageAction:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginBase:: |
|
MessageAction:: |
public | function |
Executes the plugin. Overrides ExecutableInterface:: |
|
MessageAction:: |
public | function |
Form constructor. Overrides ConfigurableActionInterface:: |
|
MessageAction:: |
protected | function |
Returns default configuration for this action. Overrides ConfigurableActionBase:: |
|
MessageAction:: |
public | function |
Form submission handler. Overrides ConfigurableActionInterface:: |
|
MessageAction:: |
public | function |
Constructs a MessageAction object. Overrides ConfigurableActionBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
public | function |
Returns the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function |
Returns the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |