Skip to content

Commit

Permalink
feat: Adding TextRendererProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
philipsorst committed Oct 3, 2024
1 parent 279ccb2 commit bf2e159
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config/services/field_definition_renderers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
28 changes: 28 additions & 0 deletions src/Service/FieldRenderer/TextRendererProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Dontdrinkandroot\CrudAdminBundle\Service\FieldRenderer;

use BackedEnum;
use Doctrine\DBAL\Types\Types;
use Dontdrinkandroot\CrudAdminBundle\Model\FieldDefinition;
use Override;
use UnitEnum;

class TextRendererProvider implements FieldRendererProviderInterface
{

#[Override]
public function supports(FieldDefinition $fieldDefinition, mixed $value): bool
{
return $fieldDefinition->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("<br/>", $escapedLines);
}
}

0 comments on commit bf2e159

Please sign in to comment.