Browse Source

OpenGraphTrait : propriétés pour gérer les meta OpenGraph

develop
Guillaume 3 years ago
parent
commit
feb2cbe999
3 changed files with 162 additions and 2 deletions
  1. +88
    -0
      ShopBundle/Model/OpenGraphTrait.php
  2. +5
    -2
      ShopBundle/Resources/translations/lcshop.fr.yaml
  3. +69
    -0
      ShopBundle/Services/Utils.php

+ 88
- 0
ShopBundle/Model/OpenGraphTrait.php View File

@@ -0,0 +1,88 @@
<?php

namespace Lc\ShopBundle\Model;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;


trait OpenGraphTrait
{
/**
* @ORM\Column(type="string", nullable=true)
*/
protected $openGraphTitle;

/**
* @ORM\Column(type="text", nullable=true)
*/
protected $openGraphDescription;

/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $openGraphImage;

/**
* @Vich\UploadableField(mapping="images", fileNameProperty="openGraphImage")
* @var File
*/
protected $openGraphImageFile;


public function getOpenGraphTitle(): ?string
{
return $this->openGraphTitle;
}

public function setOpenGraphTitle(string $openGraphTitle): self
{
$this->openGraphTitle = $openGraphTitle;

return $this;
}

public function getOpenGraphDescription(): ?string
{
return $this->openGraphDescription;
}

public function setOpenGraphDescription(?string $openGraphDescription): self
{
$this->openGraphDescription = $openGraphDescription;

return $this;
}

public function getOpenGraphImage(): ?string
{
return $this->openGraphImage;
}

public function setOpenGraphImage(?string $openGraphImage): self
{
$this->openGraphImage = $openGraphImage;

return $this;
}

public function setOpenGraphImageFile(File $openGraphImageFile = null)
{
$this->openGraphImageFile = $openGraphImageFile;

// VERY IMPORTANT:
// It is required that at least one field changes if you are using Doctrine,
// otherwise the event listeners won't be called and the file is lost
if ($openGraphImageFile) {
// if 'updatedAt' is not defined in your entity, use another property
$this->updatedAt = new \DateTime('now');
}
}

public function getOpenGraphImageFile()
{
return $this->openGraphImageFile ;
}

}

+ 5
- 2
ShopBundle/Resources/translations/lcshop.fr.yaml View File

@@ -299,8 +299,8 @@ field:
emailFromPurchaseOrder: "Email (From) : bons de commande"
order: Commande
subject: Sujet
metaTitle: Meta title
metaDescription: Meta description
metaTitle: Titre (meta)
metaDescription: Description (meta)
users: Utilisateurs
total: Total
products: Produits
@@ -314,6 +314,9 @@ field:
ticketTypesNotification: Catégorie ticket
newsletter: Newsletter
isEligibleTicketRestaurant: Éligible ticket restaurant
openGraphTitle: Titre (OpenGraph)
openGraphDescription: Description (OpenGraph)
openGraphImageFile: Image (OpenGraph)

PointSale:
code: Code

+ 69
- 0
ShopBundle/Services/Utils.php View File

@@ -615,5 +615,74 @@ class Utils
return $phone ;
}

public function getMetaTitle($entity)
{
if($entity) {
if(method_exists($entity, 'getMetaTitle')) {
return $entity->getMetaTitle() ;
}
elseif(method_exists($entity, 'getTitle')) {
return $entity->getTitle() ;
}
}

return '' ;
}

public function getMetaDescription($entity)
{
if($entity) {
if(method_exists($entity, 'getMetaDescription')) {
return $entity->getMetaDescription() ;
}
elseif(method_exists($entity, 'getDescription')) {
return $entity->getDescription() ;
}
}

return '' ;
}

public function getOpenGraphTitle($entity)
{
if($entity) {
if(method_exists($entity, 'getOpenGraphTitle')) {
return $entity->getOpenGraphTitle() ;
}
elseif(method_exists($entity, 'getTitle')) {
return $entity->getTitle() ;
}
}

return '' ;
}

public function getOpenGraphDescription($entity)
{
if($entity) {
if(method_exists($entity, 'getOpenGraphDescription')) {
return $entity->getOpenGraphDescription() ;
}
elseif(method_exists($entity, 'getDescription')) {
return $entity->getDescription() ;
}
}

return '' ;
}

public function getOpenGraphImage($entity)
{
if($entity) {
if(method_exists($entity, 'getOpenGraphImage')) {
return $entity->getOpenGraphImage() ;
}
elseif(method_exists($entity, 'getImage')) {
return $entity->getImage() ;
}
}

return '' ;
}

}

Loading…
Cancel
Save