Skip to content

Commit

Permalink
Removed event "rep.value.html" when exporting as html.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Berthereau authored and Daniel Berthereau committed Jul 8, 2024
1 parent 67bbceb commit e8afe35
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/Form/Writer/FormatTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public function appendFormats()
'label' => 'Format of values', // @translate
'value_options' => [
'string' => 'String', // @translate
'html' => 'Html (may contain output of modules)', // @translate
'html' => 'Html', // @translate
// TODO Add output for html with event for modules? Probably useless.
// 'html_modules' => 'Html (with output of modules)', // @translate
],
],
'attributes' => [
Expand Down
12 changes: 12 additions & 0 deletions src/Formatter/AbstractFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ abstract class AbstractFormatter implements FormatterInterface
*/
protected $api;

/**
* @var \Omeka\DataType\Manager
*/
protected $dataTypeManager;

/**
* @var \Common\Stdlib\EasyMeta
*/
Expand All @@ -69,6 +74,11 @@ abstract class AbstractFormatter implements FormatterInterface
*/
protected $translator;

/**
* @var \Laminas\View\Renderer\PhpRenderer
*/
protected $viewRenderer;

/**
* @var \Omeka\Api\Representation\AbstractResourceEntityRepresentation[]
*/
Expand Down Expand Up @@ -156,6 +166,8 @@ public function __construct(ServiceLocatorInterface $services)
$this->logger = $this->services->get('Omeka\Logger');
$this->translator = $this->services->get('MvcTranslator');
$this->easyMeta = $services->get('EasyMeta');
$this->viewRenderer = $services->get('ViewRenderer');
$this->dataTypeManager = $services->get('Omeka\DataTypeManager');
}

public function getLabel(): string
Expand Down
21 changes: 18 additions & 3 deletions src/Traits/MetadataToStringTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,13 @@ protected function stringMetadata(AbstractResourceRepresentation $resource, $met
break;
case 'html':
case 'rdf:HTML':
$v = $v->asHtml();
$v = $this->asHtmlWithoutEvent($v);
break;
case 'literal':
// case $baseType === 'literal':
default:
$v = $params['format_generic'] === 'html'
? $v->asHtml()
? $this->asHtmlWithoutEvent($v)
: (string) $v;
break;
}
Expand All @@ -269,7 +269,7 @@ protected function stringifyUri(ValueRepresentation $value, array $params): stri
$v = (string) $value->uri();
break;
case 'html':
$v = $value->asHtml();
$v = $this->asHtmlWithoutEvent($value);
break;
case 'uri_label':
default:
Expand Down Expand Up @@ -386,4 +386,19 @@ protected function isAdminRequest(): bool
return $isAdminRequest
?? $isAdminRequest = $this->services->get('Omeka\Status')->isAdminRequest();
}

/**
* Get a value like method asHtml() but without triggering event "rep.value.html".
*
* This is useful in particular for modules AdvancedResourceTemplate,
* MetadataBrowse and RedactValues.
*
* @see \Omeka\Api\Representation\ValueRepresentation::asHtml()
*/
protected function asHtmlWithoutEvent(ValueRepresentation $value): string
{
return $this->dataTypeManager
->get($value->type())
->render($this->viewRenderer, $value);
}
}
12 changes: 12 additions & 0 deletions src/Writer/AbstractWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ abstract class AbstractWriter implements WriterInterface, Configurable, Parametr
*/
protected $api;

/**
* @var \Omeka\DataType\Manager
*/
protected $dataTypeManager;

/**
* @var \Common\Stdlib\EasyMeta
*/
Expand All @@ -51,6 +56,11 @@ abstract class AbstractWriter implements WriterInterface, Configurable, Parametr
*/
protected $translator;

/**
* @var \Laminas\View\Renderer\PhpRenderer
*/
protected $viewRenderer;

/**
* @var Job
*/
Expand Down Expand Up @@ -120,6 +130,8 @@ public function __construct(ServiceLocatorInterface $services)
$this->logger = $services->get('Omeka\Logger');
$this->translator = $services->get('MvcTranslator');
$this->easyMeta = $services->get('EasyMeta');
$this->viewRenderer = $services->get('ViewRenderer');
$this->dataTypeManager = $services->get('Omeka\DataTypeManager');

/** @var \Omeka\Module\Manager $moduleManager */
$moduleManager = $this->getServiceLocator()->get('Omeka\ModuleManager');
Expand Down

0 comments on commit e8afe35

Please sign in to comment.