feat(call-script): add the Call Script component (0.19.0)

A new Mautic component, listed under Components > Call Scripts (/s/call-scripts),
built like the other domains on AbstractStandardFormController/FormModel.

- CallScript (mt3s_call_scripts): name, description, category, owner, status,
the publish window shown as start/end date and time, the HTML script with
dynamic tokens kept as typed (html cleaning mask), the calling window
(weekdays, hours, sentinel in the contact's or a fixed timezone) and the retry
policy (max attempts, delay, backoff: none/linear/exponential)
- CallScriptOutcome (mt3s_call_script_outcomes, ON DELETE CASCADE): label,
data type (checkbox/radio/free text/dropdown), options JSON ({value,label})
and position; nested collections reuse the program-collection JS
- validators: ValidCallingWindow, ValidCallScriptOutcomeOptions, and an atPath
option on EndDateAfterStartDate so its violation lands on publishDown
- config: routes, the Components menu item (parent mautic.core.components),
call_script category type, model alias, call_scripts permissions, version 0.19.0
- migration Version_0_19_0 creates both tables and their FKs immediately
(users/categories SET NULL, outcomes CASCADE), idempotent
- translations en_US/fr_FR, unit tests, readme/AGENTS documentation
This commit is contained in:
alexandre_gain_mt3s committed 2026-11-21 20:58:25 +01:00
1 parent 88256ca345
commit 4fb36eebfc
33 files changed
+2537 -6

No files matched your search

@@ -7,12 +7,27 @@ namespace MauticPlugin\MT3SMarketingProgramBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
/**
* Class constraint for any DateRangeInterface (Plan, Task): when both dates are set, endDate must be
* on or after startDate.
* Class constraint for any DateRangeInterface (Plan, Task, CallScript): when both dates are set, endDate
* must be on or after startDate.
*/
class EndDateAfterStartDate extends Constraint
{
public string $message = 'mt3s.marketing_program.end_date.before_start_date';
/**
* @param string|null $message the violation message
* @param string|null $atPath the form field the violation is attached to; entities whose end
* date is not named "endDate" (like the CallScript's publishDown) override it
*/
public function __construct(
public ?string $message = null,
public ?string $atPath = null,
?array $groups = null,
mixed $payload = null,
) {
parent::__construct(null, $groups, $payload);
$this->message = $message ?? 'mt3s.marketing_program.end_date.before_start_date';
$this->atPath = $atPath ?? 'endDate';
}
public function getTargets(): string
{
@@ -34,7 +34,7 @@ class EndDateAfterStartDateValidator extends ConstraintValidator
}
$this->context->buildViolation($constraint->message)
->atPath('endDate')
->atPath($constraint->atPath)
->addViolation();
}
}
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\MT3SMarketingProgramBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
/**
* The options of a call script outcome: required for the checkbox, radio and dropdown types,
* forbidden for free text, each with a value, and no duplicate values.
*/
class ValidCallScriptOutcomeOptions extends Constraint
{
public string $required = 'mt3s.call_script.outcome.options.required';
public string $freeTextForbidden = 'mt3s.call_script.outcome.options.free_text_forbidden';
public string $valueRequired = 'mt3s.call_script.outcome.options.value_required';
public string $duplicateValue = 'mt3s.call_script.outcome.options.duplicate_value';
public function getTargets(): string
{
return self::CLASS_CONSTRAINT;
}
}
@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\MT3SMarketingProgramBundle\Validator\Constraints;
use MauticPlugin\MT3SMarketingProgramBundle\Entity\CallScriptOutcome;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
class ValidCallScriptOutcomeOptionsValidator extends ConstraintValidator
{
public function validate(mixed $value, Constraint $constraint): void
{
if (!$constraint instanceof ValidCallScriptOutcomeOptions) {
throw new UnexpectedTypeException($constraint, ValidCallScriptOutcomeOptions::class);
}
if (!$value instanceof CallScriptOutcome) {
return;
}
$options = $value->getOptions();
if (!$value->hasOptions()) {
if ([] !== $options) {
$this->context->buildViolation($constraint->freeTextForbidden)
->atPath('options')
->addViolation();
}
return;
}
if ([] === $options) {
$this->context->buildViolation($constraint->required)
->atPath('options')
->addViolation();
return;
}
$seen = [];
foreach ($options as $index => $option) {
if ('' === $option['value']) {
$this->context->buildViolation($constraint->valueRequired)
->atPath('options['.$index.'][value]')
->addViolation();
continue;
}
if (isset($seen[$option['value']])) {
$this->context->buildViolation($constraint->duplicateValue)
->atPath('options['.$index.'][value]')
->addViolation();
continue;
}
$seen[$option['value']] = true;
}
}
}
@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\MT3SMarketingProgramBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
/**
* The calling window of a call script must be consistent: both hours or none, an end after its
* start, and a timezone when the window is read in a fixed timezone.
*/
class ValidCallingWindow extends Constraint
{
public string $partialHours = 'mt3s.call_script.calling_window.partial_hours';
public string $toBeforeFrom = 'mt3s.call_script.calling_window.to_before_from';
public string $timezoneRequired = 'mt3s.call_script.calling_window.timezone_required';
public function getTargets(): string
{
return self::CLASS_CONSTRAINT;
}
}
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\MT3SMarketingProgramBundle\Validator\Constraints;
use MauticPlugin\MT3SMarketingProgramBundle\Entity\CallScript;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
class ValidCallingWindowValidator extends ConstraintValidator
{
public function validate(mixed $value, Constraint $constraint): void
{
if (!$constraint instanceof ValidCallingWindow) {
throw new UnexpectedTypeException($constraint, ValidCallingWindow::class);
}
if (!$value instanceof CallScript) {
return;
}
$from = $value->getCallingFrom();
$to = $value->getCallingTo();
if ((null === $from) !== (null === $to)) {
$this->context->buildViolation($constraint->partialHours)
->atPath('callingFrom')
->addViolation();
return;
}
if (null !== $from && null !== $to && $to <= $from) {
$this->context->buildViolation($constraint->toBeforeFrom)
->atPath('callingTo')
->addViolation();
}
if ($value->getCallingTimezoneMode()->isFixed() && null === $value->getCallingTimezone()) {
$this->context->buildViolation($constraint->timezoneRequired)
->atPath('callingTimezone')
->addViolation();
}
}
}