forked from ezsystems/repository-forms
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ezsystems#151 from webhdx/EZP-27628_richtext
EZP-27628: Implement editing support for RichText FieldType
- Loading branch information
Showing
4 changed files
with
111 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
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