class ShowMessage in Business Rules 8
Same name and namespace in other branches
- 2.x src/Plugin/BusinessRulesAction/ShowMessage.php \Drupal\business_rules\Plugin\BusinessRulesAction\ShowMessage
Class ShowMessage.
@package Drupal\business_rules\Plugin\BusinessRulesAction
Plugin annotation
@BusinessRulesAction(
id = "show_message",
label = @Translation("Show a message"),
group = @Translation("System"),
description = @Translation("Show a system message"),
isContextDependent = FALSE,
hasTargetEntity = FALSE,
hasTargetBundle = FALSE,
hasTargetField = FALSE,
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\business_rules\Plugin\BusinessRulesItemPluginBase implements BusinessRulesItemPluginInterface
- class \Drupal\business_rules\Plugin\BusinessRulesActionPlugin implements BusinessRulesActionPluginInterface
- class \Drupal\business_rules\Plugin\BusinessRulesAction\ShowMessage
- class \Drupal\business_rules\Plugin\BusinessRulesActionPlugin implements BusinessRulesActionPluginInterface
- class \Drupal\business_rules\Plugin\BusinessRulesItemPluginBase implements BusinessRulesItemPluginInterface
Expanded class hierarchy of ShowMessage
File
- src/
Plugin/ BusinessRulesAction/ ShowMessage.php, line 29
Namespace
Drupal\business_rules\Plugin\BusinessRulesActionView source
class ShowMessage extends BusinessRulesActionPlugin {
/**
* {@inheritdoc}
*/
public function getSettingsForm(array &$form, FormStateInterface $form_state, ItemInterface $item) {
$settings['message_type'] = [
'#type' => 'select',
'#title' => t('Message Type'),
'#required' => TRUE,
'#default_value' => $item
->getSettings('message_type'),
'#options' => [
'status' => t('Status message'),
'warning' => t('Warning message'),
'error' => t('Error message'),
],
];
$settings['message'] = [
'#type' => 'textarea',
'#title' => t('Message'),
'#description' => t('To use variables on the message, just type the variable machine name as {{variable_id}}.'),
'#required' => TRUE,
'#default_value' => $item
->getSettings('message'),
];
return $settings;
}
/**
* {@inheritdoc}
*/
public function execute(ActionInterface $action, BusinessRulesEvent $event) {
$variables = $event
->getArgument('variables');
$message = $action
->getSettings('message');
$message_type = $action
->getSettings('message_type');
$message = $this
->processVariables($message, $variables);
$message = nl2br($message);
$message = Xss::filterAdmin($message);
$message = new FormattableMarkup($message, []);
drupal_set_message($message, $message_type);
$result = [
'#type' => 'markup',
'#markup' => t('Message type: %type, text: %message showed.', [
'%message' => $message,
'%type' => $message_type,
]),
];
return $result;
}
}