-
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.
- Loading branch information
1 parent
98453fc
commit f97d207
Showing
10 changed files
with
228 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_extensions</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_extensions: | ||
routes: | ||
detail: 'app.get_contact-extension' |
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
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Admin; | ||
|
||
use Sulu\Bundle\AdminBundle\Admin\Admin; | ||
use Sulu\Bundle\AdminBundle\Admin\View\ViewBuilderFactoryInterface; | ||
use Sulu\Bundle\AdminBundle\Admin\View\ViewCollection; | ||
use Sulu\Bundle\ContactBundle\Admin\ContactAdmin; | ||
|
||
class ContactExtensionAdmin 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_extensions_form', '/extensions') | ||
->setResourceKey('contact_extensions') | ||
->setFormKey('contact_extensions') | ||
->setTabTitle('app.extensions') | ||
->addToolbarActions($contactDetailsFormView->getOption('toolbarActions')) | ||
->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,93 @@ | ||
<?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\Controller\ContactController; | ||
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("contact-extension") | ||
*/ | ||
class ContactExtensionController extends AbstractRestController implements ClassResourceInterface, SecuredControllerInterface | ||
{ | ||
private EntityManagerInterface $entityManager; | ||
private ContactController $contactController; | ||
|
||
public function __construct( | ||
EntityManagerInterface $entityManager, | ||
ContactController $contactController, | ||
ViewHandlerInterface $viewHandler, | ||
?TokenStorageInterface $tokenStorage = null | ||
) { | ||
$this->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<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 $this->contactController->getSecurityContext(); | ||
} | ||
} |
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