diff --git a/config/forms/contact_extensions.xml b/config/forms/contact_extensions.xml new file mode 100644 index 00000000..50d712fb --- /dev/null +++ b/config/forms/contact_extensions.xml @@ -0,0 +1,21 @@ + +
+ additional_contact_data + + + + + app.social_security_number + + + + + + app.external_crm_id + + + +
diff --git a/config/packages/app_contact_extension_admin.yaml b/config/packages/app_contact_extension_admin.yaml new file mode 100644 index 00000000..1e6f790c --- /dev/null +++ b/config/packages/app_contact_extension_admin.yaml @@ -0,0 +1,5 @@ +sulu_admin: + resources: + additional_contact_data: + routes: + detail: 'app.get_contact-extension' 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..46f7fa8f --- /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', '/extensions') + ->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..a6622843 --- /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 + */ + protected function getDataForEntity(Contact $entity): array + { + return [ + 'id' => $entity->getId(), + 'socialSecurityNumber' => $entity->getSocialSecurityNumber(), + 'externalCrmId' => $entity->getExternalCrmId(), + ]; + } + + /** + * @param array $data + */ + protected function mapDataToEntity(array $data, Contact $entity): void + { + $entity->setSocialSecurityNumber($data['socialSecurityNumber']); + $entity->setExternalCrmId($data['externalCrmId']); + } + + public function getSecurityContext(): string + { + return $this->contactController->getSecurityContext(); + } +} diff --git a/src/Entity/Contact.php b/src/Entity/Contact.php new file mode 100644 index 00000000..4cab8c0e --- /dev/null +++ b/src/Entity/Contact.php @@ -0,0 +1,43 @@ +socialSecurityNumber; + } + + public function setSocialSecurityNumber(?string $socialSecurityNumber): void + { + $this->socialSecurityNumber = $socialSecurityNumber; + } + + public function getExternalCrmId(): ?string + { + return $this->externalCrmId; + } + + public function setExternalCrmId(?string $externalCrmId): void + { + $this->externalCrmId = $externalCrmId; + } +} diff --git a/translations/admin.de.json b/translations/admin.de.json index 4565f68a..2c21af5c 100644 --- a/translations/admin.de.json +++ b/translations/admin.de.json @@ -10,5 +10,8 @@ "app.album_selection_label": "{count} {count, plural, =1 {Album} other {Alben}} ausgewählt", "app.select_albums": "Alben auswählen", "app.no_album_selected": "Kein Album ausgewählt", - "app.select_album": "Album auswählen" + "app.select_album": "Album auswählen", + "app.additional_data": "Zusätzliche Daten", + "app.social_security_number": "Sozialversicherungsnummer", + "app.external_crm_id": "Externe CRM ID" } diff --git a/translations/admin.en.json b/translations/admin.en.json index 2160e113..bcb0645d 100644 --- a/translations/admin.en.json +++ b/translations/admin.en.json @@ -10,5 +10,8 @@ "app.album_selection_label": "{count} {count, plural, =1 {album} other {albums}} selected", "app.select_albums": "Select albums", "app.no_album_selected": "No album selected", - "app.select_album": "Select album" + "app.select_album": "Select album", + "app.additional_data": "Additional Data", + "app.social_security_number": "Social Security number", + "app.external_crm_id": "External CRM ID" }