Skip to content

Commit

Permalink
Add basic support for editing through eZ Platform Admin UI (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
emodric authored and andrerom committed Dec 19, 2017
1 parent 86f8cc0 commit 6de27fc
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
}
],
"require": {
"ezsystems/ezpublish-kernel": "^6.11@dev || ^7.0@dev"
"ezsystems/ezpublish-kernel": "^6.11@dev || ^7.0@dev",
"ezsystems/repository-forms": "^1.9 || ^2.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
Expand Down
28 changes: 28 additions & 0 deletions lib/FieldType/XmlText/FormMapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace eZ\Publish\Core\FieldType\XmlText;

use EzSystems\RepositoryForms\Data\Content\FieldData;
use EzSystems\RepositoryForms\FieldType\FieldValueFormMapperInterface;
use Symfony\Component\Form\FormInterface;

class FormMapper implements FieldValueFormMapperInterface
{
public function mapFieldValueForm(FormInterface $fieldForm, FieldData $data)
{
$fieldForm
->add(
$fieldForm->getConfig()->getFormFactory()->createBuilder()
->create(
'value',
FormType::class,
array(
'required' => $data->fieldDefinition->isRequired,
'label' => $data->fieldDefinition->getName(),
)
)
->setAutoInitialize(false)
->getForm()
);
}
}
38 changes: 38 additions & 0 deletions lib/FieldType/XmlText/FormType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace eZ\Publish\Core\FieldType\XmlText;

use eZ\Publish\API\Repository\FieldTypeService;
use EzSystems\RepositoryForms\FieldType\DataTransformer\FieldValueTransformer;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;

class FormType extends AbstractType
{
/**
* @var \eZ\Publish\API\Repository\FieldTypeService
*/
private $fieldTypeService;

public function __construct(FieldTypeService $fieldTypeService)
{
$this->fieldTypeService = $fieldTypeService;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('xml', TextareaType::class, array('attr' => array('rows' => 10)))
->addModelTransformer(
new FieldValueTransformer(
$this->fieldTypeService->getFieldType('ezxmltext')
)
);
}

public function getBlockPrefix()
{
return 'ezplatform_fieldtype_ezxmltext';
}
}
13 changes: 13 additions & 0 deletions lib/settings/fieldtypes.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
parameters:
ezpublish.fieldType.ezxmltext.class: eZ\Publish\Core\FieldType\XmlText\Type
ezpublish.fieldType.ezxmltext.formMapper.class: eZ\Publish\Core\FieldType\XmlText\FormMapper
ezpublish.fieldType.ezxmltext.formType.class: eZ\Publish\Core\FieldType\XmlText\FormType

services:
ezpublish.fieldType.ezxmltext:
Expand All @@ -10,3 +12,14 @@ services:
tags:
- {name: ezpublish.fieldType, alias: ezxmltext}

ezpublish.fieldType.ezxmltext.formMapper:
class: "%ezpublish.fieldType.ezxmltext.formMapper.class%"
tags:
- { name: ez.fieldFormMapper.value, fieldType: ezxmltext }

ezpublish.fieldType.ezxmltext.formType:
class: "%ezpublish.fieldType.ezxmltext.formType.class%"
arguments:
- "@ezpublish.api.service.field_type"
tags:
- { name: form.type }

0 comments on commit 6de27fc

Please sign in to comment.