use Liip\ImagineBundle\Imagine\Cache\CacheManager; | use Liip\ImagineBundle\Imagine\Cache\CacheManager; | ||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | |||||
class FileComponent | class FileComponent | ||||
{ | { | ||||
protected ParameterBagInterface $parameterBag; | protected ParameterBagInterface $parameterBag; | ||||
protected CacheManager $liipCacheHelper; | protected CacheManager $liipCacheHelper; | ||||
protected UrlGeneratorInterface $router; | |||||
public function __construct(ParameterBagInterface $parameterBag, CacheManager $liipCacheHelper) | |||||
public function __construct(ParameterBagInterface $parameterBag, CacheManager $liipCacheHelper, UrlGeneratorInterface $router) | |||||
{ | { | ||||
$this->parameterBag = $parameterBag; | $this->parameterBag = $parameterBag; | ||||
$this->liipCacheHelper = $liipCacheHelper; | $this->liipCacheHelper = $liipCacheHelper; | ||||
$this->router = $router; | |||||
} | |||||
public function getAssetUrl($path) | |||||
{ | |||||
$context = $this->router->getContext(); | |||||
$host = $context->getScheme().'://'.$context->getHost().'/'; | |||||
return $host.$path; | |||||
} | } | ||||
/** | /** |
class MetaComponent | class MetaComponent | ||||
{ | { | ||||
protected FileComponent $fileComponent; | |||||
protected StringComponent $stringComponent; | |||||
public function getMetaTitle($entity) | |||||
public function __construct(FileComponent $fileComponent, StringComponent $stringComponent) | |||||
{ | |||||
$this->fileComponent = $fileComponent; | |||||
$this->stringComponent = $stringComponent; | |||||
} | |||||
public function getMetaTitle($entity, $title = null) | |||||
{ | { | ||||
if($entity) { | if($entity) { | ||||
if(method_exists($entity, 'getMetaTitle')) { | |||||
if(method_exists($entity, 'getMetaTitle') && $entity->getMetaTitle()) { | |||||
return $entity->getMetaTitle() ; | return $entity->getMetaTitle() ; | ||||
} | } | ||||
elseif(method_exists($entity, 'getTitle')) { | |||||
elseif(!is_null($title)) { | |||||
return $title; | |||||
} | |||||
elseif(method_exists($entity, 'getTitle') && $entity->getTitle()) { | |||||
return $entity->getTitle() ; | return $entity->getTitle() ; | ||||
} | } | ||||
} | } | ||||
public function getMetaDescription($entity) | public function getMetaDescription($entity) | ||||
{ | { | ||||
if($entity) { | if($entity) { | ||||
if(method_exists($entity, 'getMetaDescription')) { | |||||
if(method_exists($entity, 'getMetaDescription') && $entity->getMetaDescription()) { | |||||
return $entity->getMetaDescription() ; | return $entity->getMetaDescription() ; | ||||
} | } | ||||
elseif(method_exists($entity, 'getDescription')) { | |||||
return $entity->getDescription() ; | |||||
elseif(method_exists($entity, 'getDescription') && $entity->getDescription()) { | |||||
return $this->formatDescription($entity->getDescription()); | |||||
} | } | ||||
} | } | ||||
return '' ; | return '' ; | ||||
} | } | ||||
public function getOpenGraphTitle($entity) | |||||
public function getOpenGraphTitle($entity, $title = null) | |||||
{ | { | ||||
if($entity) { | if($entity) { | ||||
if(method_exists($entity, 'getOpenGraphTitle')) { | |||||
if(method_exists($entity, 'getOpenGraphTitle') && $entity->getOpenGraphTitle()) { | |||||
return $entity->getOpenGraphTitle() ; | return $entity->getOpenGraphTitle() ; | ||||
} | } | ||||
elseif(method_exists($entity, 'getTitle')) { | |||||
elseif(!is_null($title)) { | |||||
return $title; | |||||
} | |||||
elseif(method_exists($entity, 'getTitle') && $entity->getTitle()) { | |||||
return $entity->getTitle() ; | return $entity->getTitle() ; | ||||
} | } | ||||
} | } | ||||
public function getOpenGraphDescription($entity) | public function getOpenGraphDescription($entity) | ||||
{ | { | ||||
if($entity) { | if($entity) { | ||||
if(method_exists($entity, 'getOpenGraphDescription')) { | |||||
if(method_exists($entity, 'getOpenGraphDescription') && $entity->getOpenGraphDescription()) { | |||||
return $entity->getOpenGraphDescription() ; | return $entity->getOpenGraphDescription() ; | ||||
} | } | ||||
elseif(method_exists($entity, 'getDescription')) { | |||||
return $entity->getDescription() ; | |||||
elseif(method_exists($entity, 'getDescription') && $entity->getDescription()) { | |||||
return $this->formatDescription($entity->getDescription()); | |||||
} | } | ||||
} | } | ||||
public function getOpenGraphImage($entity) | public function getOpenGraphImage($entity) | ||||
{ | { | ||||
if($entity) { | if($entity) { | ||||
if(method_exists($entity, 'getOpenGraphImage')) { | |||||
if(method_exists($entity, 'getOpenGraphImage') && $entity->getOpenGraphImage()) { | |||||
return $entity->getOpenGraphImage() ; | return $entity->getOpenGraphImage() ; | ||||
} | } | ||||
elseif(method_exists($entity, 'getImage')) { | |||||
elseif(method_exists($entity, 'getImage') && $entity->getImage()) { | |||||
return $entity->getImage() ; | return $entity->getImage() ; | ||||
} | } | ||||
} | } | ||||
return '' ; | return '' ; | ||||
} | } | ||||
public function getOpenGraphImageUrl($entity) | |||||
{ | |||||
$image = $this->getOpenGraphImage($entity); | |||||
if($image && $image->getPath() && strlen($image->getPath()) > 0) { | |||||
return $this->fileComponent->getAssetUrl($image->getPath()); | |||||
} | |||||
return ''; | |||||
} | |||||
public function formatDescription($description) | |||||
{ | |||||
$description = trim($description); | |||||
$description = $this->stringComponent->limitText($description, 50); | |||||
$description = str_replace("\r\n","",$description); | |||||
return $description; | |||||
} | |||||
} | } |
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; | use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator; | use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Security\Permission; | use EasyCorp\Bundle\EasyAdminBundle\Security\Permission; | ||||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | |||||
use Lc\SovBundle\Component\EntityComponent; | use Lc\SovBundle\Component\EntityComponent; | ||||
use Lc\SovBundle\Definition\ActionDefinition; | use Lc\SovBundle\Definition\ActionDefinition; | ||||
use Lc\SovBundle\Doctrine\Extension\DevAliasInterface; | use Lc\SovBundle\Doctrine\Extension\DevAliasInterface; | ||||
use Lc\SovBundle\Doctrine\Extension\OpenGraphInterface; | |||||
use Lc\SovBundle\Doctrine\Extension\SeoInterface; | use Lc\SovBundle\Doctrine\Extension\SeoInterface; | ||||
use Lc\SovBundle\Doctrine\Extension\SortableInterface; | use Lc\SovBundle\Doctrine\Extension\SortableInterface; | ||||
use Lc\SovBundle\Doctrine\Extension\StatusInterface; | use Lc\SovBundle\Doctrine\Extension\StatusInterface; | ||||
use Lc\SovBundle\Doctrine\Extension\TreeInterface; | use Lc\SovBundle\Doctrine\Extension\TreeInterface; | ||||
use Lc\SovBundle\Field\CollectionField; | use Lc\SovBundle\Field\CollectionField; | ||||
use Lc\SovBundle\Field\Filter\FilterManager; | use Lc\SovBundle\Field\Filter\FilterManager; | ||||
use Lc\SovBundle\Field\ImageManagerField; | |||||
use Lc\SovBundle\Form\Common\FiltersFormType; | use Lc\SovBundle\Form\Common\FiltersFormType; | ||||
use Lc\SovBundle\Form\Common\PositionType; | use Lc\SovBundle\Form\Common\PositionType; | ||||
use Lc\SovBundle\Model\User\UserInterface; | use Lc\SovBundle\Model\User\UserInterface; | ||||
if (Crud::PAGE_INDEX === $responseParameters->get('pageName')) { | if (Crud::PAGE_INDEX === $responseParameters->get('pageName')) { | ||||
$responseParameters->set('fields', $this->configureFields('index')); | $responseParameters->set('fields', $this->configureFields('index')); | ||||
if(isset($this->filtersForm)) { | |||||
if (isset($this->filtersForm)) { | |||||
$responseParameters->set('filters_form', $this->filtersForm); | $responseParameters->set('filters_form', $this->filtersForm); | ||||
} | } | ||||
} | } | ||||
if ($action->getName() == ActionDefinition::WRITE_TO_USER) { | if ($action->getName() == ActionDefinition::WRITE_TO_USER) { | ||||
$entity = $context->getEntity()->getInstance(); | $entity = $context->getEntity()->getInstance(); | ||||
if ($entity !== null) { | if ($entity !== null) { | ||||
if(method_exists($entity, 'getUser')){ | |||||
$url = $this->generateEaUrl(UserA) ->setController($context->getCrud()->getControllerFqcn()) | |||||
->set('entityId', $entity->getParent()->getId()) | |||||
->generateUrl(); | |||||
if (method_exists($entity, 'getUser')) { | |||||
$url = $this->generateEaUrl(UserA)->setController($context->getCrud()->getControllerFqcn()) | |||||
->set('entityId', $entity->getParent()->getId()) | |||||
->generateUrl(); | |||||
$action->setLinkUrl($url); | $action->setLinkUrl($url); | ||||
} | } | ||||
} else { | } else { | ||||
} | } | ||||
} | } | ||||
protected function getRequestCrudAction() :string{ | |||||
protected function getRequestCrudAction(): string | |||||
{ | |||||
return $this->getRequestStack()->getCurrentRequest()->get('crudAction'); | return $this->getRequestStack()->getCurrentRequest()->get('crudAction'); | ||||
} | } | ||||
public function configureCrud(Crud $crud): Crud | public function configureCrud(Crud $crud): Crud | ||||
{ | { | ||||
$crud = parent::configureCrud($crud); | $crud = parent::configureCrud($crud); | ||||
if($this->getRequestCrudAction() === ActionDefinition::SORT) { | |||||
if ($this->getRequestCrudAction() === ActionDefinition::SORT) { | |||||
$crud->setPaginatorPageSize(9999); | $crud->setPaginatorPageSize(9999); | ||||
}else { | |||||
} else { | |||||
$this->setMaxResults($crud); | $this->setMaxResults($crud); | ||||
} | } | ||||
if ($this->isInstanceOf(SortableInterface::class)) { | if ($this->isInstanceOf(SortableInterface::class)) { | ||||
$crud->setDefaultSort(['position' => 'ASC']); | $crud->setDefaultSort(['position' => 'ASC']); | ||||
}else{ | |||||
} else { | |||||
$crud->setDefaultSort(['id' => 'DESC']); | $crud->setDefaultSort(['id' => 'DESC']); | ||||
} | } | ||||
} | } | ||||
public function duplicate( | public function duplicate( | ||||
AdminContext $context, | |||||
EntityComponent $entityComponent, | |||||
TranslatorAdmin $translatorAdmin, | |||||
AdminContext $context, | |||||
EntityComponent $entityComponent, | |||||
TranslatorAdmin $translatorAdmin, | |||||
EntityManagerInterface $em | EntityManagerInterface $em | ||||
) { | |||||
) | |||||
{ | |||||
if (!$this->isGranted( | if (!$this->isGranted( | ||||
Permission::EA_EXECUTE_ACTION, | Permission::EA_EXECUTE_ACTION, | ||||
['action' =>ActionDefinition::DUPLICATE, 'entity' => $context->getEntity()] | |||||
['action' => ActionDefinition::DUPLICATE, 'entity' => $context->getEntity()] | |||||
)) { | )) { | ||||
throw new ForbiddenActionException($context); | throw new ForbiddenActionException($context); | ||||
} | } | ||||
return $this->redirect($url); | return $this->redirect($url); | ||||
} | } | ||||
public function isRepositoryQueryFiltered():bool{ | |||||
if(($this->filtersForm && $this->filtersForm->isSubmitted()) || $this->isRepositoryQueryFiltered){ | |||||
public function isRepositoryQueryFiltered(): bool | |||||
{ | |||||
if (($this->filtersForm && $this->filtersForm->isSubmitted()) || $this->isRepositoryQueryFiltered) { | |||||
return true; | return true; | ||||
}else{ | |||||
} else { | |||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
public function createIndexRepositoryQuery( | public function createIndexRepositoryQuery( | ||||
SearchDto $searchDto, | |||||
EntityDto $entityDto, | |||||
FieldCollection $fields, | |||||
SearchDto $searchDto, | |||||
EntityDto $entityDto, | |||||
FieldCollection $fields, | |||||
FilterCollection $filters | FilterCollection $filters | ||||
): RepositoryQueryInterface { | |||||
): RepositoryQueryInterface | |||||
{ | |||||
$repositoryQuery = $this->get(EntityRepository::class)->createRepositoryQuery( | $repositoryQuery = $this->get(EntityRepository::class)->createRepositoryQuery( | ||||
$this->getRepositoryQuery(), | $this->getRepositoryQuery(), | ||||
$searchDto, | $searchDto, | ||||
public function createSortRepositoryQuery( | public function createSortRepositoryQuery( | ||||
SearchDto $searchDto, | |||||
EntityDto $entityDto, | |||||
FieldCollection $fields, | |||||
FilterCollection $filters | |||||
): RepositoryQueryInterface { | |||||
$repositoryQuery = $this->createIndexRepositoryQuery($searchDto,$entityDto, $fields, $filters); | |||||
if($this->isInstanceOf(StatusInterface::class)) { | |||||
$repositoryQuery->filterIsOnline(); | |||||
} | |||||
$repositoryQuery->orderBy('position', 'asc'); | |||||
return $repositoryQuery; | |||||
SearchDto $searchDto, | |||||
EntityDto $entityDto, | |||||
FieldCollection $fields, | |||||
FilterCollection $filters | |||||
): RepositoryQueryInterface | |||||
{ | |||||
$repositoryQuery = $this->createIndexRepositoryQuery($searchDto, $entityDto, $fields, $filters); | |||||
if ($this->isInstanceOf(StatusInterface::class)) { | |||||
$repositoryQuery->filterIsOnline(); | |||||
} | |||||
$repositoryQuery->orderBy('position', 'asc'); | |||||
return $repositoryQuery; | |||||
} | } | ||||
public function createIndexQueryBuilder( | public function createIndexQueryBuilder( | ||||
SearchDto $searchDto, | |||||
EntityDto $entityDto, | |||||
FieldCollection $fields, | |||||
SearchDto $searchDto, | |||||
EntityDto $entityDto, | |||||
FieldCollection $fields, | |||||
FilterCollection $filters | FilterCollection $filters | ||||
): QueryBuilder { | |||||
): QueryBuilder | |||||
{ | |||||
$repositoryQuery = $this->createIndexRepositoryQuery($searchDto, $entityDto, $fields, $filters); | $repositoryQuery = $this->createIndexRepositoryQuery($searchDto, $entityDto, $fields, $filters); | ||||
return $repositoryQuery->getQueryBuilder(); | return $repositoryQuery->getQueryBuilder(); | ||||
} | } | ||||
public function createSortQueryBuilder( | public function createSortQueryBuilder( | ||||
SearchDto $searchDto, | |||||
EntityDto $entityDto, | |||||
FieldCollection $fields, | |||||
SearchDto $searchDto, | |||||
EntityDto $entityDto, | |||||
FieldCollection $fields, | |||||
FilterCollection $filters | FilterCollection $filters | ||||
): QueryBuilder { | |||||
): QueryBuilder | |||||
{ | |||||
$repositoryQuery = $this->createSortRepositoryQuery($searchDto, $entityDto, $fields, $filters); | $repositoryQuery = $this->createSortRepositoryQuery($searchDto, $entityDto, $fields, $filters); | ||||
return $repositoryQuery->getQueryBuilder(); | return $repositoryQuery->getQueryBuilder(); | ||||
} | } | ||||
public function deleteEntity(EntityManagerInterface $entityManager, $entityInstance): void | public function deleteEntity(EntityManagerInterface $entityManager, $entityInstance): void | ||||
{ | { | ||||
if($this->isInstanceOf(StatusInterface::class)){ | |||||
if ($this->isInstanceOf(StatusInterface::class)) { | |||||
$entityInstance->setStatus(-1); | $entityInstance->setStatus(-1); | ||||
$entityManager->update($entityInstance); | $entityManager->update($entityInstance); | ||||
}else{ | |||||
} else { | |||||
$entityManager->delete($entityInstance); | $entityManager->delete($entityInstance); | ||||
} | } | ||||
$entityManager->flush(); | $entityManager->flush(); | ||||
public function autocompleteFilter(AdminContext $context): JsonResponse | public function autocompleteFilter(AdminContext $context): JsonResponse | ||||
{ | { | ||||
$queryBuilder = $this->createIndexQueryBuilder( | |||||
$repositoryQuery = $this->get(EntityRepository::class)->createRepositoryQuery( | |||||
$this->getRepositoryQuery(), | |||||
$context->getSearch(), | $context->getSearch(), | ||||
$context->getEntity(), | $context->getEntity(), | ||||
FieldCollection::new([]), | FieldCollection::new([]), | ||||
FilterCollection::new() | FilterCollection::new() | ||||
); | ); | ||||
if ($this->isInstanceOf(StatusInterface::class)) { | |||||
$repositoryQuery->filterIsOnlineAndOffline(); | |||||
} | |||||
$autocompleteContext = $context->getRequest()->get(AssociationField::PARAM_AUTOCOMPLETE_CONTEXT); | $autocompleteContext = $context->getRequest()->get(AssociationField::PARAM_AUTOCOMPLETE_CONTEXT); | ||||
/** @var CrudControllerInterface $controller */ | /** @var CrudControllerInterface $controller */ | ||||
)->getByProperty($autocompleteContext['propertyName']); | )->getByProperty($autocompleteContext['propertyName']); | ||||
$filterManager = $this->get(FilterManager::class); | $filterManager = $this->get(FilterManager::class); | ||||
$filterManager->applyFilter($queryBuilder, $field, $context->getRequest()->query->get('q')); | |||||
if ($filterManager->isRelationField($field->getProperty())) { | |||||
$queryBuilder->select($autocompleteContext['propertyName']); | |||||
} else { | |||||
$queryBuilder->select('entity.' . $autocompleteContext['propertyName']); | |||||
} | |||||
$filteredValue = ['value' => $context->getRequest()->query->get('q')]; | |||||
$filterManager->applyFilter($repositoryQuery, $field, $filteredValue); | |||||
$repositoryQuery->select('.' . $autocompleteContext['propertyName']); | |||||
//dump($repositoryQuery->getQueryBuilder()->getQuery()->getDQL()); | |||||
$responses = array(); | $responses = array(); | ||||
foreach ($queryBuilder->getQuery()->getArrayResult() as $result) { | |||||
foreach ($repositoryQuery->find() as $result) { | |||||
$responses[] = array_values($result)[0]; | $responses[] = array_values($result)[0]; | ||||
} | } | ||||
return JsonResponse::fromJsonString(json_encode($responses)); | return JsonResponse::fromJsonString(json_encode($responses)); | ||||
} | } | ||||
'metaDescription' => TextareaField::new('metaDescription') | 'metaDescription' => TextareaField::new('metaDescription') | ||||
->setLabel('Meta : description') | ->setLabel('Meta : description') | ||||
->setHelp('Affiché dans les résultats de recherche Google'), | ->setHelp('Affiché dans les résultats de recherche Google'), | ||||
'openGraphTitle' => TextField::new('openGraphTitle') | |||||
->setLabel('OpenGraph : titre'), | |||||
'openGraphDescription' => TextareaField::new('openGraphDescription') | |||||
->setLabel('OpenGraph : description'), | |||||
'openGraphImage' => ImageManagerField::new('openGraphImage') | |||||
->setLabel('OpenGraph : image'), | |||||
'oldUrls' => CollectionField::new('oldUrls') | 'oldUrls' => CollectionField::new('oldUrls') | ||||
->setFormTypeOption('entry_type', TextType::class) | ->setFormTypeOption('entry_type', TextType::class) | ||||
->setLabel('Anciennes urls du document') | ->setLabel('Anciennes urls du document') | ||||
->hideOnIndex(), | ->hideOnIndex(), | ||||
'openGraphTitle' => TextField::new('openGraphTitle') | |||||
->setLabel('OpenGraph : titre') | |||||
->setHelp('Utilisé par les réseaux sociaux pour récupérer le titre de la page'), | |||||
'openGraphDescription' => TextareaField::new('openGraphDescription') | |||||
->setLabel('OpenGraph : description') | |||||
->setHelp('Utilisé par les réseaux sociaux pour récupérer la description de la page'), | |||||
'openGraphImage' => ImageManagerField::new('openGraphImage') | |||||
->setLabel('OpenGraph : image'), | |||||
'devAlias' => TextField::new('devAlias')->hideOnIndex(), | 'devAlias' => TextField::new('devAlias')->hideOnIndex(), | ||||
'status' => StatusField::new('status')->setSortable(true), | 'status' => StatusField::new('status')->setSortable(true), | ||||
'createdAt' => DateTimeField::new('createdAt')->setSortable(true), | 'createdAt' => DateTimeField::new('createdAt')->setSortable(true), |
public function configurePanels(): array | public function configurePanels(): array | ||||
{ | { | ||||
return ['general', 'seo', 'conf']; | |||||
return ['general', 'seo', 'opengraph', 'conf']; | |||||
} | } | ||||
public function configureFields(): array | public function configureFields(): array |
use Lc\SovBundle\Doctrine\Extension\BlameableTrait; | use Lc\SovBundle\Doctrine\Extension\BlameableTrait; | ||||
use Lc\SovBundle\Doctrine\Extension\DevAliasInterface; | use Lc\SovBundle\Doctrine\Extension\DevAliasInterface; | ||||
use Lc\SovBundle\Doctrine\Extension\DevAliasTrait; | use Lc\SovBundle\Doctrine\Extension\DevAliasTrait; | ||||
use Lc\SovBundle\Doctrine\Extension\OpenGraphInterface; | |||||
use Lc\SovBundle\Doctrine\Extension\OpenGraphTrait; | |||||
use Lc\SovBundle\Doctrine\Extension\SeoInterface; | use Lc\SovBundle\Doctrine\Extension\SeoInterface; | ||||
use Lc\SovBundle\Doctrine\Extension\SeoTrait; | use Lc\SovBundle\Doctrine\Extension\SeoTrait; | ||||
use Lc\SovBundle\Doctrine\Extension\SluggableInterface; | use Lc\SovBundle\Doctrine\Extension\SluggableInterface; | ||||
/** | /** | ||||
* @ORM\MappedSuperclass | * @ORM\MappedSuperclass | ||||
*/ | */ | ||||
abstract class AbstractFullEntity implements BlameableInterface, SeoInterface, SluggableInterface, SortableInterface, | |||||
abstract class AbstractFullEntity implements BlameableInterface, SeoInterface, OpenGraphInterface, SluggableInterface, SortableInterface, | |||||
StatusInterface, TimestampableInterface, DevAliasInterface, EntityInterface | StatusInterface, TimestampableInterface, DevAliasInterface, EntityInterface | ||||
{ | { | ||||
use BlameableTrait; | use BlameableTrait; | ||||
use SeoTrait; | use SeoTrait; | ||||
use OpenGraphTrait; | |||||
use SluggableTrait; | use SluggableTrait; | ||||
use SortableTrait; | use SortableTrait; | ||||
use StatusTrait; | use StatusTrait; |
namespace Lc\SovBundle\Model\Site; | namespace Lc\SovBundle\Model\Site; | ||||
use Lc\SovBundle\Doctrine\Extension\OpenGraphInterface; | |||||
use Lc\SovBundle\Model\File\FileInterface; | use Lc\SovBundle\Model\File\FileInterface; | ||||
use Lc\SovBundle\Model\File\FileModel; | use Lc\SovBundle\Model\File\FileModel; | ||||
use Lc\SovBundle\Model\Newsletter\NewsletterInterface; | use Lc\SovBundle\Model\Newsletter\NewsletterInterface; | ||||
public function getOpenGraphTitle(): ?string; | public function getOpenGraphTitle(): ?string; | ||||
public function setOpenGraphTitle(string $openGraphTitle): NewsInterface; | |||||
public function setOpenGraphTitle(string $openGraphTitle): OpenGraphInterface; | |||||
public function getOpenGraphDescription(): ?string; | public function getOpenGraphDescription(): ?string; | ||||
public function setOpenGraphDescription(?string $openGraphDescription): NewsInterface; | |||||
public function setOpenGraphDescription(?string $openGraphDescription): OpenGraphInterface; | |||||
public function getOpenGraphImage(): ?FileInterface; | public function getOpenGraphImage(): ?FileInterface; | ||||
public function setOpenGraphImage(?FileInterface $openGraphImage): NewsInterface; | |||||
public function setOpenGraphImage(?FileInterface $openGraphImage): OpenGraphInterface; | |||||
public function setMetaTitle(?string $metaTitle); | public function setMetaTitle(?string $metaTitle); | ||||
/** | /** | ||||
* @ORM\MappedSuperclass() | * @ORM\MappedSuperclass() | ||||
*/ | */ | ||||
abstract class NewsModel extends AbstractFullEntity implements NewsInterface, OpenGraphInterface | |||||
abstract class NewsModel extends AbstractFullEntity implements NewsInterface | |||||
{ | { | ||||
use OpenGraphTrait; | |||||
/** | /** | ||||
* @ORM\Column(type="datetime") | * @ORM\Column(type="datetime") | ||||
* @Gedmo\Timestampable(on="create") | * @Gedmo\Timestampable(on="create") |
conf: Configuration | conf: Configuration | ||||
gallery: Galerie | gallery: Galerie | ||||
seo: Référencement | seo: Référencement | ||||
opengraph: Opengraph | |||||
opengraph: Réseaux sociaux | |||||
flashes: | flashes: | ||||
success: | success: | ||||
created: L'élément a bien été créé | created: L'élément a bien été créé |
public function getFunctions() | public function getFunctions() | ||||
{ | { | ||||
return [ | return [ | ||||
new TwigFunction('sov_meta_title', [$this, 'getMetaTitle']), | |||||
new TwigFunction('sov_meta_description', [$this, 'getMetaDescription']), | |||||
new TwigFunction('sov_opengraph_title', [$this, 'getOpengraphTitle']), | |||||
new TwigFunction('sov_opengraph_description', [$this, 'getOpengraphDescription']), | |||||
new TwigFunction('sov_opengraph_image', [$this, 'getOpengraphImage']), | |||||
new TwigFunction('meta_title', [$this, 'getMetaTitle']), | |||||
new TwigFunction('meta_description', [$this, 'getMetaDescription']), | |||||
new TwigFunction('opengraph_title', [$this, 'getOpengraphTitle']), | |||||
new TwigFunction('opengraph_description', [$this, 'getOpengraphDescription']), | |||||
new TwigFunction('opengraph_image', [$this, 'getOpengraphImage']), | |||||
new TwigFunction('opengraph_image_url', [$this, 'getOpengraphImageUrl']), | |||||
]; | ]; | ||||
} | } | ||||
return []; | return []; | ||||
} | } | ||||
public function getMetaTitle($entity): ?string | |||||
public function getMetaTitle($entity, $title = null): ?string | |||||
{ | { | ||||
return $this->metaComponent->getMetaTitle($entity); | |||||
return $this->metaComponent->getMetaTitle($entity, $title); | |||||
} | } | ||||
public function getMetaDescription($entity): ?string | public function getMetaDescription($entity): ?string | ||||
return $this->metaComponent->getMetaDescription($entity); | return $this->metaComponent->getMetaDescription($entity); | ||||
} | } | ||||
public function getOpenGraphTitle($entity): ?string | |||||
public function getOpenGraphTitle($entity, $title = null): ?string | |||||
{ | { | ||||
return $this->metaComponent->getOpenGraphTitle($entity); | |||||
return $this->metaComponent->getOpenGraphTitle($entity, $title); | |||||
} | } | ||||
public function getOpenGraphDescription($entity): ?string | public function getOpenGraphDescription($entity): ?string | ||||
{ | { | ||||
return $this->metaComponent->getOpenGraphImage($entity); | return $this->metaComponent->getOpenGraphImage($entity); | ||||
} | } | ||||
public function getOpenGraphImageUrl($entity): ?string | |||||
{ | |||||
return $this->metaComponent->getOpenGraphImageUrl($entity); | |||||
} | |||||
} | } |
public function getAssetUrl($path) | public function getAssetUrl($path) | ||||
{ | { | ||||
$context = $this->router->getContext(); | |||||
$host = $context->getScheme().'://'.$context->getHost().'/'; | |||||
return $host.$path; | |||||
return $this->fileComponent->getAssetUrl($path); | |||||
} | } | ||||
public function rot13(string $string): string | public function rot13(string $string): string | ||||
{ | { | ||||
return str_rot13($string); | return str_rot13($string); |