Add before step save hook per step key to simplify usage

[MAILPOET-4515]
This commit is contained in:
Jan Jakes
2022-08-02 10:20:36 +02:00
committed by Veljko V
parent 24a63f6448
commit d1fddb85f7
5 changed files with 12 additions and 7 deletions

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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()
);
}
}