Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 03e1003

Browse files
committed
feature EasyCorp#478 Added a new "raw" field type to show unescaped values (javiereguiluz)
This PR was merged into the master branch. Discussion ---------- Added a new "raw" field type to show unescaped values This fixes EasyCorp#431 Commits ------- 121bf84 Added a new "raw" field type to show unescaped values
2 parents 5576eb7 + 121bf84 commit 03e1003

124 files changed

Lines changed: 306 additions & 27 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ private function addDesignSection(ArrayNodeDefinition $rootNode)
291291
->scalarNode('field_id')->info('Used to render the field called "id". This avoids formatting its value as any other regular number (with decimals and thousand separators) ')->end()
292292
->scalarNode('field_image')->info('Used to render image field types (a special type that displays the image contents)')->end()
293293
->scalarNode('field_integer')->info('Used to render integer field types')->end()
294+
->scalarNode('field_raw')->info('Used to render unescaped values')->end()
294295
->scalarNode('field_simple_array')->info('Used to render simple array field types')->end()
295296
->scalarNode('field_smallint')->info('Used to render smallint field types')->end()
296297
->scalarNode('field_string')->info('Used to render string field types')->end()

DependencyInjection/EasyAdminExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class EasyAdminExtension extends Extension
4949
'field_id' => '@EasyAdmin/default/field_id.html.twig',
5050
'field_image' => '@EasyAdmin/default/field_image.html.twig',
5151
'field_integer' => '@EasyAdmin/default/field_integer.html.twig',
52+
'field_raw' => '@EasyAdmin/default/field_raw.html.twig',
5253
'field_simple_array' => '@EasyAdmin/default/field_simple_array.html.twig',
5354
'field_smallint' => '@EasyAdmin/default/field_smallint.html.twig',
5455
'field_string' => '@EasyAdmin/default/field_string.html.twig',

Resources/doc/getting-started/4-views-and-actions.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ Customize the Properties Appearance
223223

224224
By default, properties are displayed with the most appropriate appearance
225225
according to their data types and their labels are generated automatically
226-
based on their property name (e.g. if the property name is `published`, the
226+
based on their property name (e.g. if the property name is `published`, the
227227
label will be `Published` and if the name is `dateOfBirth`, the label will be
228228
`Date of birth`).
229229

230-
In order to customize the appearance of the properties,use the following
230+
In order to customize the appearance of the properties,use the following
231231
expanded field configuration:
232232

233233
```yaml
@@ -310,6 +310,9 @@ These are the options that you can define for each field:
310310
`show` views (as explained later in this chapter).
311311
* `toggle`, displays a boolean value as a flip switch in the `list`
312312
and `search` views (as explained later in this chapter).
313+
* `raw`, displays the value unescaped (thanks to the `raw` Twig filter),
314+
which is useful when the content stores HTML code that must be rendered
315+
instead of displayed as HTML tags (as explained later in this chapter).
313316

314317
In addition to these "official" options, you can define any custom option for
315318
the fields. These custom options are passed to the template that renders each
@@ -472,8 +475,8 @@ be modified:
472475

473476
### Customize Image Properties
474477

475-
If some property stores the URL of an image, you can show the actual image in
476-
the `list`, `search` and `show` views instead of its URL. Just set the type of
478+
If some property stores the URL of an image, you can show the actual image in
479+
the `list`, `search` and `show` views instead of its URL. Just set the type of
477480
the property to `image`:
478481

479482
```yaml
@@ -538,6 +541,25 @@ easy_admin:
538541
The base paths defined for a property always have priority over the one defined
539542
globally for the entity.
540543

544+
### Displaying Raw Values
545+
546+
All the string-based values are escaped before displaying them. For that reason,
547+
if the value stores HTML content, you'll see the HTML tags instead of the rendered
548+
HTML content. In case you want to display the rendered content, set the type of
549+
the property to `raw`:
550+
551+
```yaml
552+
easy_admin:
553+
entities:
554+
Product:
555+
class: AppBundle\Entity\Product
556+
list:
557+
fields:
558+
- { property: 'features', type: 'raw' }
559+
# ...
560+
# ...
561+
```
562+
541563
List View Configuration
542564
-----------------------
543565

@@ -581,7 +603,7 @@ Edit and New Views Configuration
581603
### The Special Form View
582604

583605
The `edit` and `new` views are pretty similar, so most of the times you apply
584-
the same customization to them. Instead of duplicating the configuration for
606+
the same customization to them. Instead of duplicating the configuration for
585607
both views, you can use the special `form` view:
586608

587609
```yaml

Resources/doc/tutorials/advanced-design-customization.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ Doctrine data type and are self-explanatory):
226226
* `field_image`, related to the special `image` type defined by EasyAdmin
227227
used to display the contents of an image.
228228
* `field_integer`
229+
* `field_raw`, renders the value of the property without applying any escape
230+
mechanism.
229231
* `field_simple_array`
230232
* `field_smallint`
231233
* `field_string`
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{ value|raw }}

Tests/Controller/RawFieldTest.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the EasyAdminBundle.
5+
*
6+
* (c) Javier Eguiluz <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace JavierEguiluz\Bundle\EasyAdminBundle\Tests\Controller;
13+
14+
use Symfony\Component\DomCrawler\Crawler;
15+
use JavierEguiluz\Bundle\EasyAdminBundle\Tests\Fixtures\AbstractTestCase;
16+
17+
class RawFieldTest extends AbstractTestCase
18+
{
19+
public function setUp()
20+
{
21+
parent::setUp();
22+
23+
$this->initClient(array('environment' => 'raw_field'));
24+
}
25+
26+
public function testListViewRawField()
27+
{
28+
$crawler = $this->requestListView();
29+
30+
$this->assertRegExp('/\s*<ul>\s*(<li>.*<\/li>\s*){2}\s*<\/ul>/', $crawler->filter('#main table td[data-label="Html features"]')->eq(0)->html());
31+
}
32+
33+
public function testShowViewRawField()
34+
{
35+
$crawler = $this->requestShowView();
36+
37+
$this->assertRegExp('/\s*<ul>\s*(<li>.*<\/li>\s*){2}\s*<\/ul>/', $crawler->filter('#main .form-control')->eq(0)->html());
38+
}
39+
40+
/**
41+
* @return Crawler
42+
*/
43+
private function requestListView()
44+
{
45+
return $this->getBackendPage(array(
46+
'action' => 'list',
47+
'entity' => 'Product',
48+
'view' => 'list',
49+
));
50+
}
51+
52+
/**
53+
* @return Crawler
54+
*/
55+
private function requestShowView()
56+
{
57+
return $this->getBackendPage(array(
58+
'action' => 'show',
59+
'entity' => 'Product',
60+
'id' => '50',
61+
));
62+
}
63+
}

Tests/DependencyInjection/fixtures/configurations/output/config_001.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ easy_admin:
106106
field_id: '@EasyAdmin/default/field_id.html.twig'
107107
field_image: '@EasyAdmin/default/field_image.html.twig'
108108
field_integer: '@EasyAdmin/default/field_integer.html.twig'
109+
field_raw: '@EasyAdmin/default/field_raw.html.twig'
109110
field_simple_array: '@EasyAdmin/default/field_simple_array.html.twig'
110111
field_smallint: '@EasyAdmin/default/field_smallint.html.twig'
111112
field_string: '@EasyAdmin/default/field_string.html.twig'

Tests/DependencyInjection/fixtures/configurations/output/config_002.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ easy_admin:
106106
field_id: '@EasyAdmin/default/field_id.html.twig'
107107
field_image: '@EasyAdmin/default/field_image.html.twig'
108108
field_integer: '@EasyAdmin/default/field_integer.html.twig'
109+
field_raw: '@EasyAdmin/default/field_raw.html.twig'
109110
field_simple_array: '@EasyAdmin/default/field_simple_array.html.twig'
110111
field_smallint: '@EasyAdmin/default/field_smallint.html.twig'
111112
field_string: '@EasyAdmin/default/field_string.html.twig'
@@ -222,6 +223,7 @@ easy_admin:
222223
field_id: '@EasyAdmin/default/field_id.html.twig'
223224
field_image: '@EasyAdmin/default/field_image.html.twig'
224225
field_integer: '@EasyAdmin/default/field_integer.html.twig'
226+
field_raw: '@EasyAdmin/default/field_raw.html.twig'
225227
field_simple_array: '@EasyAdmin/default/field_simple_array.html.twig'
226228
field_smallint: '@EasyAdmin/default/field_smallint.html.twig'
227229
field_string: '@EasyAdmin/default/field_string.html.twig'

Tests/DependencyInjection/fixtures/configurations/output/config_003.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ easy_admin:
106106
field_id: '@EasyAdmin/default/field_id.html.twig'
107107
field_image: '@EasyAdmin/default/field_image.html.twig'
108108
field_integer: '@EasyAdmin/default/field_integer.html.twig'
109+
field_raw: '@EasyAdmin/default/field_raw.html.twig'
109110
field_simple_array: '@EasyAdmin/default/field_simple_array.html.twig'
110111
field_smallint: '@EasyAdmin/default/field_smallint.html.twig'
111112
field_string: '@EasyAdmin/default/field_string.html.twig'
@@ -222,6 +223,7 @@ easy_admin:
222223
field_id: '@EasyAdmin/default/field_id.html.twig'
223224
field_image: '@EasyAdmin/default/field_image.html.twig'
224225
field_integer: '@EasyAdmin/default/field_integer.html.twig'
226+
field_raw: '@EasyAdmin/default/field_raw.html.twig'
225227
field_simple_array: '@EasyAdmin/default/field_simple_array.html.twig'
226228
field_smallint: '@EasyAdmin/default/field_smallint.html.twig'
227229
field_string: '@EasyAdmin/default/field_string.html.twig'
@@ -338,6 +340,7 @@ easy_admin:
338340
field_id: '@EasyAdmin/default/field_id.html.twig'
339341
field_image: '@EasyAdmin/default/field_image.html.twig'
340342
field_integer: '@EasyAdmin/default/field_integer.html.twig'
343+
field_raw: '@EasyAdmin/default/field_raw.html.twig'
341344
field_simple_array: '@EasyAdmin/default/field_simple_array.html.twig'
342345
field_smallint: '@EasyAdmin/default/field_smallint.html.twig'
343346
field_string: '@EasyAdmin/default/field_string.html.twig'

Tests/DependencyInjection/fixtures/configurations/output/config_004.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ easy_admin:
106106
field_id: '@EasyAdmin/default/field_id.html.twig'
107107
field_image: '@EasyAdmin/default/field_image.html.twig'
108108
field_integer: '@EasyAdmin/default/field_integer.html.twig'
109+
field_raw: '@EasyAdmin/default/field_raw.html.twig'
109110
field_simple_array: '@EasyAdmin/default/field_simple_array.html.twig'
110111
field_smallint: '@EasyAdmin/default/field_smallint.html.twig'
111112
field_string: '@EasyAdmin/default/field_string.html.twig'

0 commit comments

Comments
 (0)