diff --git a/src/new/src/PSC/Shop/CmsBundle/Controller/Backend/EditController.php b/src/new/src/PSC/Shop/CmsBundle/Controller/Backend/EditController.php index e8eddae07..ddea433d2 100755 --- a/src/new/src/PSC/Shop/CmsBundle/Controller/Backend/EditController.php +++ b/src/new/src/PSC/Shop/CmsBundle/Controller/Backend/EditController.php @@ -21,23 +21,23 @@ use PSC\Shop\CmsBundle\Form\Backend\CmsType; use PSC\Shop\CmsBundle\PSCShopCmsBundle; use PSC\Shop\EntityBundle\Entity\Cms; use PSC\Shop\EntityBundle\Entity\Motiv; +use PSC\Shop\SettingsBundle\Service\Routing; use PSC\Shop\ShippingBundle\Form\Backend\DeleteType; use PSC\Shop\ThemeBundle\Core\Config\Cms\Position; use PSC\System\PluginBundle\Form\Chain\Field; use PSC\System\SettingsBundle\Document\LogEntry; use PSC\System\SettingsBundle\Service\History; use PSC\System\SettingsBundle\Service\Log; -use PSC\Shop\SettingsBundle\Service\Routing; use PSC\System\SettingsBundle\Service\Shop; +use Symfony\Bridge\Twig\Attribute\Template; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\JsonResponse; -use Symfony\Component\HttpFoundation\Session\SessionInterface; -use Symfony\Component\Security\Core\SecurityContext; -use Symfony\Component\Routing\Attribute\Route; -use Symfony\Bridge\Twig\Attribute\Template; -use Symfony\Component\Security\Http\Attribute\IsGranted; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Session\SessionInterface; +use Symfony\Component\Routing\Attribute\Route; +use Symfony\Component\Security\Core\SecurityContext; +use Symfony\Component\Security\Http\Attribute\IsGranted; /** * EditController fürs Backend @@ -81,12 +81,10 @@ class EditController extends AbstractController EntityManagerInterface $entityManager, DocumentManager $documentManager, Routing $routing, - Shop $shopService + Shop $shopService, ) { - $customFields = $fieldService->getFields(\PSC\System\PluginBundle\Form\Interfaces\Field::Cms); $customGroups = $fieldService->getGroups(\PSC\System\PluginBundle\Form\Interfaces\Field::Cms); - $selectedShop = $shopService->getSelectedShop(); $cms = new Cms(); @@ -108,19 +106,26 @@ class EditController extends AbstractController $cmsDoc->setExtraSettings($cms->getExtraSettings()); $cmsDoc->setPluginSettings($cms->getPluginSettings()); $cmsDoc->setNoIndex($cms->isNoIndex()); - $cmsDoc->setRawText($cms->isRawText()); + $cmsDoc->setEditorMode($cms->getEditorMode()); $documentManager->persist($cmsDoc); $documentManager->flush(); - $this->logService->createLogEntry($selectedShop, $this->getUser(), LogEntry::INFO, PSCShopCmsBundle::class, $cms->getTitle(), "CMS Site saved"); + $this->logService->createLogEntry( + $selectedShop, + $this->getUser(), + LogEntry::INFO, + PSCShopCmsBundle::class, + $cms->getTitle(), + 'CMS Site saved', + ); return $this->redirectToRoute('psc_shop_cms_backend_list'); } return array( 'form' => $form->createView(), 'customFields' => $customFields, - 'customGroups' => $customGroups + 'customGroups' => $customGroups, ); } @@ -146,16 +151,17 @@ class EditController extends AbstractController EntityManagerInterface $entityManager, DocumentManager $documentManager, Routing $routing, - $uid + $uid, ) { - $customFields = $fieldService->getFields(\PSC\System\PluginBundle\Form\Interfaces\Field::Cms); $customGroups = $fieldService->getGroups(\PSC\System\PluginBundle\Form\Interfaces\Field::Cms); - + dump($customGroups); $selectedShop = $shopService->getSelectedShop(); /** @var Cms $cms */ - $cms = $entityManager->getRepository('PSC\Shop\EntityBundle\Entity\Cms')->findOneBy(array('shop' => $selectedShop, 'uid' => $uid)); + $cms = $entityManager + ->getRepository('PSC\Shop\EntityBundle\Entity\Cms') + ->findOneBy(array('shop' => $selectedShop, 'uid' => $uid)); /** @var \PSC\Shop\EntityBundle\Document\Cms $cmsDoc */ $cmsDoc = $documentManager @@ -166,17 +172,17 @@ class EditController extends AbstractController $cms->setExtraSettings($cmsDoc->getExtraSettings()); $cms->setPluginSettings($cmsDoc->getPluginSettings()); $cms->setNoIndex($cmsDoc->isNoIndex()); - $cms->setRawText($cmsDoc->isRawText()); + $cms->setEditorMode($cmsDoc->getEditorMode()); } elseif (!$cmsDoc) { $cmsDoc = new \PSC\Shop\EntityBundle\Document\Cms(); $cmsDoc->setUid($cms->getUid()); $cmsDoc->setExtraSettings($cms->getExtraSettings()); $cmsDoc->setNoIndex($cms->isNoIndex()); - $cmsDoc->setRawText($cms->isRawText()); + $cmsDoc->setEditorMode($cms->getEditorMode()); $documentManager->persist($cmsDoc); $documentManager->flush(); - } elseif ($request->isMethod('POST') && $cmsDoc && isset($request->get('cms')['rawText'])) { - $cms->setRawText($request->get('cms')['rawText']); + } elseif ($request->isMethod('POST') && $cmsDoc && isset($request->get('cms')['editorMode'])) { + $cms->setEditorMode($request->get('cms')['editorMode']); } $form = $this->createForm(CmsType::class, $cms); @@ -188,25 +194,30 @@ class EditController extends AbstractController $cmsDoc->setPluginSettings($cms->getPluginSettings()); $cmsDoc->setExtraSettings($cms->getExtraSettings()); $cmsDoc->setNoIndex($cms->isNoIndex()); - $cmsDoc->setRawText($cms->isRawText()); - $this->historyService->createHistoryEntry(new PSCHistory((string)$cms->getUid()), $cms, $cmsDoc); + $cmsDoc->setEditorMode($cms->getEditorMode()); + $this->historyService->createHistoryEntry(new PSCHistory((string) $cms->getUid()), $cms, $cmsDoc); $entityManager->persist($cms); $entityManager->flush(); $documentManager->persist($cmsDoc); $documentManager->flush(); - $this->logService->createLogEntry($selectedShop, $this->getUser(), LogEntry::INFO, PSCShopCmsBundle::class, $cms->getTitle(), "CMS Site saved"); + $this->logService->createLogEntry( + $selectedShop, + $this->getUser(), + LogEntry::INFO, + PSCShopCmsBundle::class, + $cms->getTitle(), + 'CMS Site saved', + ); } - - return array( 'cms' => $cms, 'form' => $form->createView(), 'customFields' => $customFields, 'customGroups' => $customGroups, - 'changes' => $this->historyService->getHistory(new PSCHistory(), (string)$cms->getUid()) + 'changes' => $this->historyService->getHistory(new PSCHistory(), (string) $cms->getUid()), ); } @@ -227,9 +238,8 @@ class EditController extends AbstractController EntityManagerInterface $entityManager, SessionInterface $session, Shop $shopService, - $uid + $uid, ) { - $cms = $entityManager->getRepository('PSC\Shop\EntityBundle\Entity\Cms')->findOneBy(['uid' => $uid]); $selectedShop = $shopService->getSelectedShop(); @@ -242,11 +252,15 @@ class EditController extends AbstractController $title = $cms->getTitle(); $entityManager->remove($cms); $entityManager->flush(); - $session->getFlashBag()->add( - 'success', - 'Site \'' . $title . '\' has been deleted!' + $session->getFlashBag()->add('success', 'Site \'' . $title . '\' has been deleted!'); + $this->logService->createLogEntry( + $selectedShop, + $this->getUser(), + LogEntry::INFO, + PSCShopCmsBundle::class, + $title, + 'CMS Site deleted', ); - $this->logService->createLogEntry($selectedShop, $this->getUser(), LogEntry::INFO, PSCShopCmsBundle::class, $title, "CMS Site deleted"); return $this->redirectToRoute('psc_shop_cms_backend_list'); } return $this->redirectToRoute('psc_shop_cms_backend_list'); @@ -254,7 +268,7 @@ class EditController extends AbstractController return array( 'cms' => $cms, - 'form' => $form->createView() + 'form' => $form->createView(), ); } } diff --git a/src/new/src/PSC/Shop/CmsBundle/Form/Backend/CmsType.php b/src/new/src/PSC/Shop/CmsBundle/Form/Backend/CmsType.php index c55b1befc..af03a470c 100755 --- a/src/new/src/PSC/Shop/CmsBundle/Form/Backend/CmsType.php +++ b/src/new/src/PSC/Shop/CmsBundle/Form/Backend/CmsType.php @@ -72,7 +72,7 @@ class CmsType extends AbstractType $this->entityManager = $entityManager; } - private function buildCmsTree(array $tmp = [], null|Cms $cms = null, $level = ''): array + private function buildCmsTree(array $tmp = [], ?Cms $cms = null, $level = ''): array { if ($cms) { $sites = $this->entityManager @@ -112,7 +112,14 @@ class CmsType extends AbstractType ->add('enable', CheckboxType::class, ['label' => 'psc_shop_cms.Active', 'required' => false]) ->add('notInMenu', CheckboxType::class, ['label' => 'psc_shop_cms.NotInMenu', 'required' => false]) ->add('noIndex', CheckboxType::class, ['label' => 'psc_shop_cms.NoIndex', 'required' => false]) - ->add('rawText', CheckboxType::class, ['label' => 'psc_shop_cms.rawText', 'required' => false]) + ->add('editorMode', ChoiceType::class, [ + 'label' => 'psc_shop_cms.editorMode', + 'choices' => [ + 'psc_shop_cms.editorMode.wysiwyg' => 'wysiwyg', + 'psc_shop_cms.editorMode.html' => 'html', + ], + 'required' => true, + ]) ->add('displayTitle', CheckboxType::class, ['label' => 'psc_shop_cms.DisplayTitle', 'required' => false]) ->add('sort', IntegerType::class, ['label' => 'psc_shop_cms.Sort', 'required' => false]) ->add('url', TextType::class, ['label' => 'psc_shop_cms.Url', 'required' => true]) @@ -127,29 +134,6 @@ class CmsType extends AbstractType ->getPositionsAsArray(); }), ]); - if ($options['data']->isRawText()) { - $builder->add('text', AceEditorType::class, [ - 'label' => 'psc_shop_cms.Text', - 'wrapper_attr' => [], // aceeditor wrapper html attributes. - 'width' => '90%', - 'height' => '500', - 'font_size' => 14, - 'mode' => 'ace/mode/html', // every single default mode must have ace/mode/* prefix - 'theme' => 'ace/theme/monokai', // every single default theme must have ace/theme/* prefix - 'tab_size' => null, - 'read_only' => null, - 'use_soft_tabs' => null, - 'use_wrap_mode' => null, - 'show_print_margin' => null, - 'required' => false, - 'highlight_active_line' => null, - ]); - } else { - $builder->add('text', TextareaType::class, [ - 'label' => 'psc_shop_cms.Text', - 'required' => false, - ]); - } $builder ->add('metaAuthor', TextType::class, ['label' => 'psc_shop_cms.MetaAuthor', 'required' => false]) ->add('metaKeywords', TextAreaType::class, ['label' => 'psc_shop_cms.MetaKeywords', 'required' => false]) @@ -177,12 +161,12 @@ class CmsType extends AbstractType ]); /** @var \PSC\System\PluginBundle\Form\Interfaces\Field $field */ foreach ($this->fields->getFields(\PSC\System\PluginBundle\Form\Interfaces\Field::Cms) as $field) { - $builder->add($field->buildForm($this->formFactory->createNamedBuilder( - $field->getGroup(), - FormType::class, - null, - ['mapped' => false], - ), $options)); + $var = $field->buildForm($this->formFactory->createNamedBuilder($field->getGroup(), FormType::class, null, [ + 'mapped' => false, + ]), $options); + if ($var->count() > 0) { + $builder->add($var); + } } $builder->add('save', SubmitType::class, ['label' => 'psc_shop_cms.Save']); diff --git a/src/new/src/PSC/Shop/CmsBundle/Form/Field/HtmlTextContent.php b/src/new/src/PSC/Shop/CmsBundle/Form/Field/HtmlTextContent.php new file mode 100644 index 000000000..ee898f97f --- /dev/null +++ b/src/new/src/PSC/Shop/CmsBundle/Form/Field/HtmlTextContent.php @@ -0,0 +1,73 @@ +getEditorMode() == 'html') { + $builder->add('text', AceEditorType::class, [ + 'label' => 'psc_shop_cms.Text', + 'wrapper_attr' => [], // aceeditor wrapper html attributes. + 'width' => '90%', + 'height' => '500', + 'font_size' => 14, + 'mode' => 'ace/mode/html', // every single default mode must have ace/mode/* prefix + 'theme' => 'ace/theme/monokai', // every single default theme must have ace/theme/* prefix + 'tab_size' => null, + 'read_only' => null, + 'use_soft_tabs' => null, + 'use_wrap_mode' => null, + 'show_print_margin' => null, + 'required' => false, + 'highlight_active_line' => null, + ]); + } + return $builder; + } + + public function formPreSetData(FormEvent $event): void {} + + public function formPostSetData(FormEvent $event): void + { + $data = $event->getData(); + if ($data->getEditorMode() == 'html') { + $event->getForm()->get('html')->get('text')->setData($data->getText()); + } + } + + public function formPreSubmit(FormEvent $event): void {} + + public function formPostSubmit(FormEvent $event): void {} + + public function formSubmit(FormEvent $event): void + { + $data = $event->getData(); + if ($data->getEditorMode() == 'html') { + $data->setText($event->getForm()->get('html')->get('text')->getData()); + } + } +} diff --git a/src/new/src/PSC/Shop/CmsBundle/Form/Field/WysiwygTextContent.php b/src/new/src/PSC/Shop/CmsBundle/Form/Field/WysiwygTextContent.php new file mode 100644 index 000000000..2bc5b016a --- /dev/null +++ b/src/new/src/PSC/Shop/CmsBundle/Form/Field/WysiwygTextContent.php @@ -0,0 +1,61 @@ +getEditorMode() == 'wysiwyg') { + $builder->add('text', TextareaType::class, [ + 'label' => 'psc_shop_cms.Text', + 'required' => false, + ]); + } + return $builder; + } + + public function formPreSetData(FormEvent $event): void {} + + public function formPostSetData(FormEvent $event): void + { + $data = $event->getData(); + if ($data->getEditorMode() == 'wysiwyg') { + $event->getForm()->get('wysiwyg')->get('text')->setData($data->getText()); + } + } + + public function formPreSubmit(FormEvent $event): void {} + + public function formPostSubmit(FormEvent $event): void {} + + public function formSubmit(FormEvent $event): void + { + $data = $event->getData(); + if ($data->getEditorMode() == 'wysiwyg') { + $data->setText($event->getForm()->get('wysiwyg')->get('text')->getData()); + } + } +} diff --git a/src/new/src/PSC/Shop/CmsBundle/Form/Group/HtmlText.php b/src/new/src/PSC/Shop/CmsBundle/Form/Group/HtmlText.php new file mode 100644 index 000000000..d59541a25 --- /dev/null +++ b/src/new/src/PSC/Shop/CmsBundle/Form/Group/HtmlText.php @@ -0,0 +1,28 @@ + {{ 'psc_shop_cms.Common'|trans }} - - - - - {{ 'psc_shop_cms.Text'|trans }} - @@ -53,7 +47,7 @@ {{ 'psc_shop_cms.Extended'|trans }} {% for customGroup in customGroups %} - + - - - @@ -187,24 +166,32 @@ {% for customGroup in customGroups %} - + {% if customGroup.editorMode is defined and customGroup.editorMode %} + {% if cms.editorMode in customGroup.editorMode|split(',') %} + + {% endif %} + {% else %} + + {% endif %} {% endfor %} - {% for customField in customFields %} - {% if customField.group == 'general' and customField.getTemplate %} - {{ include(customField.getTemplate, { 'form': form }) }} - {% endif %} - {% endfor %} -