Add subject data to automation editor registry

[MAILPOET-4946]
This commit is contained in:
Jan Jakes
2023-03-03 15:14:12 +01:00
committed by Aschepikov
parent 0bf9e75dd0
commit 3ed038479a
2 changed files with 49 additions and 1 deletions

View File

@ -20,6 +20,27 @@ export type Registry = {
}; };
} }
>; >;
subjects: Record<
string,
{
key: string;
name: string;
args_schema: {
type: 'object';
properties?: Record<string, { type: string; default?: unknown }>;
};
field_keys: string[];
}
>;
fields: Record<
string,
{
key: string;
type: 'string' | 'enum_array';
name: string;
args: Record<string, unknown>;
}
>;
}; };
export type Context = Record<string, unknown>; export type Context = Record<string, unknown>;

View File

@ -105,7 +105,34 @@ class AutomationEditor {
'args_schema' => $step->getArgsSchema()->toArray(), '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 { private function buildContext(): array {