-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ContactRequest): Add fields in contact form + settings to displa…
…y them or no, make them required or no
- Loading branch information
Etienne Gutbub
committed
Oct 4, 2024
1 parent
9643d20
commit 54dd21c
Showing
14 changed files
with
303 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz' Contact Request plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <[email protected]> | ||
* | ||
* 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 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', 'field_name_displayed'); | ||
$isCompanyRequired = $this->isFieldRequired('field_company_required', 'field_company_displayed'); | ||
$isPhoneNumberRequired = $this->isFieldRequired('field_phone_number_required', 'field_phone_number_displayed'); | ||
|
||
$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, string $pathDisplayed): bool | ||
{ | ||
return $this->settingProvider->getSettingValue('monsieurbiz_contact_request.contact', $path) | ||
&& $this->settingProvider->getSettingValue('monsieurbiz_contact_request.contact', $pathDisplayed); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Monsieur Biz' Contact Request plugin for Sylius. | ||
* | ||
* (c) Monsieur Biz <[email protected]> | ||
* | ||
* 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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...sources/templates/bundles/SyliusCoreBundle/Email/Blocks/ContactRequest/_content.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<div style="text-align: left;"> | ||
<div style="color: #1abb9c;"> | ||
<strong>{{ 'sylius.email.contact_request.message_from'|trans({}, null, localeCode) }}:</strong> | ||
</div> | ||
<div style="margin-bottom: 20px;">{{ data.email }}</div> | ||
|
||
<div style="color: #1abb9c;"> | ||
<strong>{{ 'monsieurbiz.contact_request.form.name'|trans({}, null, localeCode) }}:</strong> | ||
</div> | ||
<div style="margin-bottom: 20px;">{{ data.name|default('') }}</div> | ||
<div style="color: #1abb9c;"> | ||
<strong>{{ 'monsieurbiz.contact_request.form.company'|trans({}, null, localeCode) }}:</strong> | ||
</div> | ||
<div style="margin-bottom: 20px;">{{ data.company|default('') }}</div> | ||
|
||
<div style="color: #1abb9c;"> | ||
<strong>{{ 'monsieurbiz.contact_request.form.phone_number'|trans({}, null, localeCode) }}:</strong> | ||
</div> | ||
<div style="margin-bottom: 20px;">{{ data.phoneNumber|default('') }}</div> | ||
|
||
<div style="color: #1abb9c;"> | ||
<strong>{{ 'sylius.email.contact_request.content'|trans({}, null, localeCode) }}:</strong> | ||
</div> | ||
<div>{{ data.message|nl2br }}</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters