From ae97614478ee0aa8b54ac7d1ed30a664afd1171e Mon Sep 17 00:00:00 2001 From: RobinDev Date: Fri, 17 Nov 2023 12:04:16 +0100 Subject: [PATCH] continue to simplify and add templates/icons in default svg dirs --- packages/admin/src/AdminFormFieldManager.php | 12 + packages/admin/src/AdminTrait.php | 33 ++- packages/admin/src/FormField/Event.php | 2 +- packages/admin/src/FormField/PageH1Field.php | 11 +- packages/admin/src/MediaAdmin.php | 13 + packages/admin/src/Menu/PageMenuProvider.php | 3 + packages/admin/src/PageAbstractAdmin.php | 268 +++++++++++++++++ packages/admin/src/PageAdmin.php | 269 +----------------- packages/admin/src/PageCRUDController.php | 24 +- packages/admin/src/PageCheatSheetAdmin.php | 11 +- .../admin/src/PageCheatSheetController.php | 2 + packages/admin/src/PageRedirectionAdmin.php | 9 +- packages/admin/src/UserAdmin.php | 6 + packages/admin/src/config/services.yaml | 70 +---- packages/skeleton/var/app.db | Bin 77824 -> 77824 bytes .../src/DependencyInjection/Configuration.php | 1 + packages/svg/src/TwigExtension.php | 10 +- 17 files changed, 378 insertions(+), 366 deletions(-) create mode 100644 packages/admin/src/AdminFormFieldManager.php create mode 100755 packages/admin/src/PageAbstractAdmin.php diff --git a/packages/admin/src/AdminFormFieldManager.php b/packages/admin/src/AdminFormFieldManager.php new file mode 100644 index 000000000..7c58d48fc --- /dev/null +++ b/packages/admin/src/AdminFormFieldManager.php @@ -0,0 +1,12 @@ + */ @@ -39,8 +37,6 @@ trait AdminTrait protected string $userClass; - protected Twig $twig; - protected EntityManagerInterface $em; protected RouterInterface $router; @@ -145,6 +141,9 @@ public function getEntityManager(): EntityManagerInterface return $this->em; } + /** Used in AbstractField::class / MediaPreviewField::class */ + protected Twig $twig; + #[Required] public function setTwig(Twig $twig): void { @@ -226,17 +225,6 @@ public function getMessagePrefix(): string return $this->messagePrefix; } - #[Required] - public function setImageManager(ImageManager $imageManager): void - { - $this->imageManager = $imageManager; - } - - public function getImageManager(): ImageManager - { - return $this->imageManager; - } - /** * @psalm-suppress InvalidArgument * @@ -255,4 +243,19 @@ protected function getFormFields(): array return $event->getFields(); } + + private ImageManager $imageManager; + + public function getImageManager(): ImageManager + { + return $this->imageManager; + } + + #[Required] + public function setImageManager(ImageManager $imageManager): self + { + $this->imageManager = $imageManager; + + return $this; + } } diff --git a/packages/admin/src/FormField/Event.php b/packages/admin/src/FormField/Event.php index e64ced1dc..0ce9bc555 100755 --- a/packages/admin/src/FormField/Event.php +++ b/packages/admin/src/FormField/Event.php @@ -18,7 +18,7 @@ class Event extends SfEvent /** * @param AdminInterface $admin - * @param mixed[] $fields + * @param mixed[] $fields // TODO Reduce complexity !!! */ public function __construct( private readonly AdminInterface $admin, diff --git a/packages/admin/src/FormField/PageH1Field.php b/packages/admin/src/FormField/PageH1Field.php index 5660bc1ab..5812b5cc6 100755 --- a/packages/admin/src/FormField/PageH1Field.php +++ b/packages/admin/src/FormField/PageH1Field.php @@ -14,8 +14,9 @@ class PageH1Field extends AbstractField /** * @var string */ - final public const DEFAULT_STYLE = 'font-size: 22px !important; border:0;' - .'font-weight: 700; padding: 10px 10px 0px 10px; margin-top:-23px; margin-bottom:-23px max-width: 640px; color:#111827'; + final public const DEFAULT_STYLE = 'font-size: 22px !important; font-weight: 700; border:0; color:#111827;' + .'padding: 10px 10px 0px 10px; margin-top:-23px; margin-bottom:-23px; + max-width: 640px; '; /** * @param FormMapper $form @@ -29,7 +30,11 @@ public function formField(FormMapper $form, string $style = ''): FormMapper // Todo move style to view return $form->add('h1', TextareaType::class, [ 'required' => false, - 'attr' => ['class' => 'autosize textarea-no-newline ce-block__content', 'placeholder' => 'admin.page.title.label', 'style' => $style], + 'attr' => [ + 'class' => 'autosize textarea-no-newline ce-block__content', + 'placeholder' => 'admin.page.title.label', + 'style' => $style, + ], 'label' => ' ', ]); } diff --git a/packages/admin/src/MediaAdmin.php b/packages/admin/src/MediaAdmin.php index 2a892977e..d15b45b9c 100755 --- a/packages/admin/src/MediaAdmin.php +++ b/packages/admin/src/MediaAdmin.php @@ -11,6 +11,7 @@ use Sonata\AdminBundle\Object\Metadata; use Sonata\DoctrineORMAdminBundle\Filter\ChoiceFilter; use Sonata\DoctrineORMAdminBundle\Filter\ModelAutocompleteFilter; +use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; /** @@ -18,6 +19,12 @@ * * @implements AdminInterface */ +#[AutoconfigureTag('sonata.admin', [ + 'model_class' => '%pw.entity_media%', + 'manager_type' => 'orm', + 'label' => 'admin.label.media', + 'persist_filters' => true, +])] final class MediaAdmin extends AbstractAdmin implements AdminInterface { /** @@ -27,6 +34,12 @@ final class MediaAdmin extends AbstractAdmin implements AdminInterface private string $messagePrefix = 'admin.media'; + protected function configure(): void + { + $this->setTemplate('list', '@pwAdmin/CRUD/mosaic.html.twig'); + $this->setTemplate('short_object_description', '@pwAdmin/media/short_object_description.html.twig'); + } + protected function configureDefaultSortValues(array &$sortValues): void { $sortValues = [ diff --git a/packages/admin/src/Menu/PageMenuProvider.php b/packages/admin/src/Menu/PageMenuProvider.php index c1cad855b..9efa708f0 100755 --- a/packages/admin/src/Menu/PageMenuProvider.php +++ b/packages/admin/src/Menu/PageMenuProvider.php @@ -6,6 +6,7 @@ use Knp\Menu\FactoryInterface; use Knp\Menu\ItemInterface; use Sonata\AdminBundle\Event\ConfigureMenuEvent; +use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerAwareTrait; use Symfony\Component\EventDispatcher\Attribute\AsEventListener; @@ -13,6 +14,8 @@ use Symfony\Contracts\Service\Attribute\Required; use Symfony\Contracts\Translation\TranslatorInterface; +#[AutoconfigureTag('knp_menu.menu_builder', ['method' => 'getMenu', 'alias' => 'page_admin_menu'])] +#[AutoconfigureTag('knp_menu.menu_builder', ['method' => 'getRedirectionMenu', 'alias' => 'redirection_admin_menu'])] final class PageMenuProvider implements ContainerAwareInterface { use ContainerAwareTrait; diff --git a/packages/admin/src/PageAbstractAdmin.php b/packages/admin/src/PageAbstractAdmin.php new file mode 100755 index 000000000..a94394dfc --- /dev/null +++ b/packages/admin/src/PageAbstractAdmin.php @@ -0,0 +1,268 @@ + + * + * @implements AdminInterface + */ +abstract class PageAbstractAdmin extends AbstractAdmin implements AdminInterface +{ + /** @use AdminTrait */ + use AdminTrait; + + /** @var bool */ + public $supportsPreviewMode = true; + + protected string $messagePrefix = 'admin.page'; + + /** @var string[] */ + protected array $fields = []; + + /** @var int[] */ + protected array $perPageOptions = [16, 250, 1000]; + + protected int $maxPerPage = 1000; + + protected ?string $mainColClass = null; + + protected ?string $secondColClass = null; + + public function __construct() + { + parent::__construct(); + } + + protected function configure(): void + { + parent::configure(); + + // $this->setListModes([...$this->getListModes(), ...['tree' => ['class' => 'fa fa-sitemap']]]); + $this->setBaseControllerName(PageCRUDController::class); + $this->setTemplate('list', '@pwAdmin/CRUD/mosaic.html.twig'); + $this->setTemplate('show', '@pwAdmin/page/page_show.html.twig'); + $this->setTemplate('edit', '@pwAdmin/page/page_edit.html.twig'); + $this->setTemplate('preview', '@pwAdmin/page/preview.html.twig'); + } + + protected function configureDefaultSortValues(array &$sortValues): void + { + $sortValues = [ + '_page' => 1, + '_sort_order' => 'DESC', + '_sort_by' => 'updatedAt', + '_per_page' => 100, + ]; + } + + protected function generateBaseRouteName(bool $isChildAdmin = false): string + { + return 'admin_page'; + } + + protected function generateBaseRoutePattern(bool $isChildAdmin = false): string + { + return 'app/page'; + } + + /** + * @param ProxyQueryInterface $query + */ + protected function getQueryBuilderFrom(ProxyQueryInterface $query): QueryBuilder + { + if (! method_exists($query, 'getQueryBuilder')) { + throw new \Exception(); + } + + $qb = $query->getQueryBuilder(); + + return $qb instanceof QueryBuilder ? $qb : throw new \Exception(); + } + + protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface + { + $query = parent::configureQuery($query); + + $qb = $this->getQueryBuilderFrom($query); + + $rootAlias = current($qb->getRootAliases()); + + $qb->andWhere($qb->expr()->notLike($rootAlias.'.mainContent', ':mcf'))->setParameter('mcf', 'Location:%'); + + $qb->andWhere($qb->expr()->neq($rootAlias.'.slug', ':slug'))->setParameter('slug', 'pushword-cheatsheet'); + + return $query; + } + + /** + * Check if page entity's item $name exist. + */ + protected function exists(string $name): bool + { + return method_exists($this->pageClass, 'get'.$name); + } + + /** + * @psalm-suppress InvalidArgument + */ + protected function configureFormFields(FormMapper $form): void + { + $this->apps->switchCurrentApp($this->getSubject()); + $fields = $this->getFormFields(); + if (! isset($fields[0]) || ! \is_array($fields[0]) || ! isset($fields[1]) || ! \is_array($fields[1])) { + throw new \LogicException(); + } + + $form->with('admin.page.mainContent.label', ['class' => $this->mainColClass ?? 'col-md-9 mainFields']); + foreach ($fields[0] as $field) { + $this->addFormField($field, $form); + } + + $form->end(); + + foreach ($fields[1] as $k => $block) { + if (null === $this->getSubject()->getId() && 'admin.page.revisions' == $k) { + continue; + } + + $fields = $block['fields'] ?? $block; + $class = isset($block['expand']) ? 'expand' : ''; + $form->with($k, ['class' => $this->secondColClass ?? 'col-md-3 columnFields '.$class, 'label' => $k]); + foreach ($fields as $field) { + $this->addFormField($field, $form); + } + + $form->end(); + } + } + + /** + * @phpstan-param PageInterface $object + */ + protected function alterNewInstance(object $object): void + { + $object->setLocale($this->apps->get()->getDefaultLocale()); // always use first app params... + } + + /** + * @param ProxyQuery $queryBuilder + * + * @psalm-suppress TooManyArguments + */ + public function getSearchFilterForTitle(ProxyQuery $queryBuilder, string $alias, string $field, FilterData $filterData): ?bool + { + if (! $filterData->hasValue()) { + return null; + } + + $exp = new \Doctrine\ORM\Query\Expr(); + $queryBuilder->andWhere( + (string) $exp->like( + (string) $exp->concat($alias.'.h1', $alias.'.title', $alias.'.slug'), + (string) $exp->literal('%'.$filterData->getValue().'%') + ) + ); + + return true; + } + + /** + * @psalm-suppress InvalidArgument + */ + protected function configureDatagridFilters(DatagridMapper $filter): void + { + if (\count($this->getApps()->getHosts()) > 1) { + // $filter->add('host', null, ['label' => 'admin.page.host.label']); + (new HostField($this))->datagridMapper($filter); // @phpstan-ignore-line + } + + $filter->add('slug', null, ['label' => 'admin.page.slug.label']); + + $filter + ->add('h1', CallbackFilter::class, [ + 'callback' => fn (\Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery $queryBuilder, string $alias, string $field, \Sonata\AdminBundle\Filter\Model\FilterData $filterData): ?bool => $this->getSearchFilterForTitle($queryBuilder, $alias, $field, $filterData), + 'label' => 'admin.page.h1.label', + ]); + + $filter->add('mainContent', null, ['label' => 'admin.page.mainContent.label']); + + $filter->add('locale', null, ['label' => 'admin.page.locale.label']); + + if ($this->exists('name')) { + $filter->add('name', null, ['label' => 'admin.page.name.label']); + } + + if ($this->exists('parentPage')) { + $filter->add('parentPage', null, ['label' => 'admin.page.parentPage.label']); + } + + $filter->add('metaRobots', null, [ + 'choices' => [ + 'admin.page.metaRobots.choice.noIndex' => 'noindex', + ], + 'label' => 'admin.page.metaRobots.label', + ]); + + $filter->add('customProperties', null, ['label' => 'admin.page.customProperties.label']); + } + + protected function preUpdate(object $object): void + { + $object->setUpdatedAt(new \DateTime()); + } + + protected function configureListFields(ListMapper $list): void + { + $list->addIdentifier('h1', 'html', [ + 'label' => 'admin.page.title.label', + 'template' => '@pwAdmin/page/page_list_titleField.html.twig', + ]); + $list->add('updatedAt', 'datetime', [ + 'format' => 'd/m à H:m', + 'label' => 'admin.page.updatedAt.label', + ]); + $list->add('_actions', null, [ + 'actions' => [ + 'edit' => [], + 'show' => [], + 'delete' => [], + ], + 'row_align' => 'right', + 'header_class' => 'text-right', + 'label' => 'admin.action', + ]); + } + + /** + * @param PageInterface $object + * + * @psalm-suppress MoreSpecificImplementedParamType + */ + public function getObjectMetadata(object $object): Metadata + { + $media = $object->getMainImage(); + if (null !== $media && $this->imageManager->isImage($media)) { + $thumb = $this->imageManager->getBrowserPath($media, 'thumb'); + } else { + $thumb = self::$thumb; + } + + $name = \in_array($object->getName(), ['', null], true) ? $object->getH1() : $object->getName(); + + return new Metadata(strip_tags((string) $name), null, $thumb); + } +} diff --git a/packages/admin/src/PageAdmin.php b/packages/admin/src/PageAdmin.php index 1efadcaf4..0a649a3bf 100755 --- a/packages/admin/src/PageAdmin.php +++ b/packages/admin/src/PageAdmin.php @@ -2,265 +2,14 @@ namespace Pushword\Admin; -use Doctrine\ORM\QueryBuilder; -use Pushword\Admin\FormField\HostField; -use Pushword\Core\Entity\PageInterface; -use Sonata\AdminBundle\Admin\AbstractAdmin; -use Sonata\AdminBundle\Datagrid\DatagridMapper; -use Sonata\AdminBundle\Datagrid\ListMapper; -use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; -use Sonata\AdminBundle\Filter\Model\FilterData; -use Sonata\AdminBundle\Form\FormMapper; -use Sonata\AdminBundle\Object\Metadata; -use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery; -use Sonata\DoctrineORMAdminBundle\Filter\CallbackFilter; - -/** - * @extends AbstractAdmin - * - * @implements AdminInterface - */ -class PageAdmin extends AbstractAdmin implements AdminInterface +use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; + +#[AutoconfigureTag('sonata.admin', [ + 'model_class' => '%pw.entity_page%', + 'manager_type' => 'orm', + 'label' => 'admin.label.page', + 'default' => true, +])] +class PageAdmin extends PageAbstractAdmin { - /** - * @use AdminTrait - */ - use AdminTrait; - - /** - * @var bool - */ - public $supportsPreviewMode = true; - - protected string $messagePrefix = 'admin.page'; - - /** - * @var string[] - */ - protected array $fields = []; - - /** - * @var int[] - */ - protected array $perPageOptions = [16, 250, 1000]; - - protected int $maxPerPage = 1000; - - protected ?string $mainColClass = null; - - protected ?string $secondColClass = null; - - protected function configureDefaultSortValues(array &$sortValues): void - { - $sortValues = [ - '_page' => 1, - '_sort_order' => 'DESC', - '_sort_by' => 'updatedAt', - '_per_page' => 100, - ]; - } - - protected function generateBaseRouteName(bool $isChildAdmin = false): string - { - return 'admin_page'; - } - - protected function generateBaseRoutePattern(bool $isChildAdmin = false): string - { - return 'app/page'; - } - - /** - * @param ProxyQueryInterface $query - */ - protected function getQueryBuilderFrom(ProxyQueryInterface $query): QueryBuilder - { - if (! method_exists($query, 'getQueryBuilder')) { - throw new \Exception(); - } - - $qb = $query->getQueryBuilder(); - - return $qb instanceof QueryBuilder ? $qb : throw new \Exception(); - } - - protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface - { - $query = parent::configureQuery($query); - - $qb = $this->getQueryBuilderFrom($query); - - $rootAlias = current($qb->getRootAliases()); - - $qb->andWhere($qb->expr()->notLike($rootAlias.'.mainContent', ':mcf'))->setParameter('mcf', 'Location:%'); - - $qb->andWhere($qb->expr()->neq($rootAlias.'.slug', ':slug'))->setParameter('slug', 'pushword-cheatsheet'); - - return $query; - } - - protected function configure(): void - { - parent::configure(); - - // $this->setListModes([...$this->getListModes(), ...['tree' => ['class' => 'fa fa-sitemap']]]); - } - - /** - * Check if page entity's item $name exist. - */ - protected function exists(string $name): bool - { - return method_exists($this->pageClass, 'get'.$name); - } - - /** - * @psalm-suppress InvalidArgument - */ - protected function configureFormFields(FormMapper $form): void - { - $this->apps->switchCurrentApp($this->getSubject()); - $fields = $this->getFormFields(); - if (! isset($fields[0]) || ! \is_array($fields[0]) || ! isset($fields[1]) || ! \is_array($fields[1])) { - throw new \LogicException(); - } - - $form->with('admin.page.mainContent.label', ['class' => $this->mainColClass ?? 'col-md-9 mainFields']); - foreach ($fields[0] as $field) { - $this->addFormField($field, $form); - } - - $form->end(); - - foreach ($fields[1] as $k => $block) { - if (null === $this->getSubject()->getId() && 'admin.page.revisions' == $k) { - continue; - } - - $fields = $block['fields'] ?? $block; - $class = isset($block['expand']) ? 'expand' : ''; - $form->with($k, ['class' => $this->secondColClass ?? 'col-md-3 columnFields '.$class, 'label' => $k]); - foreach ($fields as $field) { - $this->addFormField($field, $form); - } - - $form->end(); - } - } - - /** - * @phpstan-param PageInterface $object - */ - protected function alterNewInstance(object $object): void - { - $object->setLocale($this->apps->get()->getDefaultLocale()); // always use first app params... - } - - /** - * @param ProxyQuery $queryBuilder - * - * @psalm-suppress TooManyArguments - */ - public function getSearchFilterForTitle(ProxyQuery $queryBuilder, string $alias, string $field, FilterData $filterData): ?bool - { - if (! $filterData->hasValue()) { - return null; - } - - $exp = new \Doctrine\ORM\Query\Expr(); - $queryBuilder->andWhere( - (string) $exp->like( - (string) $exp->concat($alias.'.h1', $alias.'.title', $alias.'.slug'), - (string) $exp->literal('%'.$filterData->getValue().'%') - ) - ); - - return true; - } - - /** - * @psalm-suppress InvalidArgument - */ - protected function configureDatagridFilters(DatagridMapper $filter): void - { - if (\count($this->getApps()->getHosts()) > 1) { - // $filter->add('host', null, ['label' => 'admin.page.host.label']); - (new HostField($this))->datagridMapper($filter); // @phpstan-ignore-line - } - - $filter->add('slug', null, ['label' => 'admin.page.slug.label']); - - $filter - ->add('h1', CallbackFilter::class, [ - 'callback' => fn (\Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery $queryBuilder, string $alias, string $field, \Sonata\AdminBundle\Filter\Model\FilterData $filterData): ?bool => $this->getSearchFilterForTitle($queryBuilder, $alias, $field, $filterData), - 'label' => 'admin.page.h1.label', - ]); - - $filter->add('mainContent', null, ['label' => 'admin.page.mainContent.label']); - - $filter->add('locale', null, ['label' => 'admin.page.locale.label']); - - if ($this->exists('name')) { - $filter->add('name', null, ['label' => 'admin.page.name.label']); - } - - if ($this->exists('parentPage')) { - $filter->add('parentPage', null, ['label' => 'admin.page.parentPage.label']); - } - - $filter->add('metaRobots', null, [ - 'choices' => [ - 'admin.page.metaRobots.choice.noIndex' => 'noindex', - ], - 'label' => 'admin.page.metaRobots.label', - ]); - - $filter->add('customProperties', null, ['label' => 'admin.page.customProperties.label']); - } - - protected function preUpdate(object $object): void - { - $object->setUpdatedAt(new \DateTime()); - } - - protected function configureListFields(ListMapper $list): void - { - $list->addIdentifier('h1', 'html', [ - 'label' => 'admin.page.title.label', - 'template' => '@pwAdmin/page/page_list_titleField.html.twig', - ]); - $list->add('updatedAt', 'datetime', [ - 'format' => 'd/m à H:m', - 'label' => 'admin.page.updatedAt.label', - ]); - $list->add('_actions', null, [ - 'actions' => [ - 'edit' => [], - 'show' => [], - 'delete' => [], - ], - 'row_align' => 'right', - 'header_class' => 'text-right', - 'label' => 'admin.action', - ]); - } - - /** - * @param PageInterface $object - * - * @psalm-suppress MoreSpecificImplementedParamType - */ - public function getObjectMetadata(object $object): Metadata - { - $media = $object->getMainImage(); - if (null !== $media && $this->imageManager->isImage($media)) { - $thumb = $this->imageManager->getBrowserPath($media, 'thumb'); - } else { - $thumb = self::$thumb; - } - - $name = \in_array($object->getName(), ['', null], true) ? $object->getH1() : $object->getName(); - - return new Metadata(strip_tags((string) $name), null, $thumb); - } } diff --git a/packages/admin/src/PageCRUDController.php b/packages/admin/src/PageCRUDController.php index c8fdb2180..39769e536 100755 --- a/packages/admin/src/PageCRUDController.php +++ b/packages/admin/src/PageCRUDController.php @@ -3,42 +3,28 @@ namespace Pushword\Admin; use Doctrine\ORM\EntityManagerInterface; -use Psr\Container\ContainerInterface; use Pushword\Core\Entity\PageInterface; use Pushword\Core\Repository\Repository; use Sonata\AdminBundle\Controller\CRUDController as SonataCRUDController; +use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Contracts\Service\Attribute\Required; /** * @extends SonataCRUDController */ +#[AutoconfigureTag('controller.service_arguments')] class PageCRUDController extends SonataCRUDController { protected ParameterBagInterface $params; - /** - * https://github.com/symfony/symfony/blob/5.4/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php. - */ - #[\Symfony\Contracts\Service\Attribute\Required] + #[Required] public EntityManagerInterface $entityManager; - /** - * https://github.com/symfony/symfony/blob/5.4/src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php. - */ - #[\Symfony\Contracts\Service\Attribute\Required] - public function loadContainer(ContainerInterface $container): void - { - $this->container = $container; - - if (! $this->container->has('parameter_bag')) { // @phpstan-ignore-line - throw new \Exception('patch no longer worked'); - } - } - - #[\Symfony\Contracts\Service\Attribute\Required] + #[Required] public function setParams(ParameterBagInterface $parameterBag): void { $this->params = $parameterBag; diff --git a/packages/admin/src/PageCheatSheetAdmin.php b/packages/admin/src/PageCheatSheetAdmin.php index 539cf15ae..c28f8acb9 100755 --- a/packages/admin/src/PageCheatSheetAdmin.php +++ b/packages/admin/src/PageCheatSheetAdmin.php @@ -4,8 +4,15 @@ use Sonata\AdminBundle\Form\FormMapper; use Sonata\AdminBundle\Route\RouteCollectionInterface; - -class PageCheatSheetAdmin extends PageAdmin +use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; + +#[AutoconfigureTag('sonata.admin', [ + 'model_class' => '%pw.entity_page%', + 'manager_type' => 'orm', + 'label' => 'admin.label.page', + 'default' => false, +])] +class PageCheatSheetAdmin extends PageAbstractAdmin { final public const CHEATSHEET_SLUG = 'pushword-cheatsheet'; diff --git a/packages/admin/src/PageCheatSheetController.php b/packages/admin/src/PageCheatSheetController.php index feb8c8518..bbd483cd5 100644 --- a/packages/admin/src/PageCheatSheetController.php +++ b/packages/admin/src/PageCheatSheetController.php @@ -6,11 +6,13 @@ use Pushword\Core\Entity\PageInterface; use Pushword\Core\Repository\PageRepository; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Contracts\Translation\TranslatorInterface; +#[AutoconfigureTag('controller.service_arguments')] class PageCheatSheetController extends AbstractController { public function __construct( diff --git a/packages/admin/src/PageRedirectionAdmin.php b/packages/admin/src/PageRedirectionAdmin.php index a4aeedc79..fb81c2387 100755 --- a/packages/admin/src/PageRedirectionAdmin.php +++ b/packages/admin/src/PageRedirectionAdmin.php @@ -6,8 +6,15 @@ use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; use Sonata\AdminBundle\Form\FormMapper; +use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; -class PageRedirectionAdmin extends PageAdmin +#[AutoconfigureTag('sonata.admin', [ + 'model_class' => '%pw.entity_page%', + 'manager_type' => 'orm', + 'label' => 'admin.label.page', + 'default' => false, +])] +class PageRedirectionAdmin extends PageAbstractAdmin { /** * @psalm-suppress InvalidArgument diff --git a/packages/admin/src/UserAdmin.php b/packages/admin/src/UserAdmin.php index 8fffc32b7..16308bf00 100755 --- a/packages/admin/src/UserAdmin.php +++ b/packages/admin/src/UserAdmin.php @@ -7,6 +7,7 @@ use Sonata\AdminBundle\Datagrid\DatagridMapper; use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Form\FormMapper; +use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; use Symfony\Component\Form\Extension\Core\Type\TextType; /** @@ -14,6 +15,11 @@ * * @implements AdminInterface */ +#[AutoconfigureTag('sonata.admin', [ + 'model_class' => '%pw.entity_user%', + 'manager_type' => 'orm', + 'label' => 'admin.label.user', +])] class UserAdmin extends AbstractAdmin implements AdminInterface { /** diff --git a/packages/admin/src/config/services.yaml b/packages/admin/src/config/services.yaml index 0f96ec668..e3bf4661d 100755 --- a/packages/admin/src/config/services.yaml +++ b/packages/admin/src/config/services.yaml @@ -7,67 +7,13 @@ services: $pageClass: "%pw.entity_page%" $userClass: "%pw.entity_user%" - Pushword\Admin\Menu\PageMenuProvider: - tags: - - { name: knp_menu.menu_builder, method: getMenu, alias: page_admin_menu } - - { name: knp_menu.menu_builder, method: getRedirectionMenu, alias: redirection_admin_menu } + Pushword\Admin\: + resource: '../../src/' + exclude: + - '../../src/DependencyInjection/' + - '../../src/FormField/' + - '../../src/Resources/' + - '../../src/config/' #Sonata\AdminBundle\Bridge\Exporter\AdminExporter: - # autowire: true - - Pushword\Admin\PageAdmin: - autowire: true - tags: - - { name: sonata.admin, model_class: "%pw.entity_page%", manager_type: orm, label: admin.label.page, default: true } - calls: - - [setBaseControllerName, [Pushword\Admin\PageCRUDController]] - - [setTemplate, [list, "@@pwAdmin/CRUD/mosaic.html.twig"]] - - [setTemplate, [show, "@@pwAdmin/page/page_show.html.twig"]] - - [setTemplate, [edit, "@@pwAdmin/page/page_edit.html.twig"]] - - [setTemplate, [preview, "@@pwAdmin/page/preview.html.twig"]] - public: true - - Pushword\Admin\PageCheatSheetAdmin: - tags: - - { name: sonata.admin, model_class: "%pw.entity_page%", manager_type: orm, label: admin.label.page } - calls: - - [setTemplate, [edit, "@@pwAdmin/page/page_edit.html.twig"]] - public: true - - Pushword\Admin\PageRedirectionAdmin: - tags: - - { name: sonata.admin, model_class: "%pw.entity_page%", manager_type: orm, label: admin.label.page } - calls: - - [setBaseControllerName, [Pushword\Admin\PageCRUDController:]] - - [setTemplate, [list, "@@pwAdmin/CRUD/mosaic.html.twig"]] - - [setTemplate, [show, "@@pwAdmin/page/page_show.html.twig"]] - - [setTemplate, [edit, "@@pwAdmin/page/page_edit.html.twig"]] - - [setTemplate, [preview, "@@pwAdmin/page/preview.html.twig"]] - - [setMediaClass, ["%pw.entity_media%"]] - - [setUserClass, ["%pw.entity_user%"]] - - [setPageClass, ["%pw.entity_page%"]] - public: true - - Pushword\Admin\PageCRUDController: - tags: ["controller.service_arguments"] - - Pushword\Admin\PageCheatSheetController: - tags: ["controller.service_arguments"] - - Pushword\Admin\MediaAdmin: - autowire: true - calls: - - [setTemplate, [list, "@@pwAdmin/CRUD/mosaic.html.twig"]] - - [setTemplate, [short_object_description, "@@pwAdmin/media/short_object_description.html.twig"]] - - [setPageClass, ["%pw.entity_page%"]] - - [setMediaClass, ["%pw.entity_media%"]] - tags: - - { name: sonata.admin, model_class: "%pw.entity_media%", manager_type: orm, label: admin.label.media, persist_filters: true } - - Pushword\Admin\UserAdmin: - autowire: true - tags: - - { name: sonata.admin, model_class: "%pw.entity_user%", manager_type: orm, label: admin.label.user } - public: true - calls: - - [setUserClass, ["%pw.entity_user%"]] + # diff --git a/packages/skeleton/var/app.db b/packages/skeleton/var/app.db index 7dd14ab49374fb0f2372dccd2e4dc92556c277af..00a0d890e937a1705c3c90672889f4a79296f441 100644 GIT binary patch delta 1215 zcmcIkO-vI(6zTcJB1D1-DY?BZ5kjF z55`2yCSFV=-aUvMCGo(40~gOm5;zM7jM0k+XQst)(3>`!H{EaE_r9-h-gIU|oY@fP zqeA3)?5Yr1eDGS9t5*YJa3K&}sCiO-w`z59_E|7B*DBNn_$PBp3QLl-Ki>DaSyj~{ zG_hgzn0SbE*^Y@lsG*V{ZpsCvkmOG^wes~<(;{DQHD5kV@z8ZVMnKo7m0(FPo6put zAq6RFGM!GQ+kt{KRn-vkKQ+guGXP~Z)TX7=j}C~t9xhfq)Xs(f<^k)bVI?2t?ZJ^G z(GAabQXX+VVj)#UsEu4;Z$;=CCV^TygOGxFCsRg`_f|cK?={{+Bxa2{=X^*RUGtphKL{(61=vBV#S#Q#>m z(!ge+r3LgF)`$yEg4^~eZ5^A5wT9z@(LuR_ z-ZOM!Gi*M3mNS;4_qlo70d|2{09(MwIoKpDX*t^Cd$BV|D&!7*j2<@8+18s_mb&FX z`Zlq2;(%N9=FkSXUKwsF137!t(!rR4!Hsdo3&&$zHx=(Z!4mJ-CIKU4a@=-w7hs2g zf@6DR&?7p~7{QO9{>!EM7>|X@m#SSu*>~WJEQtQrxrT$Hyd98#%0J|<^7c{~t;;Q9 zFd&F51XFe~Nx4!_8 CO+PXK delta 617 zcmZp8z|!!5Wr8%L&_o$$Mxl)f3;B5&7#Nt@Lm7C#u^(p--Pq{PJ~>ppNUTSPNen2% zz{qK;&MU~v%gdn}KTUM<0!i`7rzH=IaB(RsEBIvQWfv=`DFo%0mZTPQO z>g0D)W|LK=4JL<4yG))fZ8rImwC!X88D||XU9dLK+{E#P6O&O6Hx_{aUvUmq>!jR4;Pn5Vp*z!TWOvS*W^S|kUv4jt`ZdnVy;aJulX67 zC%@5`;9} diff --git a/packages/svg/src/DependencyInjection/Configuration.php b/packages/svg/src/DependencyInjection/Configuration.php index 7e198169a..573e8b453 100755 --- a/packages/svg/src/DependencyInjection/Configuration.php +++ b/packages/svg/src/DependencyInjection/Configuration.php @@ -23,6 +23,7 @@ public function getConfigTreeBuilder(): TreeBuilder $treeBuilder->getRootNode()->children() ->variableNode('app_fallback_properties')->defaultValue(self::DEFAULT_APP_FALLBACK)->cannotBeEmpty()->end() ->variableNode('svg_dir')->defaultValue([ + '%kernel.project_dir%/templates/icons', '%vendor_dir%/fortawesome/font-awesome/svgs/solid', '%vendor_dir%/fortawesome/font-awesome/svgs/regular', '%vendor_dir%/fortawesome/font-awesome/svgs/brands', diff --git a/packages/svg/src/TwigExtension.php b/packages/svg/src/TwigExtension.php index d5b1db60c..2db880133 100755 --- a/packages/svg/src/TwigExtension.php +++ b/packages/svg/src/TwigExtension.php @@ -23,11 +23,15 @@ public function getFunctions(): array } /** - * @param array $attr - * @param string[]|string $dir + * @param array|string $attr + * @param string[]|string $dir */ - public function getSvg(string $name, array $attr = ['class' => 'fill-current w-4 inline-block -mt-1'], array|string $dir = '', bool $retryWithFontAwesome5IconsRenamed = true): string + public function getSvg(string $name, array|string $attr = ['class' => 'fill-current w-4 inline-block -mt-1'], array|string $dir = '', bool $retryWithFontAwesome5IconsRenamed = true): string { + if (\is_string($attr)) { + $attr = ['class' => $attr]; + } + $dirs = '' !== $dir ? $dir : $this->apps->get()->get('svg_dir'); if (! \is_array($dirs)) {