diff --git a/config/forms/additional_contact_data.xml b/config/forms/additional_contact_data.xml new file mode 100644 index 00000000..50d712fb --- /dev/null +++ b/config/forms/additional_contact_data.xml @@ -0,0 +1,21 @@ + +
diff --git a/config/packages/app_additional_contact_data_admin.yaml b/config/packages/app_additional_contact_data_admin.yaml new file mode 100644 index 00000000..03c3a9e1 --- /dev/null +++ b/config/packages/app_additional_contact_data_admin.yaml @@ -0,0 +1,5 @@ +sulu_admin: + resources: + additional_contact_data: + routes: + detail: 'app.get_additional-contact-data' diff --git a/config/packages/sulu_contact.yaml b/config/packages/sulu_contact.yaml new file mode 100644 index 00000000..50daad8a --- /dev/null +++ b/config/packages/sulu_contact.yaml @@ -0,0 +1,4 @@ +sulu_contact: + objects: + contact: + model: 'App\Entity\Contact' diff --git a/config/routes_admin.yaml b/config/routes_admin.yaml index 37754b5b..b924a83a 100644 --- a/config/routes_admin.yaml +++ b/config/routes_admin.yaml @@ -4,3 +4,9 @@ app_albums_api: prefix: /admin/api resource: App\Controller\Admin\AlbumController name_prefix: app. + +app_additional_contact_data_api: + type: rest + prefix: /admin/api + resource: App\Controller\Admin\AdditionalContactDataController + name_prefix: app. diff --git a/config/services.yaml b/config/services.yaml index bd73083f..8621a12c 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -13,6 +13,7 @@ services: Sulu\Bundle\SnippetBundle\Snippet\DefaultSnippetManagerInterface: '@sulu_snippet.default_snippet.manager' Sulu\Component\PHPCR\PathCleanupInterface: '@sulu.content.path_cleaner' Doctrine\ORM\EntityManagerInterface: '@doctrine.orm.entity_manager' + Sulu\Bundle\ContactBundle\Controller\ContactController: '@sulu_contact.contact_controller' # makes classes in src/ available to be used as services # this creates a service per class whose id is the fully-qualified class name diff --git a/src/Admin/AdditionalContactDataAdmin.php b/src/Admin/AdditionalContactDataAdmin.php new file mode 100644 index 00000000..080cb2d3 --- /dev/null +++ b/src/Admin/AdditionalContactDataAdmin.php @@ -0,0 +1,47 @@ +viewBuilderFactory = $viewBuilderFactory; + } + + public function configureViews(ViewCollection $viewCollection): void + { + if ($viewCollection->has('sulu_contact.contact_edit_form.details')) { + $contactDetailsFormView = $viewCollection->get('sulu_contact.contact_edit_form.details')->getView(); + + $viewCollection->add( + $this->viewBuilderFactory + ->createFormViewBuilder('app.additional_contact_data_form', '/additional-data') + ->setResourceKey('additional_contact_data') + ->setFormKey('additional_contact_data') + ->setTabTitle('app.additional_data') + ->addToolbarActions($contactDetailsFormView->getOption('toolbarActions')) + ->setTabOrder($contactDetailsFormView->getOption('tabOrder') + 1) + ->setParent(ContactAdmin::CONTACT_EDIT_FORM_VIEW) + ); + } + } + + public static function getPriority(): int + { + return ContactAdmin::getPriority() - 1; + } +} diff --git a/src/Controller/Admin/AdditionalContactDataController.php b/src/Controller/Admin/AdditionalContactDataController.php new file mode 100644 index 00000000..a8c05c1a --- /dev/null +++ b/src/Controller/Admin/AdditionalContactDataController.php @@ -0,0 +1,93 @@ +entityManager = $entityManager; + $this->contactController = $contactController; + + parent::__construct($viewHandler, $tokenStorage); + } + + public function getAction(int $id): Response + { + $contact = $this->entityManager->getRepository(Contact::class)->find($id); + if (!$contact) { + throw new NotFoundHttpException(); + } + + return $this->handleView($this->view($this->getDataForEntity($contact))); + } + + public function putAction(Request $request, int $id): Response + { + $contact = $this->entityManager->getRepository(Contact::class)->find($id); + if (!$contact) { + throw new NotFoundHttpException(); + } + + $this->mapDataToEntity($request->request->all(), $contact); + $this->entityManager->flush(); + + return $this->handleView($this->view($this->getDataForEntity($contact))); + } + + public function deleteAction(int $id): Response + { + return $this->contactController->deleteAction($id); + } + + /** + * @return array