public function RemoveNodeFromGroupAction::execute in Business Rules 2.x
Same name and namespace in other branches
- 8 modules/br_group/src/Plugin/BusinessRulesAction/RemoveNodeFromGroupAction.php \Drupal\br_group\Plugin\BusinessRulesAction\RemoveNodeFromGroupAction::execute()
Execute the action.
Parameters
\Drupal\business_rules\ActionInterface $action: The configured action.
\Drupal\business_rules\Events\BusinessRulesEvent $event: The event that has triggered the action.
Return value
array The render array to be showed on debug block.
Overrides BusinessRulesActionPlugin::execute
File
- modules/
br_group/ src/ Plugin/ BusinessRulesAction/ RemoveNodeFromGroupAction.php, line 58
Class
- RemoveNodeFromGroupAction
- Class RemoveNodeFromGroupAction.
Namespace
Drupal\br_group\Plugin\BusinessRulesActionCode
public function execute(ActionInterface $action, BusinessRulesEvent $event) {
$variables = $event
->getArgument('variables');
$group_id = $action
->getSettings('group_id');
$group_id = $this
->processVariables($group_id, $variables);
$node_id = $action
->getSettings('node_id');
$node_id = $this
->processVariables($node_id, $variables);
$node = Node::load($node_id);
$group = Group::load($group_id);
if ($node instanceof Node) {
$type = 'group_node:' . $node
->getType();
$current_node = $group
->getContent($type, [
'entity_id' => $node_id,
]);
if (count($current_node)) {
/** @var \Drupal\group\Entity\GroupContent $content */
$content = array_values($current_node)[0];
$content
->delete();
$result = [
'#type' => 'markup',
'#markup' => t('Node %node has been removed from group %group.', [
'%node' => $node
->label(),
'%group' => $group
->label(),
]),
];
}
else {
$result = [
'#type' => 'markup',
'#markup' => t('Node %node is not on group %group.', [
'%node' => $node
->label(),
'%group' => $group
->label(),
]),
];
}
}
else {
$result = [
'#type' => 'markup',
'#markup' => t('Node id %node could not be removed from group %group.', [
'%node' => $node_id,
'%group' => $group
->label(),
]),
];
}
return $result;
}