-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EZP-27628: Implement editing support for RichText FieldType
- Loading branch information
Maciej Kobus
committed
Sep 5, 2017
1 parent
afc4a97
commit 8a29ed0
Showing
4 changed files
with
119 additions
and
5 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
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,14 @@ | ||
# Backwards compatibility changes | ||
|
||
Changes affecting version compatibility with former or future versions. | ||
|
||
## Changes | ||
- EZP-27628: Implement editing support for RichText FieldType | ||
|
||
What changed: `ezrepoforms.field_type.form_mapper.ezrichtext` requires `ezpublish.api.service.field_type` and `ezpublish.fieldType.ezrichtext.converter.edit.xhtml5` dependencies. | ||
|
||
How it might affect your code: If you are implementing a subclass, make sure you are injecting required services. | ||
|
||
## Deprecations | ||
|
||
## Removed features |
63 changes: 63 additions & 0 deletions
63
lib/FieldType/DataTransformer/RichTextValueTransformer.php
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\FieldType\DataTransformer; | ||
|
||
use eZ\Publish\API\Repository\FieldType; | ||
use eZ\Publish\Core\FieldType\RichText\Converter; | ||
use eZ\Publish\Core\FieldType\RichText\Value; | ||
use Symfony\Component\Form\DataTransformerInterface; | ||
|
||
/** | ||
* DataTransformer for RichText\Value. | ||
*/ | ||
class RichTextValueTransformer implements DataTransformerInterface | ||
{ | ||
/** @var FieldType */ | ||
private $fieldType; | ||
|
||
/** | ||
* @var \eZ\Publish\Core\FieldType\RichText\Converter | ||
*/ | ||
protected $docbookToXhtml5EditConverter; | ||
|
||
public function __construct(FieldType $fieldType, Converter $docbookToXhtml5EditConverter) | ||
{ | ||
$this->fieldType = $fieldType; | ||
$this->docbookToXhtml5EditConverter = $docbookToXhtml5EditConverter; | ||
} | ||
|
||
/** | ||
* @param mixed $value | ||
* | ||
* @return string | ||
*/ | ||
public function transform($value) | ||
{ | ||
if (!$value instanceof Value) { | ||
return ''; | ||
} | ||
|
||
return $this->docbookToXhtml5EditConverter->convert($value->xml)->saveXML(); | ||
} | ||
|
||
/** | ||
* @param mixed $value | ||
* | ||
* @return Value|null | ||
*/ | ||
public function reverseTransform($value) | ||
{ | ||
if ($value === null || empty($value)) { | ||
return $this->fieldType->getEmptyValue(); | ||
} | ||
|
||
return $this->fieldType->fromHash(['xml' => $value]); | ||
} | ||
} |
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