Add before step save hook per step key to simplify usage
[MAILPOET-4515]
This commit is contained in:
@ -56,6 +56,7 @@ class UpdateWorkflowController {
|
||||
$this->updateStepsController->updateSteps($workflow, $data['steps']);
|
||||
foreach ($workflow->getSteps() as $step) {
|
||||
$this->hooks->doWorkflowStepBeforeSave($step);
|
||||
$this->hooks->doWorkflowStepByKeyBeforeSave($step);
|
||||
}
|
||||
$changed = true;
|
||||
}
|
||||
|
@ -31,4 +31,8 @@ class Hooks {
|
||||
public function doWorkflowStepBeforeSave(Step $step): void {
|
||||
$this->wordPress->doAction(self::WORKFLOW_STEP_BEFORE_SAVE, $step);
|
||||
}
|
||||
|
||||
public function doWorkflowStepByKeyBeforeSave(Step $step): void {
|
||||
$this->wordPress->doAction(self::WORKFLOW_STEP_BEFORE_SAVE . '/key=' . $step->getKey(), $step);
|
||||
}
|
||||
}
|
||||
|
@ -105,7 +105,8 @@ class Registry {
|
||||
$this->wordPress->addAction(Hooks::WORKFLOW_BEFORE_SAVE, $callback, $priority);
|
||||
}
|
||||
|
||||
public function onBeforeWorkflowStepSave(callable $callback, int $priority = 10): void {
|
||||
$this->wordPress->addAction(Hooks::WORKFLOW_STEP_BEFORE_SAVE, $callback, $priority);
|
||||
public function onBeforeWorkflowStepSave(callable $callback, string $key = null, int $priority = 10): void {
|
||||
$keyPart = $key ? "/key=$key" : '';
|
||||
$this->wordPress->addAction(Hooks::WORKFLOW_STEP_BEFORE_SAVE . $keyPart, $callback, $priority);
|
||||
}
|
||||
}
|
||||
|
@ -119,10 +119,6 @@ class SendEmailAction implements Action {
|
||||
}
|
||||
|
||||
public function saveEmailSettings(Step $step): void {
|
||||
if ($step->getKey() !== $this->getKey()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$args = $step->getArgs();
|
||||
if (!isset($args['email_id'])) {
|
||||
return;
|
||||
|
@ -41,6 +41,9 @@ class MailPoetIntegration implements Integration {
|
||||
$registry->addAction($this->sendEmailAction);
|
||||
|
||||
// sync step args (subject, preheader, etc.) to email settings
|
||||
$registry->onBeforeWorkflowStepSave([$this->sendEmailAction, 'saveEmailSettings']);
|
||||
$registry->onBeforeWorkflowStepSave(
|
||||
[$this->sendEmailAction, 'saveEmailSettings'],
|
||||
$this->sendEmailAction->getKey()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user