Skip to content

Commit

Permalink
Develop plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
maximehuran committed Jul 29, 2024
1 parent 4bf57df commit d3fc154
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
imports:
resource: '@MonsieurBizSyliusRobotsTxtPlugin/Resources/config/config.yaml'
5 changes: 5 additions & 0 deletions dist/config/routes/monsieurbiz_sylius_robots_txt_plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
monsieurbiz_robots_txt_render:
path: /robots.txt
methods: [ GET ]
defaults:
_controller: MonsieurBiz\SyliusRobotsTxtPlugin\Controller\RenderController
Empty file removed src/Controller/.gitignore
Empty file.
43 changes: 43 additions & 0 deletions src/Controller/RenderController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/*
* This file is part of Monsieur Biz's Sylius Robots Txt Plugin for Sylius.
* (c) Monsieur Biz <sylius@monsieurbiz.com>
* 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',
]);
}
}
36 changes: 36 additions & 0 deletions src/Form/Type/RobotsTxtType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of Monsieur Biz's Sylius Robots Txt Plugin for Sylius.
* (c) Monsieur Biz <sylius@monsieurbiz.com>
* 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,
]
);
}
}
2 changes: 2 additions & 0 deletions src/Resources/config/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
imports:
- { resource: 'monsieurbiz/*.yaml' }
14 changes: 14 additions & 0 deletions src/Resources/config/monsieurbiz/settings.yaml
Original file line number Diff line number Diff line change
@@ -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:
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions src/translations/messages.en.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions src/translations/messages.fr.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d3fc154

Please sign in to comment.