Skip to content

Commit

Permalink
Add meta image managed by media manager
Browse files Browse the repository at this point in the history
  • Loading branch information
maximehuran committed Oct 3, 2024
1 parent e5123db commit f3aa87b
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"license": "MIT",
"require": {
"monsieurbiz/sylius-plus-adapter-plugin": "^1.1",
"monsieurbiz/sylius-media-manager-plugin": "^1.1",
"monsieurbiz/sylius-rich-editor-plugin": "^2.8",
"php": "^8.0",
"sylius/sylius": ">=1.11 <1.14"
Expand Down
10 changes: 10 additions & 0 deletions src/Entity/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ public function setMetaKeywords(?string $metaKeywords): void
$this->getTranslation()->setMetaKeywords($metaKeywords);
}

public function getMetaImage(): ?string
{
return $this->getTranslation()->getMetaImage();
}

public function setMetaImage(?string $metaImage): void
{
$this->getTranslation()->setMetaImage($metaImage);
}

public function getSlug(): ?string
{
return $this->getTranslation()->getSlug();
Expand Down
4 changes: 4 additions & 0 deletions src/Entity/PageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,8 @@ public function setMetaDescription(?string $metaDescription): void;
public function getMetaKeywords(): ?string;

public function setMetaKeywords(?string $metaKeywords): void;

public function getMetaImage(): ?string;

public function setMetaImage(?string $metaImage): void;
}
15 changes: 15 additions & 0 deletions src/Entity/PageTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class PageTranslation extends AbstractTranslation implements PageTranslationInte
*/
protected $metaDescription;

/**
* @var string|null
*/
protected $metaImage;

public function getId(): ?int
{
return $this->id;
Expand Down Expand Up @@ -107,6 +112,16 @@ public function setMetaKeywords(?string $metaKeywords): void
$this->metaKeywords = $metaKeywords;
}

public function getMetaImage(): ?string
{
return $this->metaImage;
}

public function setMetaImage(?string $metaImage): void
{
$this->metaImage = $metaImage;
}

public function getSlug(): ?string
{
return $this->slug;
Expand Down
4 changes: 4 additions & 0 deletions src/Entity/PageTranslationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ public function setMetaDescription(?string $metaDescription): void;
public function getMetaKeywords(): ?string;

public function setMetaKeywords(?string $metaKeywords): void;

public function getMetaImage(): ?string;

public function setMetaImage(?string $metaImage): void;
}
6 changes: 6 additions & 0 deletions src/Form/Type/PageTranslationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace MonsieurBiz\SyliusCmsPagePlugin\Form\Type;

use MonsieurBiz\SyliusMediaManagerPlugin\Form\Type\ImageType as MediaManagerImageType;
use MonsieurBiz\SyliusRichEditorPlugin\Form\Type\RichEditorType;
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
Expand Down Expand Up @@ -48,6 +49,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'required' => false,
'label' => 'monsieurbiz_cms_page.ui.form.meta_keywords',
])
->add('metaImage', MediaManagerImageType::class, [
'label' => 'monsieurbiz_cms_page.ui.form.meta_image',
'help' => 'monsieurbiz_cms_page.ui.form.meta_image_help',
'required' => false,
])
;
}

Expand Down
40 changes: 40 additions & 0 deletions src/Migrations/Version20241003143537.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file is part of Monsieur Biz' Cms Page plugin for Sylius.
*
* (c) Monsieur Biz <sylius@monsieurbiz.com>
*
* 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 Version20241003143537 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_translation ADD meta_image 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_cms_page_translation DROP meta_image');
}
}
1 change: 1 addition & 0 deletions src/Resources/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ imports:
- { resource: "sylius/resources.yaml" }
- { resource: "sylius/grid.yaml" }
- { resource: "sylius/fixtures.yaml" }
- { resource: "images.yaml" }
1 change: 1 addition & 0 deletions src/Resources/config/doctrine/PageTranslation.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<field name="slug" length="255" nullable="true" />
<field name="metaTitle" column="meta_title" length="255" nullable="true" />
<field name="metaKeywords" column="meta_keywords" length="255" nullable="true" />
<field name="metaImage" column="meta_image" nullable="true" />
<field name="metaDescription" column="meta_description" type="text" nullable="true" />
</mapped-superclass>

Expand Down
3 changes: 3 additions & 0 deletions src/Resources/config/images.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
liip_imagine:
filter_sets:
monsieurbiz_cms_page_og_image: ~
2 changes: 2 additions & 0 deletions src/Resources/translations/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ monsieurbiz_cms_page:
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:
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/translations/messages.fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ monsieurbiz_cms_page:
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:
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/translations/messages.pl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ monsieurbiz_cms_page:
meta_title: "Tytuł meta"
meta_description: "Opis meta"
meta_keywords: "Słowa kluczowe meta"
meta_image: "Obraz meta"
meta_image_help: "Idealny format: 1200 x 630 px"
show_in: "Pokaż w"
show_page_in_shop_page: "Pokaż stronę na stronie sklepu"
actions:
Expand Down
3 changes: 3 additions & 0 deletions src/Resources/views/Shop/Page/show.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
{% if page.metaKeywords is not empty %}
<meta name="keywords" content="{{ page.metaKeywords }}"/>
{% endif %}
{% if page is not empty and page.metaImage is not empty %}
<meta property="og:image" content="{{ page.metaImage|imagine_filter('monsieurbiz_cms_page_og_image') }}" />
{% endif %}
{% endblock %}

{% block content %}
Expand Down

0 comments on commit f3aa87b

Please sign in to comment.