diff --git a/config/services/field_definition_renderers.php b/config/services/field_definition_renderers.php index 5ef5f91..2f9a29c 100644 --- a/config/services/field_definition_renderers.php +++ b/config/services/field_definition_renderers.php @@ -10,6 +10,7 @@ use Dontdrinkandroot\CrudAdminBundle\Service\FieldRenderer\FieldRenderer; use Dontdrinkandroot\CrudAdminBundle\Service\FieldRenderer\JsonRendererProvider; use Dontdrinkandroot\CrudAdminBundle\Service\FieldRenderer\NullRendererProvider; +use Dontdrinkandroot\CrudAdminBundle\Service\FieldRenderer\TextRendererProvider; use Dontdrinkandroot\CrudAdminBundle\Service\FieldRenderer\ToStringRendererProvider; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; @@ -49,6 +50,10 @@ ->tag(DdrCrudAdminExtension::TAG_FIELD_RENDERER_PROVIDER, ['priority' => DdrCrudAdminExtension::PRIORITY_MEDIUM] ); + $services->set(TextRendererProvider::class) + ->tag(DdrCrudAdminExtension::TAG_FIELD_RENDERER_PROVIDER, ['priority' => DdrCrudAdminExtension::PRIORITY_MEDIUM] + ); + $services->set(ToStringRendererProvider::class) ->tag( DdrCrudAdminExtension::TAG_FIELD_RENDERER_PROVIDER, diff --git a/src/Service/FieldRenderer/TextRendererProvider.php b/src/Service/FieldRenderer/TextRendererProvider.php new file mode 100644 index 0000000..44b6945 --- /dev/null +++ b/src/Service/FieldRenderer/TextRendererProvider.php @@ -0,0 +1,28 @@ +displayType === Types::TEXT; + } + + #[Override] + public function render(FieldDefinition $fieldDefinition, mixed $value): string + { + $lines = explode("\n", $value); + $escapedLines = array_map(fn($line) => FieldRenderer::escapeHtml($line), $lines); + + return implode("
", $escapedLines); + } +}