diff --git a/mailpoet/assets/js/src/automation/editor/store/types.ts b/mailpoet/assets/js/src/automation/editor/store/types.ts index 56c031bb02..f48ad3bad5 100644 --- a/mailpoet/assets/js/src/automation/editor/store/types.ts +++ b/mailpoet/assets/js/src/automation/editor/store/types.ts @@ -20,6 +20,27 @@ export type Registry = { }; } >; + subjects: Record< + string, + { + key: string; + name: string; + args_schema: { + type: 'object'; + properties?: Record; + }; + field_keys: string[]; + } + >; + fields: Record< + string, + { + key: string; + type: 'string' | 'enum_array'; + name: string; + args: Record; + } + >; }; export type Context = Record; diff --git a/mailpoet/lib/AdminPages/Pages/AutomationEditor.php b/mailpoet/lib/AdminPages/Pages/AutomationEditor.php index d8a8bf7e34..67d5643f4f 100644 --- a/mailpoet/lib/AdminPages/Pages/AutomationEditor.php +++ b/mailpoet/lib/AdminPages/Pages/AutomationEditor.php @@ -105,7 +105,34 @@ class AutomationEditor { 'args_schema' => $step->getArgsSchema()->toArray(), ]; } - return ['steps' => $steps]; + + $subjects = []; + foreach ($this->registry->getSubjects() as $key => $subject) { + $subjects[$key] = [ + 'key' => $subject->getKey(), + 'name' => $subject->getName(), + 'args_schema' => $subject->getArgsSchema()->toArray(), + 'field_keys' => array_map(function ($field) { + return $field->getKey(); + }, $subject->getFields()), + ]; + } + + $fields = []; + foreach ($this->registry->getFields() as $key => $field) { + $fields[$key] = [ + 'key' => $field->getKey(), + 'type' => $field->getType(), + 'name' => $field->getName(), + 'args' => $field->getArgs(), + ]; + } + + return [ + 'steps' => $steps, + 'subjects' => $subjects, + 'fields' => $fields, + ]; } private function buildContext(): array {