public function ChangeFormDisplay::execute in Business Rules 8
Same name and namespace in other branches
- 2.x src/Plugin/BusinessRulesAction/ChangeFormDisplay.php \Drupal\business_rules\Plugin\BusinessRulesAction\ChangeFormDisplay::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/ ChangeFormDisplay.php, line 111
Class
- ChangeFormDisplay
- Class ChangeFormDisplay.
Namespace
Drupal\business_rules\Plugin\BusinessRulesActionCode
public function execute(ActionInterface $action, BusinessRulesEvent $event) {
$variables = $event
->getArgument('variables');
$selection_mode = $action
->getSettings('selection_mode');
$fixed = $action
->getSettings('fixed');
$variable = $action
->getSettings('variable');
$variable = $this
->processVariables($variable, $variables);
// Remove the first part of the machine name id it's on the variable value.
$arr = explode('.', $variable);
$variable = isset($arr[1]) ? $arr[1] : $arr[0];
$entity_type = $event
->getArgument('entity_type_id');
$bundle = $event
->getArgument('bundle');
$form_display_mode = $selection_mode == 'fixed' ? $fixed : $variable;
$form_display = \Drupal::entityTypeManager()
->getStorage('entity_form_display')
->load($entity_type . '.' . $bundle . '.' . $form_display_mode);
$event
->setArgument('form_display', $form_display);
$result = [
'#type' => 'markup',
'#markup' => t('Form display changed to: %form_display, on entity type: %entity_type, bundle: %bundle.', [
'%form_display' => $form_display_mode,
'%entity_type' => $entity_type,
'%bundle' => $bundle,
]),
];
return $result;
}