diff --git a/phpstan.neon b/phpstan.neon
index 942036d..e37ca81 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -13,3 +13,4 @@ parameters:
ignoreErrors:
- identifier: missingType.generics
- identifier: missingType.iterableValue
+ reportUnmatchedIgnoredErrors: false
diff --git a/src/Entity/ContactRequest.php b/src/Entity/ContactRequest.php
index 01843f0..6c81069 100644
--- a/src/Entity/ContactRequest.php
+++ b/src/Entity/ContactRequest.php
@@ -27,6 +27,12 @@ class ContactRequest implements ContactRequestInterface
private ?string $message;
+ private ?string $name;
+
+ private ?string $company;
+
+ private ?string $phoneNumber;
+
private ?ChannelInterface $channel;
/**
@@ -93,4 +99,34 @@ public function setUpdatedAt(?DateTimeInterface $updatedAt): void
{
$this->updatedAt = $updatedAt;
}
+
+ public function getName(): ?string
+ {
+ return $this->name;
+ }
+
+ public function setName(?string $name): void
+ {
+ $this->name = $name;
+ }
+
+ public function getCompany(): ?string
+ {
+ return $this->company;
+ }
+
+ public function setCompany(?string $company): void
+ {
+ $this->company = $company;
+ }
+
+ public function getPhoneNumber(): ?string
+ {
+ return $this->phoneNumber;
+ }
+
+ public function setPhoneNumber(?string $phoneNumber): void
+ {
+ $this->phoneNumber = $phoneNumber;
+ }
}
diff --git a/src/Entity/ContactRequestInterface.php b/src/Entity/ContactRequestInterface.php
index d2881d8..095818d 100644
--- a/src/Entity/ContactRequestInterface.php
+++ b/src/Entity/ContactRequestInterface.php
@@ -41,4 +41,16 @@ public function setCreatedAt(?DateTimeInterface $createdAt): void;
public function getUpdatedAt(): ?DateTimeInterface;
public function setUpdatedAt(?DateTimeInterface $updatedAt): void;
+
+ public function getName(): ?string;
+
+ public function setName(?string $name): void;
+
+ public function getCompany(): ?string;
+
+ public function setCompany(?string $company): void;
+
+ public function getPhoneNumber(): ?string;
+
+ public function setPhoneNumber(?string $phoneNumber): void;
}
diff --git a/src/Factory/ContactRequestFactory.php b/src/Factory/ContactRequestFactory.php
index e683554..b38d48f 100644
--- a/src/Factory/ContactRequestFactory.php
+++ b/src/Factory/ContactRequestFactory.php
@@ -34,6 +34,9 @@ public function createNewFromChannelAndData(ChannelInterface $channel, array $da
$contactRequest = $this->createNew();
$contactRequest->setEmail($data['email']);
$contactRequest->setMessage($data['message']);
+ $contactRequest->setName($data['name'] ?? null);
+ $contactRequest->setCompany($data['company'] ?? null);
+ $contactRequest->setPhoneNumber($data['phoneNumber'] ?? null);
$contactRequest->setChannel($channel);
return $contactRequest;
diff --git a/src/Form/Extension/ContactTypeExtension.php b/src/Form/Extension/ContactTypeExtension.php
new file mode 100644
index 0000000..221a3b7
--- /dev/null
+++ b/src/Form/Extension/ContactTypeExtension.php
@@ -0,0 +1,78 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE.txt
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace MonsieurBiz\SyliusContactRequestPlugin\Form\Extension;
+
+use MonsieurBiz\SyliusSettingsPlugin\Provider\SettingsProviderInterface;
+use Sylius\Bundle\CoreBundle\Form\Type\ContactType;
+use Symfony\Component\Form\AbstractTypeExtension;
+use Symfony\Component\Form\Extension\Core\Type\TelType;
+use Symfony\Component\Form\Extension\Core\Type\TextType;
+use Symfony\Component\Form\FormBuilderInterface;
+use Symfony\Component\Validator\Constraints as Assert;
+
+final class ContactTypeExtension extends AbstractTypeExtension
+{
+ public function __construct(
+ private readonly SettingsProviderInterface $settingProvider,
+ ) {
+ }
+
+ public function buildForm(FormBuilderInterface $builder, array $options): void
+ {
+ parent::buildForm($builder, $options);
+
+ $defaultConstraints = [
+ new Assert\Length(['max' => 255]),
+ ];
+
+ $requiredConstraints = [
+ new Assert\NotBlank(),
+ new Assert\Length(['max' => 255]),
+ ];
+
+ $isNameRequired = $this->isFieldRequired('field_name_required');
+ $isCompanyRequired = $this->isFieldRequired('field_company_required');
+ $isPhoneNumberRequired = $this->isFieldRequired('field_phone_number_required');
+
+ $builder
+ ->add('name', TextType::class, [
+ 'label' => 'monsieurbiz.contact_request.form.name',
+ 'required' => $isNameRequired,
+ 'constraints' => $isNameRequired ? $requiredConstraints : $defaultConstraints,
+ ])
+ ->add('company', TextType::class, [
+ 'label' => 'monsieurbiz.contact_request.form.company',
+ 'required' => $isCompanyRequired,
+ 'constraints' => $isCompanyRequired ? $requiredConstraints : $defaultConstraints,
+ ])
+ ->add('phoneNumber', TelType::class, [
+ 'label' => 'monsieurbiz.contact_request.form.phone_number',
+ 'required' => $isPhoneNumberRequired,
+ 'constraints' => $isPhoneNumberRequired ? $requiredConstraints : $defaultConstraints,
+ ])
+ ;
+ }
+
+ public static function getExtendedTypes(): iterable
+ {
+ return [
+ ContactType::class,
+ ];
+ }
+
+ private function isFieldRequired(string $path): bool
+ {
+ return $this->settingProvider->getSettingValue('monsieurbiz_contact_request.contact', $path);
+ }
+}
diff --git a/src/Form/Type/ContactSettingsType.php b/src/Form/Type/ContactSettingsType.php
index 2595bb9..c96ec6b 100644
--- a/src/Form/Type/ContactSettingsType.php
+++ b/src/Form/Type/ContactSettingsType.php
@@ -24,6 +24,7 @@ final class ContactSettingsType extends AbstractSettingsType implements Settings
{
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
@@ -47,10 +48,55 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
);
$this->addWithDefaultCheckbox(
$builder,
- 'meta_title',
- TextType::class,
+ 'field_name_displayed',
+ CheckboxType::class,
+ [
+ 'label' => 'monsieurbiz.contact_request.settings.field_name_displayed',
+ 'required' => false,
+ ]
+ );
+ $this->addWithDefaultCheckbox(
+ $builder,
+ 'field_name_required',
+ CheckboxType::class,
+ [
+ 'label' => 'monsieurbiz.contact_request.settings.field_name_required',
+ 'required' => false,
+ ]
+ );
+ $this->addWithDefaultCheckbox(
+ $builder,
+ 'field_company_displayed',
+ CheckboxType::class,
+ [
+ 'label' => 'monsieurbiz.contact_request.settings.field_company_displayed',
+ 'required' => false,
+ ]
+ );
+ $this->addWithDefaultCheckbox(
+ $builder,
+ 'field_company_required',
+ CheckboxType::class,
+ [
+ 'label' => 'monsieurbiz.contact_request.settings.field_company_required',
+ 'required' => false,
+ ]
+ );
+ $this->addWithDefaultCheckbox(
+ $builder,
+ 'field_phone_number_displayed',
+ CheckboxType::class,
+ [
+ 'label' => 'monsieurbiz.contact_request.settings.field_phone_number_displayed',
+ 'required' => false,
+ ]
+ );
+ $this->addWithDefaultCheckbox(
+ $builder,
+ 'field_phone_number_required',
+ CheckboxType::class,
[
- 'label' => 'monsieurbiz.contact_request.ui.meta_title',
+ 'label' => 'monsieurbiz.contact_request.settings.field_phone_number_required',
'required' => false,
]
);
diff --git a/src/Migrations/Version20241003154058.php b/src/Migrations/Version20241003154058.php
new file mode 100644
index 0000000..b0cb803
--- /dev/null
+++ b/src/Migrations/Version20241003154058.php
@@ -0,0 +1,40 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE.txt
+ * file that was distributed with this source code.
+ */
+
+declare(strict_types=1);
+
+namespace MonsieurBiz\SyliusContactRequestPlugin\Migrations;
+
+use Doctrine\DBAL\Schema\Schema;
+use Doctrine\Migrations\AbstractMigration;
+
+/**
+ * Auto-generated Migration: Please modify to your needs!
+ */
+final class Version20241003154058 extends AbstractMigration
+{
+ public function getDescription(): string
+ {
+ return '';
+ }
+
+ public function up(Schema $schema): void
+ {
+ // this up() migration is auto-generated, please modify it to your needs
+ $this->addSql('ALTER TABLE monsieurbiz_contact_request ADD name VARCHAR(255) DEFAULT NULL, ADD company VARCHAR(255) DEFAULT NULL, ADD phone_number VARCHAR(255) DEFAULT NULL');
+ }
+
+ public function down(Schema $schema): void
+ {
+ // this down() migration is auto-generated, please modify it to your needs
+ $this->addSql('ALTER TABLE monsieurbiz_contact_request DROP name, DROP company, DROP phone_number');
+ }
+}
diff --git a/src/Resources/config/doctrine/ContactRequest.orm.xml b/src/Resources/config/doctrine/ContactRequest.orm.xml
index 6600006..2f9dfe3 100644
--- a/src/Resources/config/doctrine/ContactRequest.orm.xml
+++ b/src/Resources/config/doctrine/ContactRequest.orm.xml
@@ -11,6 +11,9 @@
{{ resource.email|default('') }}
++ {{ resource.name|default('') }} +
++ {{ resource.company|default('') }} +
++ {{ resource.phone_number|default('') }} +
++ {{ resource.email|default('') }} +