diff --git a/app/bundles/SmsBundle/Entity/Sms.php b/app/bundles/SmsBundle/Entity/Sms.php index 26ac3bad2d4..e5b2f75c65e 100644 --- a/app/bundles/SmsBundle/Entity/Sms.php +++ b/app/bundles/SmsBundle/Entity/Sms.php @@ -3,6 +3,7 @@ namespace Mautic\SmsBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Mautic\ApiBundle\Serializer\Driver\ApiMetadataDriver; use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder; @@ -81,6 +82,11 @@ class Sms extends FormEntity */ private $pendingCount = 0; + /** + * @var array + */ + private $properties = []; + public function __clone() { $this->id = null; @@ -131,6 +137,8 @@ public static function loadMetadata(ORM\ClassMetadata $metadata): void ->columnName('sent_count') ->build(); + $builder->addField('properties', Types::JSON); + $builder->addCategory(); $builder->createManyToMany('lists', \Mautic\LeadBundle\Entity\LeadList::class) @@ -207,6 +215,7 @@ public static function loadApiMetadata(ApiMetadataDriver $metadata): void 'publishUp', 'publishDown', 'sentCount', + 'properties', ] ) ->build(); @@ -459,4 +468,23 @@ public function getPendingCount() { return $this->pendingCount; } + + /** + * @return array> + */ + public function getProperties(): array + { + return $this->properties; + } + + /** + * @param array> $properties + */ + public function setProperties(array $properties): static + { + $this->isChanged('properties', $properties); + $this->properties = $properties; + + return $this; + } } diff --git a/app/bundles/SmsBundle/Event/SmsPropertiesEvent.php b/app/bundles/SmsBundle/Event/SmsPropertiesEvent.php new file mode 100644 index 00000000000..2720eb414cc --- /dev/null +++ b/app/bundles/SmsBundle/Event/SmsPropertiesEvent.php @@ -0,0 +1,40 @@ +formBuilder; + } + + public function getData(): array + { + return $this->data; + } + + public function addField(string $child, string $type = null, array $options = []): void + { + $this->fields[] = [ + 'child' => $child, + 'type' => $type, + 'options' => $options, + ]; + } + + public function getFields(): array + { + return $this->fields; + } +} diff --git a/app/bundles/SmsBundle/Form/Type/SmsPropertiesType.php b/app/bundles/SmsBundle/Form/Type/SmsPropertiesType.php new file mode 100644 index 00000000000..b92ce02a1f3 --- /dev/null +++ b/app/bundles/SmsBundle/Form/Type/SmsPropertiesType.php @@ -0,0 +1,31 @@ +dispatcher = $dispatcher; + } + + public function buildForm(FormBuilderInterface $builder, array $options) + { + $event = new SmsPropertiesEvent($builder, $options['data'] ?? []); + $this->dispatcher->dispatch($event, SmsEvents::SMS_PROPERTIES); + + foreach ($event->getFields() as $formField) { + $builder->add($formField['child'], $formField['type'], $formField['options']); + } + } +} diff --git a/app/bundles/SmsBundle/Form/Type/SmsType.php b/app/bundles/SmsBundle/Form/Type/SmsType.php index 7bd15a7842d..bdb7ebbeb83 100644 --- a/app/bundles/SmsBundle/Form/Type/SmsType.php +++ b/app/bundles/SmsBundle/Form/Type/SmsType.php @@ -104,6 +104,15 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ] ); + $builder->add( + 'properties', + SmsPropertiesType::class, + [ + 'label'=> false, + 'data' => $options['data']->getProperties(), + ] + ); + $builder->add( 'language', LocaleType::class, diff --git a/app/bundles/SmsBundle/SmsEvents.php b/app/bundles/SmsBundle/SmsEvents.php index f02b62b516b..ebafe0613ed 100644 --- a/app/bundles/SmsBundle/SmsEvents.php +++ b/app/bundles/SmsBundle/SmsEvents.php @@ -102,4 +102,13 @@ final class SmsEvents * Mautic\SmsBundle\Event\TokensBuildEvent */ public const ON_SMS_TOKENS_BUILD = 'mautic.sms.on_tokens_build'; + + /** + * The mautic.sms_properties event is dispatched during the configuration in send text message dialog. + * + * The event listener receives a Mautic\SmsBundle\Event\SmsPropertiesEvent instance. + * + * @var string + */ + public const SMS_PROPERTIES = 'mautic.sms_properties'; } diff --git a/app/migrations/Version20240209104703.php b/app/migrations/Version20240209104703.php new file mode 100644 index 00000000000..32a22cca416 --- /dev/null +++ b/app/migrations/Version20240209104703.php @@ -0,0 +1,31 @@ +getTable(MAUTIC_TABLE_PREFIX.'sms_messages'); + if ($smsTable->hasColumn('properties')) { + throw new SkipMigration('Schema includes this migration'); + } + } + + /** + * @throws \Doctrine\DBAL\Schema\SchemaException + */ + public function up(Schema $schema): void + { + $smsTable = $schema->getTable(MAUTIC_TABLE_PREFIX.'sms_messages'); + if (!$smsTable->hasColumn('properties')) { + $this->addSql("ALTER TABLE {$this->prefix}sms_messages ADD properties LONGTEXT NOT NULL COMMENT '(DC2Type:json)'"); + } + } +}