From d3fc15400467fb79a0b7e9d5a788f1addadf88b9 Mon Sep 17 00:00:00 2001 From: Maxime Huran Date: Mon, 29 Jul 2024 12:12:14 +0200 Subject: [PATCH] Develop plugin --- .../monsieurbiz_sylius_robots_txt_plugin.yaml | 2 + .../monsieurbiz_sylius_robots_txt_plugin.yaml | 5 +++ src/Controller/.gitignore | 0 src/Controller/RenderController.php | 43 +++++++++++++++++++ src/Form/Type/RobotsTxtType.php | 36 ++++++++++++++++ src/Resources/config/config.yaml | 2 + .../config/monsieurbiz/settings.yaml | 14 ++++++ src/Resources/config/routes/admin.yaml | 0 src/Resources/config/routes/shop.yaml | 0 src/translations/messages.en.yaml | 7 +++ src/translations/messages.fr.yaml | 7 +++ 11 files changed, 116 insertions(+) create mode 100644 dist/config/packages/monsieurbiz_sylius_robots_txt_plugin.yaml create mode 100644 dist/config/routes/monsieurbiz_sylius_robots_txt_plugin.yaml delete mode 100644 src/Controller/.gitignore create mode 100644 src/Controller/RenderController.php create mode 100644 src/Form/Type/RobotsTxtType.php create mode 100644 src/Resources/config/monsieurbiz/settings.yaml delete mode 100644 src/Resources/config/routes/admin.yaml delete mode 100644 src/Resources/config/routes/shop.yaml create mode 100644 src/translations/messages.en.yaml create mode 100644 src/translations/messages.fr.yaml diff --git a/dist/config/packages/monsieurbiz_sylius_robots_txt_plugin.yaml b/dist/config/packages/monsieurbiz_sylius_robots_txt_plugin.yaml new file mode 100644 index 0000000..c007128 --- /dev/null +++ b/dist/config/packages/monsieurbiz_sylius_robots_txt_plugin.yaml @@ -0,0 +1,2 @@ +imports: + resource: '@MonsieurBizSyliusRobotsTxtPlugin/Resources/config/config.yaml' diff --git a/dist/config/routes/monsieurbiz_sylius_robots_txt_plugin.yaml b/dist/config/routes/monsieurbiz_sylius_robots_txt_plugin.yaml new file mode 100644 index 0000000..994d93b --- /dev/null +++ b/dist/config/routes/monsieurbiz_sylius_robots_txt_plugin.yaml @@ -0,0 +1,5 @@ +monsieurbiz_robots_txt_render: + path: /robots.txt + methods: [ GET ] + defaults: + _controller: MonsieurBiz\SyliusRobotsTxtPlugin\Controller\RenderController diff --git a/src/Controller/.gitignore b/src/Controller/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/src/Controller/RenderController.php b/src/Controller/RenderController.php new file mode 100644 index 0000000..20cd0ae --- /dev/null +++ b/src/Controller/RenderController.php @@ -0,0 +1,43 @@ + + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace MonsieurBiz\SyliusRobotsTxtPlugin\Controller; + +use MonsieurBiz\SyliusSettingsPlugin\Settings\SettingsInterface; +use Sylius\Component\Channel\Context\ChannelContextInterface; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\Response; +use Webmozart\Assert\Assert; + +final class RenderController extends AbstractController +{ + public function __invoke( + SettingsInterface $robotstxtSettings, + ChannelContextInterface $channelContext, + ): Response { + $robotsTxtContent = $robotstxtSettings->getCurrentValue( + $channelContext->getChannel(), + null, + 'robots_txt_content' + ); + + Assert::string($robotsTxtContent); + $robotsTxtContent = trim($robotsTxtContent); + + if (empty($robotsTxtContent)) { + throw $this->createNotFoundException(); + } + + return new Response($robotsTxtContent, Response::HTTP_OK, [ + 'Content-Type' => 'text/plain', + ]); + } +} diff --git a/src/Form/Type/RobotsTxtType.php b/src/Form/Type/RobotsTxtType.php new file mode 100644 index 0000000..3dd3995 --- /dev/null +++ b/src/Form/Type/RobotsTxtType.php @@ -0,0 +1,36 @@ + + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace MonsieurBiz\SyliusRobotsTxtPlugin\Form\Type; + +use MonsieurBiz\SyliusSettingsPlugin\Form\AbstractSettingsType; +use MonsieurBiz\SyliusSettingsPlugin\Form\SettingsTypeInterface; +use Symfony\Component\Form\Extension\Core\Type\TextareaType; +use Symfony\Component\Form\FormBuilderInterface; + +final class RobotsTxtType extends AbstractSettingsType implements SettingsTypeInterface +{ + /** + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function buildForm(FormBuilderInterface $builder, array $options): void + { + $this->addWithDefaultCheckbox( + $builder, + 'robots_txt_content', + TextareaType::class, + [ + 'label' => 'monsieurbiz_robots_txt.form.robots_txt_content', + 'required' => false, + ] + ); + } +} diff --git a/src/Resources/config/config.yaml b/src/Resources/config/config.yaml index e69de29..f7bf4e6 100644 --- a/src/Resources/config/config.yaml +++ b/src/Resources/config/config.yaml @@ -0,0 +1,2 @@ +imports: + - { resource: 'monsieurbiz/*.yaml' } diff --git a/src/Resources/config/monsieurbiz/settings.yaml b/src/Resources/config/monsieurbiz/settings.yaml new file mode 100644 index 0000000..c7d35eb --- /dev/null +++ b/src/Resources/config/monsieurbiz/settings.yaml @@ -0,0 +1,14 @@ +monsieurbiz_sylius_settings: + plugins: + monsieurbiz_robots_txt.robotstxt: + vendor_name: Monsieur Biz + plugin_name: monsieurbiz_robots_txt.settings.robots_txt.plugin_name + description: monsieurbiz_robots_txt.settings.robots_txt.description + icon: searchengin + use_locales: false + classes: + form: MonsieurBiz\SyliusRobotsTxtPlugin\Form\Type\RobotsTxtType + default_values: + robots_txt_content: | + User-agent: * + Disallow: diff --git a/src/Resources/config/routes/admin.yaml b/src/Resources/config/routes/admin.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/src/Resources/config/routes/shop.yaml b/src/Resources/config/routes/shop.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/src/translations/messages.en.yaml b/src/translations/messages.en.yaml new file mode 100644 index 0000000..fab87fc --- /dev/null +++ b/src/translations/messages.en.yaml @@ -0,0 +1,7 @@ +monsieurbiz_robots_txt: + form: + robots_txt_content: 'Robots Txt content' + settings: + robots_txt: + plugin_name: Robots Txt + description: Edit your robots.txt file diff --git a/src/translations/messages.fr.yaml b/src/translations/messages.fr.yaml new file mode 100644 index 0000000..d28fd08 --- /dev/null +++ b/src/translations/messages.fr.yaml @@ -0,0 +1,7 @@ +monsieurbiz_robots_txt: + form: + robots_txt_content: 'Contenu du Robots Txt' + settings: + robots_txt: + plugin_name: Robots Txt + description: Editez votre fichier robots.txt