Skip to content

Commit

Permalink
feat(sitemap): Add a property to Page to include it in sitemap or not
Browse files Browse the repository at this point in the history
  • Loading branch information
welcoMattic committed Oct 9, 2024
1 parent 8739c74 commit abce8bb
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 66 deletions.
15 changes: 15 additions & 0 deletions src/Entity/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class Page implements PageInterface
*/
protected $updatedAt;

/**
* @var bool
*/
protected $showInSitemap = true;

/**
* Page constructor.
*/
Expand Down Expand Up @@ -185,6 +190,16 @@ public function setSlug(?string $slug): void
$this->getTranslation()->setSlug($slug);
}

public function isShowInSitemap(): bool
{
return $this->showInSitemap;
}

public function setShowInSitemap(bool $showInSitemap): void
{
$this->showInSitemap = $showInSitemap;
}

/**
* @inheritdoc
*/
Expand Down
4 changes: 4 additions & 0 deletions src/Entity/PageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ public function setMetaKeywords(?string $metaKeywords): void;
public function getMetaImage(): ?string;

public function setMetaImage(?string $metaImage): void;

public function isShowInSitemap(): bool;

public function setShowInSitemap(bool $showInSitemap): void;
}
4 changes: 4 additions & 0 deletions src/Fixture/Factory/PageFixtureFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function create(array $options = []): PageInterface
/** @var PageInterface $page */
$page = $this->pageFactory->createNew();
$page->setEnabled($options['enabled']);
$page->setShowInSitemap($options['showInSitemap']);
$page->setCode($options['code']);

foreach ($options['channels'] as $channel) {
Expand Down Expand Up @@ -120,6 +121,9 @@ protected function configureOptions(OptionsResolver $resolver): void
->setDefault('enabled', function (Options $options): bool {
return $this->faker->boolean(80);
})
->setDefault('showInSitemap', function (Options $options): bool {
return $this->faker->boolean(90);
})
->setDefault('code', function (Options $options): string {
return $this->slugGenerator->generate($this->faker->sentence(2, true));
})
Expand Down
1 change: 1 addition & 0 deletions src/Fixture/PageFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected function configureResourceNode(ArrayNodeDefinition $resourceNode): voi
$resourceNode
->children()
->booleanNode('enabled')->end()
->booleanNode('showInSitemap')->end()
->scalarNode('code')->cannotBeEmpty()->end()
->arrayNode('channels')
->scalarPrototype()->end()
Expand Down
4 changes: 4 additions & 0 deletions src/Form/Type/PageType.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'multiple' => true,
'expanded' => true,
])
->add('showInSitemap', CheckboxType::class, [
'label' => 'monsieurbiz_cms_page.ui.form.show_in_sitemap',
'required' => false,
])
->add('translations', ResourceTranslationsType::class, [
'entry_type' => PageTranslationType::class,
])
Expand Down
42 changes: 42 additions & 0 deletions src/Migrations/Version20241009132657.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* This file is part of Monsieur Biz' Cms Page 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\SyliusCmsPagePlugin\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20241009132657 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_cms_page ADD showInSitemap TINYINT(1) DEFAULT 1 NOT NULL');
$this->addSql('ALTER TABLE messenger_messages CHANGE created_at created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', CHANGE available_at available_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', CHANGE delivered_at delivered_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\'');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE messenger_messages CHANGE created_at created_at DATETIME NOT NULL, CHANGE available_at available_at DATETIME NOT NULL, CHANGE delivered_at delivered_at DATETIME DEFAULT NULL');
$this->addSql('ALTER TABLE monsieurbiz_cms_page DROP showInSitemap');
}
}
5 changes: 5 additions & 0 deletions src/Resources/config/doctrine/Page.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
<option name="default">1</option>
</options>
</field>
<field name="showInSitemap" type="boolean">
<options>
<option name="default">1</option>
</options>
</field>
<field name="createdAt" column="created_at" type="datetime_immutable">
<gedmo:timestampable on="create"/>
</field>
Expand Down
67 changes: 34 additions & 33 deletions src/Resources/translations/messages.en.yaml
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
monsieurbiz_cms_page:
ui:
pages: "Pages"
new_page: "New page"
edit_page: "Edit page"
cms_content: "CMS content"
pages_subheader: "CMS Page management"
back_to_admin: "Back to admin"
form:
id: 'ID'
page_info: 'Page information'
page_content: 'Page content'
enabled: "Enabled"
channels: "Channels"
title: "Title"
slug: "Slug"
code: "Code"
content: "Content"
meta_title: "Meta Title"
meta_description: "Meta Description"
meta_keywords: "Meta Keyword"
meta_image: "Meta Image"
meta_image_help: "Ideal format: 1200 x 630 px"
show_in: "Show in"
show_page_in_shop_page: "Show page in shop page"
actions:
create: 'Create a new page'
preview: 'Preview'
banner:
preview: 'Preview'
ui:
pages: "Pages"
new_page: "New page"
edit_page: "Edit page"
cms_content: "CMS content"
pages_subheader: "CMS Page management"
back_to_admin: "Back to admin"
form:
id: 'ID'
page_info: 'Page information'
page_content: 'Page content'
enabled: "Enabled"
channels: "Channels"
title: "Title"
slug: "Slug"
code: "Code"
content: "Content"
meta_title: "Meta Title"
meta_description: "Meta Description"
meta_keywords: "Meta Keyword"
meta_image: "Meta Image"
meta_image_help: "Ideal format: 1200 x 630 px"
show_in_sitemap: "Show in sitemap"
show_in: "Show in"
show_page_in_shop_page: "Show page in shop page"
actions:
create: 'Create a new page'
preview: 'Preview'
banner:
preview: 'Preview'
monsieurbiz_menu:
provider:
page: 'Page'
sylius_plus:
rbac:
parent:
page: 'Page'
pages: 'Pages'
rbac:
parent:
page: 'Page'
pages: 'Pages'
67 changes: 34 additions & 33 deletions src/Resources/translations/messages.fr.yaml
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
monsieurbiz_cms_page:
ui:
pages: "Pages"
new_page: "Nouvelle page"
edit_page: "Éditer une page"
cms_content: "Contenus CMS"
pages_subheader: "Gestion des contenus CMS"
back_to_admin: "Retour à l'admin"
form:
id: 'ID'
page_info: 'Informations de la page'
page_content: 'Contenu de la page'
enabled: "Activée"
channels: "Canaux"
title: "Titre"
slug: "Slug"
code: "Code"
content: "Contenu"
meta_title: "Meta Title"
meta_description: "Meta Description"
meta_keywords: "Meta Keyword"
meta_image: "Meta Image"
meta_image_help: "Format idéal : 1200 x 630 px"
show_in: "Afficher dans"
show_page_in_shop_page: "Afficher la page dans la boutique"
actions:
create: 'Créer une nouvelle page'
preview: 'Prévisualiser'
banner:
preview: 'Prévisualisation'
ui:
pages: "Pages"
new_page: "Nouvelle page"
edit_page: "Éditer une page"
cms_content: "Contenus CMS"
pages_subheader: "Gestion des contenus CMS"
back_to_admin: "Retour à l'admin"
form:
id: 'ID'
page_info: 'Informations de la page'
page_content: 'Contenu de la page'
enabled: "Activée"
channels: "Canaux"
title: "Titre"
slug: "Slug"
code: "Code"
content: "Contenu"
meta_title: "Meta Title"
meta_description: "Meta Description"
meta_keywords: "Meta Keyword"
meta_image: "Meta Image"
meta_image_help: "Format idéal : 1200 x 630 px"
show_in_sitemap: "Afficher dans le sitemap"
show_in: "Afficher dans"
show_page_in_shop_page: "Afficher la page dans la boutique"
actions:
create: 'Créer une nouvelle page'
preview: 'Prévisualiser'
banner:
preview: 'Prévisualisation'
monsieurbiz_menu:
provider:
page: 'Page'
sylius_plus:
rbac:
parent:
page: 'Page'
pages: 'Pages'
rbac:
parent:
page: 'Page'
pages: 'Pages'
1 change: 1 addition & 0 deletions src/Resources/translations/messages.pl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ monsieurbiz_cms_page:
meta_keywords: "Słowa kluczowe meta"
meta_image: "Obraz meta"
meta_image_help: "Idealny format: 1200 x 630 px"
show_in_sitemap: "Włączenie do Sitemap"
show_in: "Pokaż w"
show_page_in_shop_page: "Pokaż stronę na stronie sklepu"
actions:
Expand Down

0 comments on commit abce8bb

Please sign in to comment.