Browse Source

FieldDefinitions

develop
Guillaume 3 years ago
parent
commit
542b253a29
13 changed files with 213 additions and 23 deletions
  1. +10
    -1
      Container/Newsletter/NewsletterContainer.php
  2. +10
    -1
      Container/Site/NewsContainer.php
  3. +10
    -1
      Container/Site/PageContainer.php
  4. +21
    -8
      Definition/Field/AbstractFieldDefinition.php
  5. +45
    -0
      Definition/Field/Newsletter/NewsletterFieldDefinition.php
  6. +58
    -0
      Definition/Field/Site/NewsFieldDefinition.php
  7. +43
    -0
      Definition/Field/Site/PageFieldDefinition.php
  8. +0
    -3
      Model/Site/NewsModel.php
  9. +6
    -2
      Resources/translations/admin.fr.yaml
  10. +1
    -1
      Resources/views/admin/user/edit_password.html.twig
  11. +1
    -1
      Resources/views/admin/user/edit_profile.html.twig
  12. +1
    -1
      Resources/views/adminlte/crud/form.html.twig
  13. +7
    -4
      Resources/views/adminlte/layout.html.twig

+ 10
- 1
Container/Newsletter/NewsletterContainer.php View File



namespace Lc\SovBundle\Container\Newsletter; namespace Lc\SovBundle\Container\Newsletter;


use Lc\SovBundle\Definition\Field\Newsletter\NewsletterFieldDefinition;
use Lc\SovBundle\Factory\Newsletter\NewsletterFactory; use Lc\SovBundle\Factory\Newsletter\NewsletterFactory;
use Lc\SovBundle\Repository\Newsletter\NewsletterRepositoryQuery; use Lc\SovBundle\Repository\Newsletter\NewsletterRepositoryQuery;
use Lc\SovBundle\Repository\Newsletter\NewsletterStore; use Lc\SovBundle\Repository\Newsletter\NewsletterStore;
protected NewsletterFactory $factory; protected NewsletterFactory $factory;
protected NewsletterRepositoryQuery $repositoryQuery; protected NewsletterRepositoryQuery $repositoryQuery;
protected NewsletterStore $store; protected NewsletterStore $store;
protected NewsletterFieldDefinition $fieldDefinition;


public function __construct( public function __construct(
NewsletterFactory $factory, NewsletterFactory $factory,
NewsletterRepositoryQuery $repositoryQuery, NewsletterRepositoryQuery $repositoryQuery,
NewsletterStore $store
NewsletterStore $store,
NewsletterFieldDefinition $fieldDefinition
) { ) {
$this->factory = $factory; $this->factory = $factory;
$this->repositoryQuery = $repositoryQuery; $this->repositoryQuery = $repositoryQuery;
$this->store = $store; $this->store = $store;
$this->fieldDefinition = $fieldDefinition;
} }


public function getFactory(): NewsletterFactory public function getFactory(): NewsletterFactory
{ {
return $this->store; return $this->store;
} }

public function getFieldDefinition(): NewsletterFieldDefinition
{
return $this->fieldDefinition;
}
} }

+ 10
- 1
Container/Site/NewsContainer.php View File



namespace Lc\SovBundle\Container\Site; namespace Lc\SovBundle\Container\Site;


use Lc\SovBundle\Definition\Field\Site\NewsFieldDefinition;
use Lc\SovBundle\Factory\Site\NewsFactory; use Lc\SovBundle\Factory\Site\NewsFactory;
use Lc\SovBundle\Repository\Site\NewsRepositoryQuery; use Lc\SovBundle\Repository\Site\NewsRepositoryQuery;
use Lc\SovBundle\Repository\Site\NewsStore; use Lc\SovBundle\Repository\Site\NewsStore;
protected NewsFactory $factory; protected NewsFactory $factory;
protected NewsRepositoryQuery $repositoryQuery; protected NewsRepositoryQuery $repositoryQuery;
protected NewsStore $store; protected NewsStore $store;
protected NewsFieldDefinition $fieldDefinition;


public function __construct( public function __construct(
NewsFactory $factory, NewsFactory $factory,
NewsRepositoryQuery $repositoryQuery, NewsRepositoryQuery $repositoryQuery,
NewsStore $store
NewsStore $store,
NewsFieldDefinition $fieldDefinition
) { ) {
$this->factory = $factory; $this->factory = $factory;
$this->repositoryQuery = $repositoryQuery; $this->repositoryQuery = $repositoryQuery;
$this->store = $store; $this->store = $store;
$this->fieldDefinition = $fieldDefinition;
} }


public function getFactory(): NewsFactory public function getFactory(): NewsFactory
{ {
return $this->store; return $this->store;
} }

public function getFieldDefinition(): NewsFieldDefinition
{
return $this->fieldDefinition;
}
} }

+ 10
- 1
Container/Site/PageContainer.php View File



namespace Lc\SovBundle\Container\Site; namespace Lc\SovBundle\Container\Site;


use Lc\SovBundle\Definition\Field\Site\PageFieldDefinition;
use Lc\SovBundle\Factory\Site\PageFactory; use Lc\SovBundle\Factory\Site\PageFactory;
use Lc\SovBundle\Repository\Site\PageRepositoryQuery; use Lc\SovBundle\Repository\Site\PageRepositoryQuery;
use Lc\SovBundle\Repository\Site\PageStore; use Lc\SovBundle\Repository\Site\PageStore;
protected PageFactory $factory; protected PageFactory $factory;
protected PageRepositoryQuery $repositoryQuery; protected PageRepositoryQuery $repositoryQuery;
protected PageStore $store; protected PageStore $store;
protected PageFieldDefinition $fieldDefinition;


public function __construct( public function __construct(
PageFactory $factory, PageFactory $factory,
PageRepositoryQuery $repositoryQuery, PageRepositoryQuery $repositoryQuery,
PageStore $store
PageStore $store,
PageFieldDefinition $fieldDefinition
) { ) {
$this->factory = $factory; $this->factory = $factory;
$this->repositoryQuery = $repositoryQuery; $this->repositoryQuery = $repositoryQuery;
$this->store = $store; $this->store = $store;
$this->fieldDefinition = $fieldDefinition;
} }


public function getFactory(): PageFactory public function getFactory(): PageFactory
{ {
return $this->store; return $this->store;
} }

public function getFieldDefinition(): PageFieldDefinition
{
return $this->fieldDefinition;
}
} }

+ 21
- 8
Definition/Field/AbstractFieldDefinition.php View File

use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Field\CollectionField; use Lc\SovBundle\Field\CollectionField;
use Lc\SovBundle\Field\ImageManagerField;
use Lc\SovBundle\Field\StatusField; use Lc\SovBundle\Field\StatusField;
use Lc\SovBundle\Translation\TranslatorAdmin; use Lc\SovBundle\Translation\TranslatorAdmin;
use PhpParser\Node\Expr\Throw_;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;


abstract class AbstractFieldDefinition abstract class AbstractFieldDefinition
return [ return [
'id' => IntegerField::new('id')->onlyOnIndex()->setSortable(true), 'id' => IntegerField::new('id')->onlyOnIndex()->setSortable(true),
'metaTitle' => TextField::new('metaTitle') 'metaTitle' => TextField::new('metaTitle')
->setLabel('Meta Title')
->setHelp('Affiché dans les résultats de recherche Google')
->hideOnIndex(),
->setLabel('Meta : title')
->setHelp('Affiché dans les résultats de recherche Google'),
'metaDescription' => TextareaField::new('metaDescription') 'metaDescription' => TextareaField::new('metaDescription')
->setLabel('Meta description')
->setHelp('Affiché dans les résultats de recherche Google')
->hideOnIndex(),
->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') 'oldUrls' => CollectionField::new('oldUrls')
->setFormTypeOption('entry_type', TextType::class) ->setFormTypeOption('entry_type', TextType::class)
->setLabel('Anciennes urls du document') ->setLabel('Anciennes urls du document')
]; ];
} }


public function configurePanelOpengraph(): array
{
return [
'openGraphTitle',
'openGraphDescription',
'openGraphImage'
];
}

public function configurePanelConf(): array public function configurePanelConf(): array
{ {
return [ return [
{ {
return array_merge( return array_merge(
$this->configureFieldsBase(), $this->configureFieldsBase(),
$this->configureFields()
$this->configureFields(),
); );
} }



+ 45
- 0
Definition/Field/Newsletter/NewsletterFieldDefinition.php View File

<?php

namespace Lc\SovBundle\Definition\Field\Newsletter;

use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Definition\Field\AbstractFieldDefinition;
use Lc\SovBundle\Field\BooleanField;
use Lc\SovBundle\Field\CKEditorField;

class NewsletterFieldDefinition extends AbstractFieldDefinition
{
public function configureIndex(): array
{
return [
'id',
'title',
'isMain',
'status'
];
}

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

public function configurePanelMain(): array
{
return [
'title',
'description',
'status'
];
}

public function configureFields(): array
{
return [
'title' => TextField::new('title'),
'description' => CKEditorField::new('description')->hideOnIndex(),
'isMain' => BooleanField::new('isMain')->setCustomOption('toggle_label', 'Principale'),
];
}

}

+ 58
- 0
Definition/Field/Site/NewsFieldDefinition.php View File

<?php

namespace Lc\SovBundle\Definition\Field\Site;

use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Definition\Field\AbstractFieldDefinition;
use Lc\SovBundle\Field\BooleanField;
use Lc\SovBundle\Field\ImageManagerField;

class NewsFieldDefinition extends AbstractFieldDefinition
{
public function configureIndex(): array
{
return [
'id',
'title',
'status'
];
}

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

public function configurePanelMain(): array
{
return [
'date',
'title',
'newsletter',
'image',
'description',
'isSent',
'status'
];
}

public function configureFields(): array
{
return [
'date' => DateField::new('date')
->setFormat('d/MM/y')
->setSortable(true),
'title' => TextField::new('title')->setSortable(true),
'newsletter' => AssociationField::new('newsletter')->setSortable(true),
'image' => ImageManagerField::new('image'),
'position' => NumberField::new('position'),
'description' => TextEditorField::new('description'),
'isSent' => BooleanField::new('isSent')->setSortable(true),
];
}

}

+ 43
- 0
Definition/Field/Site/PageFieldDefinition.php View File

<?php

namespace Lc\SovBundle\Definition\Field\Site;

use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Definition\Field\AbstractFieldDefinition;
use Lc\SovBundle\Field\CKEditorField;

class PageFieldDefinition extends AbstractFieldDefinition
{

public function configureIndex(): array
{
return [
'id',
'title',
'status'
];
}

public function configurePanelMain(): array
{
return [
'title',
'description',
'status'
];
}

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

public function configureFields(): array
{
return [
'title' => TextField::new('title')->setSortable(true),
'description' => CKEditorField::new('description')->hideOnIndex(),
];
}

}

+ 0
- 3
Model/Site/NewsModel.php View File

*/ */
abstract class NewsModel extends AbstractFullEntity implements NewsInterface, OpenGraphInterface abstract class NewsModel extends AbstractFullEntity implements NewsInterface, OpenGraphInterface
{ {

use OpenGraphTrait; use OpenGraphTrait;



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



/** /**
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\Newsletter\NewsletterInterface") * @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\Newsletter\NewsletterInterface")
*/ */

+ 6
- 2
Resources/translations/admin.fr.yaml View File

status: Statut status: Statut
email: Email email: Email
value: Valeur value: Valeur
metaTitle: Meta title
metaTitle: "Meta : titre"
metaTitle_help: Affiché dans les résultats de recherche Google metaTitle_help: Affiché dans les résultats de recherche Google
metaDescription: Meta description
metaDescription: "Meta : description"
metaDescription_help: Affiché dans les résultats de recherche Google metaDescription_help: Affiché dans les résultats de recherche Google
openGraphTitle: "Opengraph : titre"
openGraphDescription: "Opengraph : description"
openGraphImage: "Opengraph : image"
oldUrls: Anciennes urls oldUrls: Anciennes urls
devAlias: Alias devAlias: Alias
gallery: Galerie gallery: Galerie
configuration: Configuration configuration: Configuration
gallery: Galerie gallery: Galerie
seo: Référencement seo: Référencement
opengraph: Opengraph
flashes: flashes:
success: success:
created: L'élément a bien été créé created: L'élément a bien été créé

+ 1
- 1
Resources/views/admin/user/edit_password.html.twig View File

</div> </div>


{% embed '@LcSov/adminlte/embed/form_footer.html.twig' %} {% embed '@LcSov/adminlte/embed/form_footer.html.twig' %}
{% block width %}8{% endblock %}
{% block width %}12{% endblock %}
{% block content %} {% block content %}
{% import '@LcSov/adminlte/macro/button.html.twig' as mbutton %} {% import '@LcSov/adminlte/macro/button.html.twig' as mbutton %}
{{ mbutton.button({form: form_id, icon: 'fa fa-check'}) }} {{ mbutton.button({form: form_id, icon: 'fa fa-check'}) }}

+ 1
- 1
Resources/views/admin/user/edit_profile.html.twig View File

</div> </div>


{% embed '@LcSov/adminlte/embed/form_footer.html.twig' %} {% embed '@LcSov/adminlte/embed/form_footer.html.twig' %}
{% block width %}8{% endblock %}
{% block width %}12{% endblock %}
{% block content %} {% block content %}
{% import '@LcSov/adminlte/macro/button.html.twig' as mbutton %} {% import '@LcSov/adminlte/macro/button.html.twig' as mbutton %}
{{ mbutton.button({form: form_id, icon: 'fa fa-check'}) }} {{ mbutton.button({form: form_id, icon: 'fa fa-check'}) }}

+ 1
- 1
Resources/views/adminlte/crud/form.html.twig View File



{% block form_footer %} {% block form_footer %}
{% embed '@LcSov/adminlte/embed/form_footer.html.twig' %} {% embed '@LcSov/adminlte/embed/form_footer.html.twig' %}
{% block width %}8{% endblock %}
{% block width %}12{% endblock %}
{% block content %} {% block content %}
{% for action in entity.actions %} {% for action in entity.actions %}
{{ include(action.templatePath, { action: action }, with_context = false) }}&nbsp; {{ include(action.templatePath, { action: action }, with_context = false) }}&nbsp;

+ 7
- 4
Resources/views/adminlte/layout.html.twig View File

<div class="content-wrapper" style="min-height: 554px;"> <div class="content-wrapper" style="min-height: 554px;">
{% block content %} {% block content %}
{% block content_header_wrapper %} {% block content_header_wrapper %}

<section class="content-header"> <section class="content-header">
<div class="container-fluid"> <div class="container-fluid">
<div class="row mb-2"> <div class="row mb-2">


<section class="content"> <section class="content">
<div class="container-fluid"> <div class="container-fluid">
{% block main %}{% endblock %}
{% if replace_content_with_message is defined %}
<div class="alert alert-warning" role="alert">
{{ replace_content_with_message }}
</div>
{% else %}
{% block main %}{% endblock %}
{% endif %}
</div> </div>
</section> </section>


{% endblock %} {% endblock %}
</div> </div>



Loading…
Cancel
Save