public function ChangeFieldInfo::execute in Business Rules 2.x
Same name and namespace in other branches
- 8 src/Plugin/BusinessRulesAction/ChangeFieldInfo.php \Drupal\business_rules\Plugin\BusinessRulesAction\ChangeFieldInfo::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
- src/
Plugin/ BusinessRulesAction/ ChangeFieldInfo.php, line 307
Class
- ChangeFieldInfo
- Class ChangeFieldInfo.
Namespace
Drupal\business_rules\Plugin\BusinessRulesActionCode
public function execute(ActionInterface $action, BusinessRulesEvent $event) {
$fields = $action
->getSettings('fields');
if (!count($fields)) {
// Nothing to do.
$result = [
'#type' => 'markup',
'#markup' => t('Nothing to do.'),
];
return $result;
}
$element = $event
->getArgument('element');
$context = $event
->getArgument('context');
/** @var \Drupal\Core\Field\FieldItemList $items */
$items = $context['items'];
$element_name = $items
->getName();
// Change the field properties.
foreach ($fields as $field) {
if ($field['field'] == $element_name) {
$this
->changeFieldInfo($element, $field);
}
}
$event
->setArgument('element', $element);
foreach ($fields as $field) {
$debug_message = t('<br>%method: %field', [
'%field' => $field['field'],
'%method' => $this->actionOptions[$field['action']],
]);
$result[] = [
'#type' => 'markup',
'#markup' => $debug_message,
];
}
return $result;
}