Selaa lähdekoodia

Merge branch 'develop'

develop
Guillaume 2 vuotta sitten
vanhempi
commit
b8be60d2e6
11 muutettua tiedostoa jossa 159 lisäystä ja 96 poistoa
  1. +12
    -1
      Component/FileComponent.php
  2. +46
    -14
      Component/MetaComponent.php
  3. +66
    -52
      Controller/AbstractAdminController.php
  4. +8
    -6
      Definition/Field/AbstractFieldDefinition.php
  5. +1
    -1
      Definition/Field/Site/PageFieldDefinition.php
  6. +4
    -1
      Doctrine/Pattern/AbstractFullEntity.php
  7. +4
    -3
      Model/Site/NewsInterface.php
  8. +1
    -3
      Model/Site/NewsModel.php
  9. +1
    -1
      Resources/translations/admin.fr.yaml
  10. +15
    -9
      Twig/MetaTwigExtension.php
  11. +1
    -5
      Twig/TwigExtension.php

+ 12
- 1
Component/FileComponent.php Näytä tiedosto

@@ -5,16 +5,27 @@ namespace Lc\SovBundle\Component;

use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class FileComponent
{
protected ParameterBagInterface $parameterBag;
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->liipCacheHelper = $liipCacheHelper;
$this->router = $router;
}

public function getAssetUrl($path)
{
$context = $this->router->getContext();
$host = $context->getScheme().'://'.$context->getHost().'/';

return $host.$path;
}

/**

+ 46
- 14
Component/MetaComponent.php Näytä tiedosto

@@ -4,14 +4,25 @@ namespace Lc\SovBundle\Component;

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(method_exists($entity, 'getMetaTitle')) {
if(method_exists($entity, 'getMetaTitle') && $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() ;
}
}
@@ -22,24 +33,27 @@ class MetaComponent
public function getMetaDescription($entity)
{
if($entity) {
if(method_exists($entity, 'getMetaDescription')) {
if(method_exists($entity, 'getMetaDescription') && $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 '' ;
}

public function getOpenGraphTitle($entity)
public function getOpenGraphTitle($entity, $title = null)
{
if($entity) {
if(method_exists($entity, 'getOpenGraphTitle')) {
if(method_exists($entity, 'getOpenGraphTitle') && $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() ;
}
}
@@ -50,11 +64,11 @@ class MetaComponent
public function getOpenGraphDescription($entity)
{
if($entity) {
if(method_exists($entity, 'getOpenGraphDescription')) {
if(method_exists($entity, 'getOpenGraphDescription') && $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());
}
}

@@ -64,10 +78,10 @@ class MetaComponent
public function getOpenGraphImage($entity)
{
if($entity) {
if(method_exists($entity, 'getOpenGraphImage')) {
if(method_exists($entity, 'getOpenGraphImage') && $entity->getOpenGraphImage()) {
return $entity->getOpenGraphImage() ;
}
elseif(method_exists($entity, 'getImage')) {
elseif(method_exists($entity, 'getImage') && $entity->getImage()) {
return $entity->getImage() ;
}
}
@@ -75,4 +89,22 @@ class MetaComponent
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;
}
}

+ 66
- 52
Controller/AbstractAdminController.php Näytä tiedosto

@@ -36,9 +36,11 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Security\Permission;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Component\EntityComponent;
use Lc\SovBundle\Definition\ActionDefinition;
use Lc\SovBundle\Doctrine\Extension\DevAliasInterface;
use Lc\SovBundle\Doctrine\Extension\OpenGraphInterface;
use Lc\SovBundle\Doctrine\Extension\SeoInterface;
use Lc\SovBundle\Doctrine\Extension\SortableInterface;
use Lc\SovBundle\Doctrine\Extension\StatusInterface;
@@ -46,6 +48,7 @@ use Lc\SovBundle\Doctrine\Extension\TranslatableInterface;
use Lc\SovBundle\Doctrine\Extension\TreeInterface;
use Lc\SovBundle\Field\CollectionField;
use Lc\SovBundle\Field\Filter\FilterManager;
use Lc\SovBundle\Field\ImageManagerField;
use Lc\SovBundle\Form\Common\FiltersFormType;
use Lc\SovBundle\Form\Common\PositionType;
use Lc\SovBundle\Model\User\UserInterface;
@@ -80,7 +83,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
if (Crud::PAGE_INDEX === $responseParameters->get('pageName')) {
$responseParameters->set('fields', $this->configureFields('index'));

if(isset($this->filtersForm)) {
if (isset($this->filtersForm)) {
$responseParameters->set('filters_form', $this->filtersForm);
}
}
@@ -136,10 +139,10 @@ abstract class AbstractAdminController extends EaAbstractCrudController
if ($action->getName() == ActionDefinition::WRITE_TO_USER) {
$entity = $context->getEntity()->getInstance();
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);
}
} else {
@@ -150,16 +153,17 @@ abstract class AbstractAdminController extends EaAbstractCrudController
}
}

protected function getRequestCrudAction() :string{
protected function getRequestCrudAction(): string
{
return $this->getRequestStack()->getCurrentRequest()->get('crudAction');
}

public function configureCrud(Crud $crud): Crud
{
$crud = parent::configureCrud($crud);
if($this->getRequestCrudAction() === ActionDefinition::SORT) {
if ($this->getRequestCrudAction() === ActionDefinition::SORT) {
$crud->setPaginatorPageSize(9999);
}else {
} else {
$this->setMaxResults($crud);
}

@@ -167,7 +171,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController

if ($this->isInstanceOf(SortableInterface::class)) {
$crud->setDefaultSort(['position' => 'ASC']);
}else{
} else {
$crud->setDefaultSort(['id' => 'DESC']);
}

@@ -319,14 +323,15 @@ abstract class AbstractAdminController extends EaAbstractCrudController
}

public function duplicate(
AdminContext $context,
EntityComponent $entityComponent,
TranslatorAdmin $translatorAdmin,
AdminContext $context,
EntityComponent $entityComponent,
TranslatorAdmin $translatorAdmin,
EntityManagerInterface $em
) {
)
{
if (!$this->isGranted(
Permission::EA_EXECUTE_ACTION,
['action' =>ActionDefinition::DUPLICATE, 'entity' => $context->getEntity()]
['action' => ActionDefinition::DUPLICATE, 'entity' => $context->getEntity()]
)) {
throw new ForbiddenActionException($context);
}
@@ -349,19 +354,22 @@ abstract class AbstractAdminController extends EaAbstractCrudController
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;
}else{
} else {
return false;
}
}

public function createIndexRepositoryQuery(
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
): RepositoryQueryInterface {
): RepositoryQueryInterface
{
$repositoryQuery = $this->get(EntityRepository::class)->createRepositoryQuery(
$this->getRepositoryQuery(),
$searchDto,
@@ -402,34 +410,38 @@ abstract class AbstractAdminController extends EaAbstractCrudController


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(
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
): QueryBuilder {
): QueryBuilder
{
$repositoryQuery = $this->createIndexRepositoryQuery($searchDto, $entityDto, $fields, $filters);
return $repositoryQuery->getQueryBuilder();
}

public function createSortQueryBuilder(
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
): QueryBuilder {
): QueryBuilder
{
$repositoryQuery = $this->createSortRepositoryQuery($searchDto, $entityDto, $fields, $filters);
return $repositoryQuery->getQueryBuilder();
}
@@ -471,10 +483,10 @@ abstract class AbstractAdminController extends EaAbstractCrudController

public function deleteEntity(EntityManagerInterface $entityManager, $entityInstance): void
{
if($this->isInstanceOf(StatusInterface::class)){
if ($this->isInstanceOf(StatusInterface::class)) {
$entityInstance->setStatus(-1);
$entityManager->update($entityInstance);
}else{
} else {
$entityManager->delete($entityInstance);
}
$entityManager->flush();
@@ -772,12 +784,18 @@ abstract class AbstractAdminController extends EaAbstractCrudController

public function autocompleteFilter(AdminContext $context): JsonResponse
{
$queryBuilder = $this->createIndexQueryBuilder(
$repositoryQuery = $this->get(EntityRepository::class)->createRepositoryQuery(
$this->getRepositoryQuery(),
$context->getSearch(),
$context->getEntity(),
FieldCollection::new([]),
FilterCollection::new()
);

if ($this->isInstanceOf(StatusInterface::class)) {
$repositoryQuery->filterIsOnlineAndOffline();
}

$autocompleteContext = $context->getRequest()->get(AssociationField::PARAM_AUTOCOMPLETE_CONTEXT);

/** @var CrudControllerInterface $controller */
@@ -792,20 +810,16 @@ abstract class AbstractAdminController extends EaAbstractCrudController
)->getByProperty($autocompleteContext['propertyName']);

$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();
foreach ($queryBuilder->getQuery()->getArrayResult() as $result) {
foreach ($repositoryQuery->find() as $result) {
$responses[] = array_values($result)[0];
}


return JsonResponse::fromJsonString(json_encode($responses));
}


+ 8
- 6
Definition/Field/AbstractFieldDefinition.php Näytä tiedosto

@@ -39,16 +39,18 @@ abstract class AbstractFieldDefinition
'metaDescription' => TextareaField::new('metaDescription')
->setLabel('Meta : description')
->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')
->setFormTypeOption('entry_type', TextType::class)
->setLabel('Anciennes urls du document')
->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(),
'status' => StatusField::new('status')->setSortable(true),
'createdAt' => DateTimeField::new('createdAt')->setSortable(true),

+ 1
- 1
Definition/Field/Site/PageFieldDefinition.php Näytä tiedosto

@@ -29,7 +29,7 @@ class PageFieldDefinition extends AbstractFieldDefinition

public function configurePanels(): array
{
return ['general', 'seo', 'conf'];
return ['general', 'seo', 'opengraph', 'conf'];
}

public function configureFields(): array

+ 4
- 1
Doctrine/Pattern/AbstractFullEntity.php Näytä tiedosto

@@ -7,6 +7,8 @@ use Lc\SovBundle\Doctrine\Extension\BlameableInterface;
use Lc\SovBundle\Doctrine\Extension\BlameableTrait;
use Lc\SovBundle\Doctrine\Extension\DevAliasInterface;
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\SeoTrait;
use Lc\SovBundle\Doctrine\Extension\SluggableInterface;
@@ -24,12 +26,13 @@ use Lc\SovBundle\Doctrine\Extension\TimestampableTrait;
/**
* @ORM\MappedSuperclass
*/
abstract class AbstractFullEntity implements BlameableInterface, SeoInterface, SluggableInterface, SortableInterface,
abstract class AbstractFullEntity implements BlameableInterface, SeoInterface, OpenGraphInterface, SluggableInterface, SortableInterface,
StatusInterface, TimestampableInterface, DevAliasInterface, EntityInterface
{

use BlameableTrait;
use SeoTrait;
use OpenGraphTrait;
use SluggableTrait;
use SortableTrait;
use StatusTrait;

+ 4
- 3
Model/Site/NewsInterface.php Näytä tiedosto

@@ -2,6 +2,7 @@

namespace Lc\SovBundle\Model\Site;

use Lc\SovBundle\Doctrine\Extension\OpenGraphInterface;
use Lc\SovBundle\Model\File\FileInterface;
use Lc\SovBundle\Model\File\FileModel;
use Lc\SovBundle\Model\Newsletter\NewsletterInterface;
@@ -47,15 +48,15 @@ interface NewsInterface

public function getOpenGraphTitle(): ?string;

public function setOpenGraphTitle(string $openGraphTitle): NewsInterface;
public function setOpenGraphTitle(string $openGraphTitle): OpenGraphInterface;

public function getOpenGraphDescription(): ?string;

public function setOpenGraphDescription(?string $openGraphDescription): NewsInterface;
public function setOpenGraphDescription(?string $openGraphDescription): OpenGraphInterface;

public function getOpenGraphImage(): ?FileInterface;

public function setOpenGraphImage(?FileInterface $openGraphImage): NewsInterface;
public function setOpenGraphImage(?FileInterface $openGraphImage): OpenGraphInterface;

public function setMetaTitle(?string $metaTitle);


+ 1
- 3
Model/Site/NewsModel.php Näytä tiedosto

@@ -13,10 +13,8 @@ use Lc\SovBundle\Model\Newsletter\NewsletterInterface;
/**
* @ORM\MappedSuperclass()
*/
abstract class NewsModel extends AbstractFullEntity implements NewsInterface, OpenGraphInterface
abstract class NewsModel extends AbstractFullEntity implements NewsInterface
{
use OpenGraphTrait;

/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="create")

+ 1
- 1
Resources/translations/admin.fr.yaml Näytä tiedosto

@@ -159,7 +159,7 @@ entity:
conf: Configuration
gallery: Galerie
seo: Référencement
opengraph: Opengraph
opengraph: Réseaux sociaux
flashes:
success:
created: L'élément a bien été créé

+ 15
- 9
Twig/MetaTwigExtension.php Näytä tiedosto

@@ -18,11 +18,12 @@ class MetaTwigExtension extends AbstractExtension
public function getFunctions()
{
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']),
];
}

@@ -31,9 +32,9 @@ class MetaTwigExtension extends AbstractExtension
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
@@ -41,9 +42,9 @@ class MetaTwigExtension extends AbstractExtension
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
@@ -55,4 +56,9 @@ class MetaTwigExtension extends AbstractExtension
{
return $this->metaComponent->getOpenGraphImage($entity);
}

public function getOpenGraphImageUrl($entity): ?string
{
return $this->metaComponent->getOpenGraphImageUrl($entity);
}
}

+ 1
- 5
Twig/TwigExtension.php Näytä tiedosto

@@ -122,13 +122,9 @@ class TwigExtension extends AbstractExtension

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
{
return str_rot13($string);

Loading…
Peruuta
Tallenna