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/src/Admin/AdditionalContactDataAdmin.php b/src/Admin/AdditionalContactDataAdmin.php new file mode 100644 index 00000000..871457cb --- /dev/null +++ b/src/Admin/AdditionalContactDataAdmin.php @@ -0,0 +1,48 @@ +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([new ToolbarAction('sulu_admin.save')]) + ->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..e4222497 --- /dev/null +++ b/src/Controller/Admin/AdditionalContactDataController.php @@ -0,0 +1,88 @@ +entityManager = $entityManager; + + parent::__construct($viewHandler, $tokenStorage); + } + + public function getAction(int $id): Response + { + /** @var Contact|null $contact */ + $contact = $this->entityManager->getRepository(ContactInterface::class)->find($id); + if (!$contact) { + throw new NotFoundHttpException(); + } + + return $this->handleView($this->view($this->getDataForEntity($contact))); + } + + public function putAction(Request $request, int $id): Response + { + /** @var Contact|null $contact */ + $contact = $this->entityManager->getRepository(ContactInterface::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))); + } + + /** + * @return array