-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into release-2015.09
- Loading branch information
Showing
20 changed files
with
739 additions
and
27 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,51 @@ | ||
parameters: | ||
# Form types | ||
ezrepoforms.policy.edit.form.class: EzSystems\RepositoryForms\Form\Type\Role\PolicyType | ||
|
||
# Validators | ||
ezrepoforms.validator.unique_role_identifier.class: EzSystems\RepositoryForms\Validator\Constraints\UniqueRoleIdentifierValidator | ||
|
||
# Action dispatchers | ||
ezrepoforms.action_dispatcher.role.class: EzSystems\RepositoryForms\Form\ActionDispatcher\RoleDispatcher | ||
ezrepoforms.action_dispatcher.policy.class: EzSystems\RepositoryForms\Form\ActionDispatcher\PolicyDispatcher | ||
|
||
# Form processors | ||
ezrepoforms.form_processor.role.class: EzSystems\RepositoryForms\Form\Processor\RoleFormProcessor | ||
ezrepoforms.form_processor.policy.class: EzSystems\RepositoryForms\Form\Processor\PolicyFormProcessor | ||
|
||
services: | ||
# Form types | ||
ezrepoforms.policy.edit.form: | ||
class: %ezrepoforms.policy.edit.form.class% | ||
arguments: [%ezpublish.api.role.policy_map%, @translator] | ||
tags: | ||
- { name: form.type, alias: ezrepoforms_policy_edit } | ||
|
||
# Validators | ||
ezrepoforms.validator.unique_role_identifier: | ||
class: %ezrepoforms.validator.unique_role_identifier.class% | ||
arguments: [@ezpublish.api.service.role] | ||
tags: | ||
- { name: validator.constraint_validator, alias: ezrepoforms.validator.unique_role_identifier } | ||
|
||
# Action dispatchers | ||
ezrepoforms.action_dispatcher.role: | ||
class: %ezrepoforms.action_dispatcher.role.class% | ||
parent: ezrepoforms.action_dispatcher.base | ||
|
||
ezrepoforms.action_dispatcher.policy: | ||
class: %ezrepoforms.action_dispatcher.policy.class% | ||
parent: ezrepoforms.action_dispatcher.base | ||
|
||
# Form processors | ||
ezrepoforms.form_processor.role: | ||
class: %ezrepoforms.form_processor.role.class% | ||
arguments: [@ezpublish.api.service.role] | ||
tags: | ||
- { name: kernel.event_subscriber } | ||
|
||
ezrepoforms.form_processor.policy: | ||
class: %ezrepoforms.form_processor.policy.class% | ||
arguments: [@ezpublish.api.service.role] | ||
tags: | ||
- { name: kernel.event_subscriber } |
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,63 @@ | ||
<?php | ||
/** | ||
* This file is part of the eZ RepositoryForms package. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
* @version //autogentag// | ||
*/ | ||
namespace EzSystems\RepositoryForms\Data\Mapper; | ||
|
||
use eZ\Publish\API\Repository\Values\User\PolicyDraft; | ||
use eZ\Publish\API\Repository\Values\ValueObject; | ||
use EzSystems\RepositoryForms\Data\Role\PolicyCreateData; | ||
use EzSystems\RepositoryForms\Data\Role\PolicyUpdateData; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
class PolicyMapper implements FormDataMapperInterface | ||
{ | ||
/** | ||
* Maps a ValueObject from eZ content repository to a data usable as underlying form data (e.g. create/update struct). | ||
* | ||
* @param ValueObject|\eZ\Publish\API\Repository\Values\User\PolicyDraft $policyDraft | ||
* @param array $params | ||
* | ||
* @return PolicyUpdateData|PolicyCreateData | ||
*/ | ||
public function mapToFormData(ValueObject $policyDraft, array $params = []) | ||
{ | ||
$resolver = new OptionsResolver(); | ||
$this->configureOptions($resolver); | ||
$params = $resolver->resolve($params); | ||
|
||
if (!$this->isPolicyNew($policyDraft)) { | ||
$data = new PolicyUpdateData([ | ||
'policyDraft' => $policyDraft, | ||
'roleDraft' => $params['roleDraft'], | ||
'initialRole' => $params['initialRole'], | ||
'moduleFunction' => "{$policyDraft->module}|{$policyDraft->function}", | ||
]); | ||
} else { | ||
$data = new PolicyCreateData([ | ||
'policyDraft' => $policyDraft, | ||
'roleDraft' => $params['roleDraft'], | ||
'initialRole' => $params['initialRole'], | ||
]); | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
private function configureOptions(OptionsResolver $optionsResolver) | ||
{ | ||
$optionsResolver | ||
->setRequired(['roleDraft', 'initialRole']) | ||
->setAllowedTypes('roleDraft', '\eZ\Publish\API\Repository\Values\User\RoleDraft') | ||
->setAllowedTypes('initialRole', '\eZ\Publish\API\Repository\Values\User\Role'); | ||
} | ||
|
||
private function isPolicyNew(PolicyDraft $policy) | ||
{ | ||
return $policy->id === null; | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
/** | ||
* This file is part of the eZ RepositoryForms package. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
* @version //autogentag// | ||
*/ | ||
namespace EzSystems\RepositoryForms\Data\Role; | ||
|
||
use eZ\Publish\Core\Repository\Values\User\PolicyCreateStruct; | ||
use EzSystems\RepositoryForms\Data\NewsnessCheckable; | ||
|
||
/** | ||
* @property-read \eZ\Publish\API\Repository\Values\User\PolicyDraft $policyDraft | ||
* @property-read \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft | ||
* @property-read \eZ\Publish\API\Repository\Values\User\Role $initialRole | ||
*/ | ||
class PolicyCreateData extends PolicyCreateStruct implements NewsnessCheckable | ||
{ | ||
use PolicyDataTrait; | ||
|
||
public function isNew() | ||
{ | ||
return true; | ||
} | ||
} |
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,49 @@ | ||
<?php | ||
/** | ||
* This file is part of the eZ RepositoryForms package. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
* @version //autogentag// | ||
*/ | ||
namespace EzSystems\RepositoryForms\Data\Role; | ||
|
||
use eZ\Publish\API\Repository\Values\User\PolicyDraft; | ||
|
||
trait PolicyDataTrait | ||
{ | ||
/** | ||
* @var PolicyDraft | ||
*/ | ||
protected $policyDraft; | ||
|
||
/** | ||
* @var \eZ\Publish\API\Repository\Values\User\RoleDraft | ||
*/ | ||
protected $roleDraft; | ||
|
||
/** | ||
* Role the draft was created from. | ||
* | ||
* @var \eZ\Publish\API\Repository\Values\User\RoleDraft | ||
*/ | ||
protected $initialRole; | ||
|
||
/** | ||
* Combination of module + function as a single string. | ||
* Example: "content|read". | ||
* | ||
* @var string | ||
*/ | ||
public $moduleFunction; | ||
|
||
public function setPolicy(PolicyDraft $policyDraft) | ||
{ | ||
$this->policy = $policyDraft; | ||
} | ||
|
||
public function getId() | ||
{ | ||
return $this->policyDraft ? $this->policyDraft->id : null; | ||
} | ||
} |
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,37 @@ | ||
<?php | ||
/** | ||
* This file is part of the eZ RepositoryForms package. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
* @version //autogentag// | ||
*/ | ||
namespace EzSystems\RepositoryForms\Data\Role; | ||
|
||
use eZ\Publish\Core\Repository\Values\User\PolicyUpdateStruct; | ||
use EzSystems\RepositoryForms\Data\NewnessChecker; | ||
|
||
/** | ||
* @property-read \eZ\Publish\API\Repository\Values\User\PolicyDraft $policyDraft | ||
* @property-read \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft | ||
* @property-read \eZ\Publish\API\Repository\Values\User\Role $initialRole | ||
*/ | ||
class PolicyUpdateData extends PolicyUpdateStruct | ||
{ | ||
use PolicyDataTrait, NewnessChecker; | ||
|
||
protected function getIdentifierValue() | ||
{ | ||
return $this->policyDraft->module; | ||
} | ||
|
||
public function getModule() | ||
{ | ||
return $this->policyDraft->module; | ||
} | ||
|
||
public function getFunction() | ||
{ | ||
return $this->policyDraft->function; | ||
} | ||
} |
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
Oops, something went wrong.