diff --git a/Makefile b/Makefile index e8a8c74..b4a6ed2 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ PLUGIN_NAME=sylius-${COMPOSE_PROJECT_NAME}-plugin COMPOSE=docker-compose YARN=yarn DOCTRINE_MIGRATIONS_NAMESPACE=MonsieurBiz\SyliusContactRequestPlugin\Migrations +DOCTRINE_ORM_CONFLICT_VERSION=">= 2.15.2" ### ### DEVELOPMENT @@ -72,6 +73,9 @@ setup_application: (cd ${APP_DIR} && ${COMPOSER} config minimum-stability dev) (cd ${APP_DIR} && ${COMPOSER} config --no-plugins allow-plugins true) (cd ${APP_DIR} && ${COMPOSER} config --no-plugins --json extra.symfony.endpoint '["https://api.github.com/repos/monsieurbiz/symfony-recipes/contents/index.json?ref=flex/master","flex://defaults"]') +ifdef DOCTRINE_ORM_CONFLICT_VERSION + (cd ${APP_DIR} && cat composer.json | jq --indent 4 '.conflict += {"doctrine/orm": ${DOCTRINE_ORM_CONFLICT_VERSION}}' > composer.json.tmp && mv composer.json.tmp composer.json) +endif (cd ${APP_DIR} && ${COMPOSER} require --no-install --no-scripts --no-progress sylius/sylius="~${SYLIUS_VERSION}") # Make sure to install the required version of sylius because the sylius-standard has a soft constraint $(MAKE) ${APP_DIR}/.php-version $(MAKE) ${APP_DIR}/php.ini diff --git a/src/EmailManager/DecorateContactEmailManager.php b/src/EmailManager/DecorateContactEmailManager.php index fc77b59..239715e 100644 --- a/src/EmailManager/DecorateContactEmailManager.php +++ b/src/EmailManager/DecorateContactEmailManager.php @@ -12,16 +12,15 @@ namespace MonsieurBiz\SyliusContactRequestPlugin\EmailManager; use Doctrine\ORM\EntityManagerInterface; -use MonsieurBiz\SyliusContactRequestPlugin\Entity\ContactRequestInterface; +use MonsieurBiz\SyliusContactRequestPlugin\Factory\ContactRequestFactoryInterface; use Sylius\Bundle\ShopBundle\EmailManager\ContactEmailManagerInterface; use Sylius\Component\Core\Model\ChannelInterface; -use Sylius\Component\Resource\Factory\FactoryInterface; final class DecorateContactEmailManager implements ContactEmailManagerInterface { public function __construct( private ContactEmailManagerInterface $decoratedContactEmailManager, - private FactoryInterface $contactRequestFactory, + private ContactRequestFactoryInterface $contactRequestFactory, private EntityManagerInterface $contactRequestManager, ) { } @@ -34,12 +33,7 @@ public function sendContactRequest(array $data, array $recipients, ChannelInterf return; } - /** @var ContactRequestInterface $contactRequest */ - $contactRequest = $this->contactRequestFactory->createNew(); - $contactRequest->setEmail($data['email']); - $contactRequest->setMessage($data['message']); - $contactRequest->setChannel($channel); - + $contactRequest = $this->contactRequestFactory->createNewFromChannelAndData($channel, $data); $this->contactRequestManager->persist($contactRequest); $this->contactRequestManager->flush(); } diff --git a/src/Factory/ContactRequestFactory.php b/src/Factory/ContactRequestFactory.php new file mode 100644 index 0000000..5fdda12 --- /dev/null +++ b/src/Factory/ContactRequestFactory.php @@ -0,0 +1,39 @@ + + * 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\Factory; + +use MonsieurBiz\SyliusContactRequestPlugin\Entity\ContactRequestInterface; +use Sylius\Component\Core\Model\ChannelInterface; +use Sylius\Component\Resource\Factory\FactoryInterface; + +final class ContactRequestFactory implements ContactRequestFactoryInterface +{ + public function __construct(private FactoryInterface $factory) + { + } + + public function createNew(): ContactRequestInterface + { + // @phpstan-ignore-next-line + return $this->factory->createNew(); + } + + public function createNewFromChannelAndData(ChannelInterface $channel, array $data): ContactRequestInterface + { + $contactRequest = $this->createNew(); + $contactRequest->setEmail($data['email']); + $contactRequest->setMessage($data['message']); + $contactRequest->setChannel($channel); + + return $contactRequest; + } +} diff --git a/src/Factory/ContactRequestFactoryInterface.php b/src/Factory/ContactRequestFactoryInterface.php new file mode 100644 index 0000000..c1b500c --- /dev/null +++ b/src/Factory/ContactRequestFactoryInterface.php @@ -0,0 +1,24 @@ + + * 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\Factory; + +use MonsieurBiz\SyliusContactRequestPlugin\Entity\ContactRequestInterface; +use Sylius\Component\Core\Model\ChannelInterface; +use Sylius\Component\Resource\Factory\FactoryInterface; + +/** + * @method ContactRequestInterface createNew() + */ +interface ContactRequestFactoryInterface extends FactoryInterface +{ + public function createNewFromChannelAndData(ChannelInterface $channel, array $data): ContactRequestInterface; +} diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml index babb339..5839a42 100644 --- a/src/Resources/config/services.yaml +++ b/src/Resources/config/services.yaml @@ -17,3 +17,9 @@ services: MonsieurBiz\SyliusContactRequestPlugin\Menu\AdminMenuListener: tags: - { name: kernel.event_listener, event: sylius.menu.admin.main, priority: -100 } + + # Custom contact request factory + MonsieurBiz\SyliusContactRequestPlugin\Factory\ContactRequestFactory: + decorates: 'monsieurbiz_contact_request.factory.contact_request' + arguments: [ '@.inner' ] + diff --git a/src/Resources/views/Admin/ContactRequest/Crud/show.html.twig b/src/Resources/views/Admin/ContactRequest/Crud/show.html.twig index 669095a..bc8930c 100644 --- a/src/Resources/views/Admin/ContactRequest/Crud/show.html.twig +++ b/src/Resources/views/Admin/ContactRequest/Crud/show.html.twig @@ -28,6 +28,7 @@
+ {{ sylius_template_event('monsieurbiz_contact.admin.contact_request.before_content', {'resource': resource}) }}

{{ 'monsieurbiz.contact_request.ui.email'|trans }}

{{ resource.email|default('') }} @@ -36,6 +37,7 @@

{{ resource.message|nl2br|default('')|raw }}
+ {{ sylius_template_event('monsieurbiz_contact.admin.contact_request.after_content', {'resource': resource}) }}
{% endblock %}