-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional data tab to contact entity
- Loading branch information
1 parent
89bc9d4
commit 4ae2f04
Showing
9 changed files
with
223 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" ?> | ||
<form xmlns="http://schemas.sulu.io/template/template" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://schemas.sulu.io/template/template http://schemas.sulu.io/template/form-1.0.xsd" | ||
> | ||
<key>contact_additional_data</key> | ||
|
||
<properties> | ||
<property name="socialSecurityNumber" type="text_line" colspan="6"> | ||
<meta> | ||
<title>app.social_security_number</title> | ||
</meta> | ||
</property> | ||
|
||
<property name="externalCrmId" type="text_line" colspan="6"> | ||
<meta> | ||
<title>app.external_crm_id</title> | ||
</meta> | ||
</property> | ||
</properties> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sulu_admin: | ||
resources: | ||
contact_additional_data: | ||
routes: | ||
detail: 'app.get_additional-contact-data' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
sulu_contact: | ||
objects: | ||
contact: | ||
model: 'App\Entity\Contact' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Admin; | ||
|
||
use Sulu\Bundle\AdminBundle\Admin\Admin; | ||
use Sulu\Bundle\AdminBundle\Admin\View\ToolbarAction; | ||
use Sulu\Bundle\AdminBundle\Admin\View\ViewBuilderFactoryInterface; | ||
use Sulu\Bundle\AdminBundle\Admin\View\ViewCollection; | ||
use Sulu\Bundle\ContactBundle\Admin\ContactAdmin; | ||
|
||
class AppAdmin extends Admin | ||
{ | ||
/** | ||
* @var ViewBuilderFactoryInterface | ||
*/ | ||
private $viewBuilderFactory; | ||
|
||
public function __construct( | ||
ViewBuilderFactoryInterface $viewBuilderFactory | ||
) { | ||
$this->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.contact_additional_data_form', '/additional-data') | ||
->setResourceKey('contact_additional_data') | ||
->setFormKey('contact_additional_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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller\Admin; | ||
|
||
use App\Entity\Contact; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use FOS\RestBundle\View\ViewHandlerInterface; | ||
use HandcraftedInTheAlps\RestRoutingBundle\Controller\Annotations\RouteResource; | ||
use HandcraftedInTheAlps\RestRoutingBundle\Routing\ClassResourceInterface; | ||
use Sulu\Bundle\ContactBundle\Admin\ContactAdmin; | ||
use Sulu\Bundle\ContactBundle\Entity\ContactInterface; | ||
use Sulu\Component\Rest\AbstractRestController; | ||
use Sulu\Component\Security\SecuredControllerInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; | ||
|
||
/** | ||
* @RouteResource("additional-contact-data") | ||
*/ | ||
class ContactAdditionalDataController extends AbstractRestController implements ClassResourceInterface, SecuredControllerInterface | ||
{ | ||
private EntityManagerInterface $entityManager; | ||
|
||
public function __construct( | ||
EntityManagerInterface $entityManager, | ||
ViewHandlerInterface $viewHandler, | ||
?TokenStorageInterface $tokenStorage = null | ||
) { | ||
$this->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<string, mixed> | ||
*/ | ||
protected function getDataForEntity(Contact $entity): array | ||
{ | ||
return [ | ||
'id' => $entity->getId(), | ||
'socialSecurityNumber' => $entity->getSocialSecurityNumber(), | ||
'externalCrmId' => $entity->getExternalCrmId(), | ||
]; | ||
} | ||
|
||
/** | ||
* @param array<string, mixed> $data | ||
*/ | ||
protected function mapDataToEntity(array $data, Contact $entity): void | ||
{ | ||
$entity->setSocialSecurityNumber($data['socialSecurityNumber']); | ||
$entity->setExternalCrmId($data['externalCrmId']); | ||
} | ||
|
||
public function getSecurityContext(): string | ||
{ | ||
return ContactAdmin::CONTACT_SECURITY_CONTEXT; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace App\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Sulu\Bundle\ContactBundle\Entity\Contact as SuluContact; | ||
|
||
/** | ||
* @ORM\Entity() | ||
* @ORM\Table(name="co_contacts") | ||
*/ | ||
class Contact extends SuluContact | ||
{ | ||
/** | ||
* @ORM\Column(type="string", length=63, nullable=true) | ||
*/ | ||
private ?string $socialSecurityNumber; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=63, nullable=true) | ||
*/ | ||
private ?string $externalCrmId; | ||
|
||
public function getSocialSecurityNumber(): ?string | ||
{ | ||
return $this->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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters