Skip to content

Commit

Permalink
EZP-27646: Implement editing support for User FieldType
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciej Kobus committed Sep 6, 2017
1 parent cfd3c7c commit 145e95f
Show file tree
Hide file tree
Showing 12 changed files with 265 additions and 71 deletions.
11 changes: 11 additions & 0 deletions bundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ parameters:
ezrepoforms.form_processor.content_type_group.class: EzSystems\RepositoryForms\Form\Processor\ContentTypeGroupFormProcessor
ezrepoforms.form_processor.content.class: EzSystems\RepositoryForms\Form\Processor\ContentFormProcessor
ezrepoforms.form_processor.user_register.class: EzSystems\RepositoryForms\Form\Processor\UserRegisterFormProcessor
ezrepoforms.form_processor.user_based_content.class: EzSystems\RepositoryForms\Form\Processor\UserBasedContentFormProcessor

ezrepoforms.controller.content_edit.class: EzSystems\RepositoryFormsBundle\Controller\ContentEditController
ezrepoforms.controller.user_register.class: EzSystems\RepositoryFormsBundle\Controller\UserRegisterController
Expand Down Expand Up @@ -363,6 +364,16 @@ services:
tags:
- { name: kernel.event_subscriber }

ezrepoforms.form_processor.user_based_content:
class: "%ezrepoforms.form_processor.user_based_content.class%"
arguments:
- '@ezpublish.api.repository'
- '@ezpublish.api.service.user'
- '@ezpublish.api.service.location'
- '@router'
tags:
- { name: kernel.event_subscriber }

ezrepoforms.form_processor.content_type_group:
class: "%ezrepoforms.form_processor.content_type_group.class%"
arguments: ["@ezpublish.api.service.content_type"]
Expand Down
6 changes: 3 additions & 3 deletions features/Context/UserRegistrationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ public function iFillInTheFormWithValidValues()

$page->fillField('ezrepoforms_user_register[fieldsData][first_name][value]', 'firstname');
$page->fillField('ezrepoforms_user_register[fieldsData][last_name][value]', 'firstname');
$page->fillField('ezrepoforms_user_register[fieldsData][user_account][value][username]', $this->registrationUsername);
$page->fillField('ezrepoforms_user_register[fieldsData][user_account][value][login]', $this->registrationUsername);
$page->fillField('ezrepoforms_user_register[fieldsData][user_account][value][email]', $this->registrationUsername . '@example.com');
$page->fillField('ezrepoforms_user_register[fieldsData][user_account][value][password][first]', self::$password);
$page->fillField('ezrepoforms_user_register[fieldsData][user_account][value][password][second]', self::$password);
$page->fillField('ezrepoforms_user_register[fieldsData][user_account][value][passwordHash][first]', self::$password);
$page->fillField('ezrepoforms_user_register[fieldsData][user_account][value][passwordHash][second]', self::$password);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Data/Content/ContentCreateData.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* @property-read \EzSystems\RepositoryForms\Data\Content\FieldData[] $fieldsData
*/
class ContentCreateData extends ContentCreateStruct implements NewnessCheckable
class ContentCreateData extends ContentCreateStruct implements NewnessCheckable, ContentDataCollectorInterface
{
use ContentData;

Expand Down
19 changes: 19 additions & 0 deletions lib/Data/Content/ContentData.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,27 @@ trait ContentData
*/
protected $fieldsData;

/**
* @param \EzSystems\RepositoryForms\Data\Content\FieldData[] $fieldsData
*/
public function setFieldsData(array $fieldsData)
{
$this->fieldsData = $fieldsData;
}

/**
* @param \EzSystems\RepositoryForms\Data\Content\FieldData $fieldData
*/
public function addFieldData(FieldData $fieldData)
{
$this->fieldsData[$fieldData->fieldDefinition->identifier] = $fieldData;
}

/**
* @return \EzSystems\RepositoryForms\Data\Content\FieldData[]
*/
public function getFieldsData()
{
return $this->fieldsData;
}
}
36 changes: 36 additions & 0 deletions lib/Data/Content/ContentDataCollectorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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\Content;

/**
* Lets implementing class hold content fields data.
*/
interface ContentDataCollectorInterface
{
/**
* Sets Fields Data.
*
* @param FieldData[]|array $fieldsData
*/
public function setFieldsData(array $fieldsData);

/**
* Adds single field information.
*
* @param FieldData $fieldData
*/
public function addFieldData(FieldData $fieldData);

/**
* Returns content's fields data.
*
* @return FieldData[]|array
*/
public function getFieldsData();
}
2 changes: 1 addition & 1 deletion lib/Data/Content/ContentUpdateData.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @property-read \EzSystems\RepositoryForms\Data\Content\FieldData[] $fieldsData
* @property-read \eZ\Publish\API\Repository\Values\Content\Content[] $contentDraft
*/
class ContentUpdateData extends ContentUpdateStruct implements NewnessCheckable
class ContentUpdateData extends ContentUpdateStruct implements NewnessCheckable, ContentDataCollectorInterface
{
use ContentData;

Expand Down
39 changes: 0 additions & 39 deletions lib/Data/User/UserAccountFieldData.php

This file was deleted.

3 changes: 2 additions & 1 deletion lib/Data/User/UserCreateData.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
use eZ\Publish\API\Repository\Values\User\UserGroup;
use eZ\Publish\Core\Repository\Values\User\UserCreateStruct;
use EzSystems\RepositoryForms\Data\Content\ContentData;
use EzSystems\RepositoryForms\Data\Content\ContentDataCollectorInterface;
use EzSystems\RepositoryForms\Data\NewnessCheckable;

/**
* @property-read \EzSystems\RepositoryForms\Data\Content\FieldData[] $fieldsData
*/
class UserCreateData extends UserCreateStruct implements NewnessCheckable
class UserCreateData extends UserCreateStruct implements NewnessCheckable, ContentDataCollectorInterface
{
use ContentData;

Expand Down
26 changes: 8 additions & 18 deletions lib/FieldType/Mapper/UserAccountFieldValueFormMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
namespace EzSystems\RepositoryForms\FieldType\Mapper;

use eZ\Publish\API\Repository\FieldTypeService;
use eZ\Publish\Core\FieldType\User\Value as ApiUserValue;
use EzSystems\RepositoryForms\Data\Content\FieldData;
use EzSystems\RepositoryForms\Data\User\UserAccountFieldData;
use EzSystems\RepositoryForms\FieldType\DataTransformer\FieldValueTransformer;
use EzSystems\RepositoryForms\FieldType\FieldValueFormMapperInterface;
use EzSystems\RepositoryForms\Form\Type\User\UserAccountType;
use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

Expand Down Expand Up @@ -45,25 +43,17 @@ public function mapFieldValueForm(FormInterface $fieldForm, FieldData $data)
$formConfig = $fieldForm->getConfig();
$names = $fieldDefinition->getNames();
$label = $fieldDefinition->getName($formConfig->getOption('languageCode')) ?: reset($names);
$inEditingMode = $data->value != $fieldDefinition->defaultValue;

$fieldForm
->add(
$formConfig->getFormFactory()->createBuilder()
->create('value', UserAccountType::class, ['required' => $fieldDefinition->isRequired, 'label' => $label])
->addModelTransformer(
new CallbackTransformer(
function (ApiUserValue $data) {
return new UserAccountFieldData($data->login, null, $data->email);
},
function ($submittedData) {
return new UserAccountFieldData(
$submittedData->username,
$submittedData->password,
$submittedData->email
);
}
)
)
->create('value', UserAccountType::class, [
'required' => $fieldDefinition->isRequired,
'label' => $label,
'editing_mode' => $inEditingMode,
])
->addModelTransformer(new FieldValueTransformer($this->fieldTypeService->getFieldType($fieldDefinition->fieldTypeIdentifier)))
->setAutoInitialize(false)
->getForm()
);
Expand Down
Loading

0 comments on commit 145e95f

Please sign in to comment.