1515
1616use Doctrine \Common \Collections \ArrayCollection ;
1717use Gedmo \Loggable \Entity \LogEntry ;
18+ use Gedmo \Loggable \Entity \Repository \LogEntryRepository ;
19+ use Networking \InitCmsBundle \Doctrine \Extensions \Versionable \VersionableInterface ;
1820use Networking \InitCmsBundle \Entity \BasePage ;
1921use Networking \InitCmsBundle \Entity \LayoutBlock ;
2022use Networking \InitCmsBundle \Entity \MenuItem ;
2830use Sonata \AdminBundle \Datagrid \DatagridMapper ;
2931use Sonata \AdminBundle \Datagrid \ListMapper ;
3032use Sonata \AdminBundle \Datagrid \ProxyQueryInterface ;
33+ use Sonata \AdminBundle \Exception \ModelManagerThrowable ;
3134use Sonata \AdminBundle \Filter \Model \FilterData ;
3235use Sonata \AdminBundle \Form \FormMapper ;
3336use Sonata \AdminBundle \Form \Type \Operator \ContainsOperatorType ;
5457 */
5558class PageAdmin extends BaseAdmin
5659{
57- /**
58- * @var string
59- */
60- protected $ pageLocale ;
60+ protected string $ pageLocale ;
6161
62- /**
63- * @var bool
64- */
65- protected $ canCreateHomepage = false ;
62+ protected bool $ canCreateHomepage = false ;
6663
67- /**
68- * @var string
69- */
70- protected $ repository = '' ;
64+ protected string $ repository = '' ;
7165
7266 private ?LogEntry $ lastEditedBy = null ;
7367
7468 public function __construct (
7569 protected PageManagerInterface $ pageManager ,
7670 protected array $ pageTemplates ,
7771 ) {
72+ parent ::__construct ();
7873 }
7974
8075 protected function generateBaseRoutePattern (bool $ isChildAdmin = false
@@ -133,7 +128,7 @@ protected function configureRoutes(RouteCollectionInterface $collection
133128 ['method ' => 'GET ' ]
134129 );
135130 $ collection ->add ('getPath ' , 'get_path/ ' , [], ['method ' => 'GET ' ]);
136- $ collection ->add ('batchTranslate ' , 'batch_translate ' , [] );
131+ $ collection ->add ('batchTranslate ' , 'batch_translate ' );
137132 $ collection ->add (
138133 'editPageSettings ' ,
139134 'edit_page_settings/{id}/{no_layout} ' ,
@@ -277,8 +272,6 @@ protected function configureFormFields(FormMapper $form): void
277272 $ this ->pageLocale ,
278273 $ this ->hasSubject () ? $ this ->getSubject ()
279274 ->getId () : null ,
280- false ,
281- false
282275 ),
283276 ]
284277 );
@@ -308,7 +301,7 @@ protected function configureFormFields(FormMapper $form): void
308301 }
309302 }
310303
311- $ requireUrl = $ this ->canCreateHomepage ? false : true ;
304+ $ requireUrl = ! $ this ->canCreateHomepage ;
312305
313306 if ($ this ->hasObject ()) {
314307 if (!$ this ->getSubject ()->isHome ()) {
@@ -513,9 +506,9 @@ protected function configureDatagridFilters(DatagridMapper $filter): void
513506 'row_attr ' => ['class ' => 'form-floating ' ],
514507 'placeholder ' => 'empty_option ' ,
515508 'choices ' => [
516- PageInterface ::STATUS_DRAFT => PageInterface ::STATUS_DRAFT ,
517- PageInterface ::STATUS_REVIEW => PageInterface ::STATUS_REVIEW ,
518- PageInterface ::STATUS_PUBLISHED => PageInterface ::STATUS_PUBLISHED ,
509+ VersionableInterface ::STATUS_DRAFT => VersionableInterface ::STATUS_DRAFT ,
510+ VersionableInterface ::STATUS_REVIEW => VersionableInterface ::STATUS_REVIEW ,
511+ VersionableInterface ::STATUS_PUBLISHED => VersionableInterface ::STATUS_PUBLISHED ,
519512 ],
520513 'translation_domain ' => $ this ->getTranslationDomain (),
521514 ],
@@ -535,12 +528,9 @@ public function configureDefaultFilterValues(array &$filterValues): void
535528 ];
536529 }
537530
538- /**
539- * @return bool
540- */
541- public function matchPath (ProxyQuery $ ProxyQuery , $ alias , $ field , $ data )
531+ public function matchPath (ProxyQuery $ ProxyQuery , $ alias , $ field , $ data ): bool
542532 {
543- if (!$ data || ! $ data instanceof FilterData || !$ data ->hasValue ()) {
533+ if (!$ data instanceof FilterData || !$ data ->hasValue ()) {
544534 return false ;
545535 }
546536 $ value = trim ((string ) $ data ->getValue ());
@@ -582,12 +572,7 @@ public function configureQuery(ProxyQueryInterface $query
582572 return $ query ;
583573 }
584574
585- /**
586- * @param FilterData $data
587- *
588- * @return bool
589- */
590- public function getByLocale (ProxyQuery $ ProxyQuery , $ alias , $ field , $ data )
575+ public function getByLocale (ProxyQueryInterface $ ProxyQuery , $ alias , $ field , $ data ): bool
591576 {
592577 if (is_array ($ data )) {
593578 $ data = FilterData::fromArray ($ data );
@@ -596,8 +581,6 @@ public function getByLocale(ProxyQuery $ProxyQuery, $alias, $field, $data)
596581 if (!$ locale = $ data ->getValue ()) {
597582 $ locale = $ this ->getDefaultLocale ();
598583 }
599-
600- $ alias = $ ProxyQuery ->getRootAlias ();
601584 $ ProxyQuery ->andWhere (sprintf ('%s.%s = :locale ' , $ alias , $ field ));
602585 $ ProxyQuery ->orderBy (sprintf ('%s.path ' , $ alias ), 'asc ' );
603586 $ ProxyQuery ->setParameter (':locale ' , $ locale );
@@ -674,10 +657,7 @@ protected function configureListFields(ListMapper $list): void
674657 }
675658 }
676659
677- /**
678- * @return \Doctrine\Common\Collections\ArrayCollection
679- */
680- public function getTranslationLanguages ()
660+ public function getTranslationLanguages (): ArrayCollection
681661 {
682662 $ translationLanguages = new ArrayCollection ();
683663
@@ -730,10 +710,8 @@ public function getTranslationLanguages()
730710 /**
731711 * Get the page templates from the configuration and create an array to use in the
732712 * choice field in the admin form.
733- *
734- * @return array
735713 */
736- protected function getPageTemplates ()
714+ protected function getPageTemplates (): array
737715 {
738716 $ choices = [];
739717
@@ -746,25 +724,22 @@ protected function getPageTemplates()
746724
747725 /**
748726 * If there is an object get the object template variable, else get first in template array.
749- *
750- * @return string
751727 */
752- protected function getDefaultTemplate ()
728+ protected function getDefaultTemplate (): string
753729 {
754730 if ($ this ->hasObject ()) {
755731 return $ this ->getSubject ()->getTemplateName ();
756732 }
757- $ defaultTemplate = array_key_first ($ this ->pageTemplates );
758733
759- return $ defaultTemplate ;
734+ return array_key_first ( $ this -> pageTemplates ) ;
760735 }
761736
762737 /**
763738 * Get the icons which represent the templates.
764739 *
765740 * @return array
766741 */
767- protected function getPageTemplateIcons ()
742+ protected function getPageTemplateIcons (): array
768743 {
769744 $ icons = [];
770745
@@ -775,6 +750,11 @@ protected function getPageTemplateIcons()
775750 return $ icons ;
776751 }
777752
753+ /**
754+ * @return array|array[]
755+ *
756+ * @throws \JsonException
757+ */
778758 public function configureBatchActions (array $ actions ): array
779759 {
780760 unset($ actions ['delete ' ]);
@@ -817,19 +797,17 @@ public function getExportFormats(): array
817797 * @param PageInterface $object
818798 *
819799 * @return mixed|void
800+ *
801+ * @throws ModelManagerThrowable
820802 */
821803 public function postRemove (object $ object ): void
822804 {
823805 $ contentRoute = $ object ->getContentRoute ();
824806
825- try {
826- $ this ->getModelManager ()->delete ($ contentRoute );
827- } catch (\Exception ) {
828- exit ;
829- }
807+ $ this ->getModelManager ()->delete ($ contentRoute );
830808 }
831809
832- public function hasObject ()
810+ public function hasObject (): bool
833811 {
834812 return $ this ->hasSubject () && $ this ->getSubject ()->getId ();
835813 }
@@ -846,7 +824,7 @@ public function getLastEditedBy(): ?LogEntry
846824 }
847825
848826 $ loggableClass = LogEntry::class;
849- /** @var \Gedmo\Loggable\Entity\Repository\ LogEntryRepository $repo */
827+ /** @var LogEntryRepository $repo */
850828 $ repo = $ this ->getModelManager ()->getEntityManager ($ loggableClass )
851829 ->getRepository ($ loggableClass );
852830
0 commit comments