+
+ no
+
+EOT
+ ,
+ 'boolean',
+ null,
+ array('editable' => true),
+ ),
+ array(
+ ' Delete | ',
+ 'trans',
+ 'action_delete',
+ array('catalogue' => 'SonataAdminBundle'),
+ ),
+ array(
+ ' | ',
+ 'trans',
+ null,
+ array('catalogue' => 'SonataAdminBundle'),
+ ),
+ array(
+ ' Delete | ',
+ 'trans',
+ 'action_delete',
+ array('format' => '%s', 'catalogue' => 'SonataAdminBundle'),
+ ),
+ array(
+ '
+ action.action_delete
+ | ',
+ 'trans',
+ 'action_delete',
+ array('format' => 'action.%s'),
+ ),
+ array(
+ '
+ action.action_delete
+ | ',
+ 'trans',
+ 'action_delete',
+ array('format' => 'action.%s', 'catalogue' => 'SonataAdminBundle'),
+ ),
+ array(
+ ' Status1 | ',
+ 'choice',
+ 'Status1',
+ array(),
+ ),
+ array(
+ ' Status1 | ',
+ 'choice',
+ array('Status1'),
+ array('choices' => array(), 'multiple' => true),
+ ),
+ array(
+ ' Alias1 | ',
+ 'choice',
+ 'Status1',
+ array('choices' => array('Status1' => 'Alias1', 'Status2' => 'Alias2', 'Status3' => 'Alias3')),
+ ),
+ array(
+ ' | ',
+ 'choice',
+ null,
+ array('choices' => array('Status1' => 'Alias1', 'Status2' => 'Alias2', 'Status3' => 'Alias3')),
+ ),
+ array(
+ '
+ NoValidKeyInChoices
+ | ',
+ 'choice',
+ 'NoValidKeyInChoices',
+ array('choices' => array('Status1' => 'Alias1', 'Status2' => 'Alias2', 'Status3' => 'Alias3')),
+ ),
+ array(
+ ' Delete | ',
+ 'choice',
+ 'Foo',
+ array('catalogue' => 'SonataAdminBundle', 'choices' => array(
+ 'Foo' => 'action_delete',
+ 'Status2' => 'Alias2',
+ 'Status3' => 'Alias3',
+ )),
+ ),
+ array(
+ ' Alias1, Alias3 | ',
+ 'choice',
+ array('Status1', 'Status3'),
+ array('choices' => array(
+ 'Status1' => 'Alias1',
+ 'Status2' => 'Alias2',
+ 'Status3' => 'Alias3',
+ ), 'multiple' => true), ),
+ array(
+ ' Alias1 | Alias3 | ',
+ 'choice',
+ array('Status1', 'Status3'),
+ array('choices' => array(
+ 'Status1' => 'Alias1',
+ 'Status2' => 'Alias2',
+ 'Status3' => 'Alias3',
+ ), 'multiple' => true, 'delimiter' => ' | '), ),
+ array(
+ ' | ',
+ 'choice',
+ null,
+ array('choices' => array(
+ 'Status1' => 'Alias1',
+ 'Status2' => 'Alias2',
+ 'Status3' => 'Alias3',
+ ), 'multiple' => true),
+ ),
+ array(
+ '
+ NoValidKeyInChoices
+ | ',
+ 'choice',
+ array('NoValidKeyInChoices'),
+ array('choices' => array(
+ 'Status1' => 'Alias1',
+ 'Status2' => 'Alias2',
+ 'Status3' => 'Alias3',
+ ), 'multiple' => true),
+ ),
+ array(
+ '
+ NoValidKeyInChoices, Alias2
+ | ',
+ 'choice',
+ array('NoValidKeyInChoices', 'Status2'),
+ array('choices' => array(
+ 'Status1' => 'Alias1',
+ 'Status2' => 'Alias2',
+ 'Status3' => 'Alias3',
+ ), 'multiple' => true),
+ ),
+ array(
+ ' Delete, Alias3 | ',
+ 'choice',
+ array('Foo', 'Status3'),
+ array('catalogue' => 'SonataAdminBundle', 'choices' => array(
+ 'Foo' => 'action_delete',
+ 'Status2' => 'Alias2',
+ 'Status3' => 'Alias3',
+ ), 'multiple' => true),
+ ),
+ array(
+ '
+ <b>Alias1</b>, <b>Alias3</b>
+ | ',
+ 'choice',
+ array('Status1', 'Status3'),
+ array('choices' => array(
+ 'Status1' => 'Alias1',
+ 'Status2' => 'Alias2',
+ 'Status3' => 'Alias3',
+ ), 'multiple' => true), ),
+ array(
+ ' | ',
+ 'url',
+ null,
+ array(),
+ ),
+ array(
+ ' | ',
+ 'url',
+ null,
+ array('url' => 'http://example.com'),
+ ),
+ array(
+ ' | ',
+ 'url',
+ null,
+ array('route' => array('name' => 'sonata_admin_foo')),
+ ),
+ array(
+ '
+ http://example.com
+ | ',
+ 'url',
+ 'http://example.com',
+ array(),
+ ),
+ array(
+ '
+ https://example.com
+ | ',
+ 'url',
+ 'https://example.com',
+ array(),
+ ),
+ array(
+ '
+ example.com
+ | ',
+ 'url',
+ 'http://example.com',
+ array('hide_protocol' => true),
+ ),
+ array(
+ '
+ example.com
+ | ',
+ 'url',
+ 'https://example.com',
+ array('hide_protocol' => true),
+ ),
+ array(
+ '
+ http://example.com
+ | ',
+ 'url',
+ 'http://example.com',
+ array('hide_protocol' => false),
+ ),
+ array(
+ '
+ https://example.com
+ | ',
+ 'url',
+ 'https://example.com',
+ array('hide_protocol' => false),
+ ),
+ array(
+ '
+ Foo
+ | ',
+ 'url',
+ 'Foo',
+ array('url' => 'http://example.com'),
+ ),
+ array(
+ '
+ <b>Foo</b>
+ | ',
+ 'url',
+ 'Foo',
+ array('url' => 'http://example.com'),
+ ),
+ array(
+ '
+ Foo
+ | ',
+ 'url',
+ 'Foo',
+ array('route' => array('name' => 'sonata_admin_foo')),
+ ),
+ array(
+ '
+ Foo
+ | ',
+ 'url',
+ 'Foo',
+ array('route' => array('name' => 'sonata_admin_foo', 'absolute' => true)),
+ ),
+ array(
+ '
+ foo/bar?a=b&c=123456789
+ | ',
+ 'url',
+ 'http://foo/bar?a=b&c=123456789',
+ array('route' => array('name' => 'sonata_admin_foo'),
+ 'hide_protocol' => true, ),
+ ),
+ array(
+ '
+ foo/bar?a=b&c=123456789
+ | ',
+ 'url',
+ 'http://foo/bar?a=b&c=123456789',
+ array(
+ 'route' => array('name' => 'sonata_admin_foo', 'absolute' => true),
+ 'hide_protocol' => true,
+ ),
+ ),
+ array(
+ '
+ Foo
+ | ',
+ 'url',
+ 'Foo',
+ array(
+ 'route' => array('name' => 'sonata_admin_foo_param',
+ 'parameters' => array('param1' => 'abcd', 'param2' => 'efgh', 'param3' => 'ijkl'), ),
+ ),
+ ),
+ array(
+ '
+ Foo
+ | ',
+ 'url',
+ 'Foo',
+ array(
+ 'route' => array('name' => 'sonata_admin_foo_param',
+ 'absolute' => true,
+ 'parameters' => array('param1' => 'abcd', 'param2' => 'efgh', 'param3' => 'ijkl'), ),
+ ),
+ ),
+ array(
+ '
+ Foo
+ | ',
+ 'url',
+ 'Foo',
+ array(
+ 'route' => array('name' => 'sonata_admin_foo_object',
+ 'parameters' => array('param1' => 'abcd', 'param2' => 'efgh', 'param3' => 'ijkl'),
+ 'identifier_parameter_name' => 'barId', ),
+ ),
+ ),
+ array(
+ '
+ Foo
+ | ',
+ 'url',
+ 'Foo',
+ array(
+ 'route' => array('name' => 'sonata_admin_foo_object',
+ 'absolute' => true,
+ 'parameters' => array('param1' => 'abcd', 'param2' => 'efgh', 'param3' => 'ijkl'),
+ 'identifier_parameter_name' => 'barId', ),
+ ),
+ ),
+ array(
+ '
+ Creating a Template for the Field and form
+ | ',
'html',
'Creating a Template for the Field and form
',
array(),
),
array(
- ' Creating a Template for the Field and form | ',
+ '
+ Creating a Template for the Field and form
+ | ',
'html',
'Creating a Template for the Field and form
',
array('strip' => true),
),
array(
- ' Creating a Template for the Fi... | ',
+ '
+ Creating a Template for the Fi...
+ | ',
'html',
'Creating a Template for the Field and form
',
array('truncate' => true),
@@ -352,19 +914,25 @@ public function getRenderListElementTests()
array('truncate' => array('length' => 10)),
),
array(
- ' Creating a Template for the Field... | ',
+ '
+ Creating a Template for the Field...
+ | ',
'html',
'Creating a Template for the Field and form
',
array('truncate' => array('preserve' => true)),
),
array(
- ' Creating a Template for the Fi etc. | ',
+ '
+ Creating a Template for the Fi etc.
+ | ',
'html',
'Creating a Template for the Field and form
',
array('truncate' => array('separator' => ' etc.')),
),
array(
- ' Creating a Template for[...] | ',
+ '
+ Creating a Template for[...]
+ | ',
'html',
'Creating a Template for the Field and form
',
array(
@@ -403,7 +971,13 @@ public function testRenderListElementNonExistentTemplate()
$this->logger->expects($this->once())
->method('warning')
- ->with(($this->stringStartsWith('An error occured trying to load the template "SonataAdminBundle:CRUD:list_nonexistent_template.html.twig" for the field "Foo_name", the default template "SonataAdminBundle:CRUD:base_list_field.html.twig" was used instead: "Unable to find template "list_nonexistent_template.html.twig')));
+ ->with(($this->stringStartsWith($this->removeExtraWhitespace(
+ 'An error occured trying to load the template
+ "SonataAdminBundle:CRUD:list_nonexistent_template.html.twig"
+ for the field "Foo_name", the default template
+ "SonataAdminBundle:CRUD:base_list_field.html.twig" was used
+ instead.'
+ ))));
$this->twigExtension->renderListElement($this->environment, $this->object, $this->fieldDescription);
}
@@ -484,7 +1058,15 @@ public function testRenderViewElement($expected, $type, $value, array $options)
}
}));
- $this->assertSame($expected, trim(preg_replace('/\s+/', ' ', $this->twigExtension->renderViewElement($this->environment, $this->fieldDescription, $this->object))));
+ $this->assertSame($expected, trim(preg_replace(
+ '/\s+/',
+ ' ',
+ $this->twigExtension->renderViewElement(
+ $this->environment,
+ $this->fieldDescription,
+ $this->object
+ )
+ )));
}
public function getRenderViewElementTests()
@@ -493,49 +1075,306 @@ public function getRenderViewElementTests()
array('Data | Example | ', 'string', 'Example', array('safe' => false)),
array('Data | Example | ', 'text', 'Example', array('safe' => false)),
array('Data | Example | ', 'textarea', 'Example', array('safe' => false)),
- array('Data | December 24, 2013 10:11 | ', 'datetime', new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('Europe/London')), array()),
- array('Data | 24.12.2013 10:11:12 | ', 'datetime', new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('Europe/London')), array('format' => 'd.m.Y H:i:s')),
- array('Data | December 24, 2013 | ', 'date', new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('Europe/London')), array()),
- array('Data | 24.12.2013 | ', 'date', new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('Europe/London')), array('format' => 'd.m.Y')),
- array('Data | 10:11:12 | ', 'time', new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('Europe/London')), array()),
+ array(
+ 'Data | December 24, 2013 10:11 | ',
+ 'datetime',
+ new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('Europe/London')), array(),
+ ),
+ array(
+ 'Data | 24.12.2013 10:11:12 | ',
+ 'datetime',
+ new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('Europe/London')),
+ array('format' => 'd.m.Y H:i:s'),
+ ),
+ array(
+ 'Data | December 24, 2013 | ',
+ 'date',
+ new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('Europe/London')),
+ array(),
+ ),
+ array(
+ 'Data | 24.12.2013 | ',
+ 'date',
+ new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('Europe/London')),
+ array('format' => 'd.m.Y'),
+ ),
+ array(
+ 'Data | 10:11:12 | ',
+ 'time',
+ new \DateTime('2013-12-24 10:11:12', new \DateTimeZone('Europe/London')),
+ array(),
+ ),
array('Data | 10.746135 | ', 'number', 10.746135, array('safe' => false)),
array('Data | 5678 | ', 'integer', 5678, array('safe' => false)),
array('Data | 1074.6135 % | ', 'percent', 10.746135, array()),
array('Data | EUR 10.746135 | ', 'currency', 10.746135, array('currency' => 'EUR')),
array('Data | GBP 51.23456 | ', 'currency', 51.23456, array('currency' => 'GBP')),
- array('Data | [1 => First] [2 => Second] | ', 'array', array(1 => 'First', 2 => 'Second'), array('safe' => false)),
- array('Data | [1 => First] [2 => Second] | ', 'array', array(1 => 'First', 2 => 'Second'), array('safe' => false, 'inline' => true)),
- array('Data | yes | ', 'boolean', true, array()),
+ array(
+ 'Data | [1 => First] [2 => Second] | ',
+ 'array',
+ array(1 => 'First', 2 => 'Second'),
+ array('safe' => false),
+ ),
+ array(
+ 'Data | [1 => First] [2 => Second] | ',
+ 'array',
+ array(1 => 'First', 2 => 'Second'),
+ array('safe' => false, 'inline' => true),
+ ),
+ array(
+ 'Data | yes | ',
+ 'boolean',
+ true,
+ array(),
+ ),
array('Data | no | ', 'boolean', false, array()),
- array('Data | Delete | ', 'trans', 'action_delete', array('safe' => false, 'catalogue' => 'SonataAdminBundle')),
+ array(
+ 'Data | Delete | ',
+ 'trans',
+ 'action_delete',
+ array('safe' => false, 'catalogue' => 'SonataAdminBundle'),
+ ),
array('Data | Status1 | ', 'choice', 'Status1', array('safe' => false)),
- array('Data | Alias1 | ', 'choice', 'Status1', array('safe' => false, 'choices' => array('Status1' => 'Alias1', 'Status2' => 'Alias2', 'Status3' => 'Alias3'))),
- array('Data | NoValidKeyInChoices | ', 'choice', 'NoValidKeyInChoices', array('safe' => false, 'choices' => array('Status1' => 'Alias1', 'Status2' => 'Alias2', 'Status3' => 'Alias3'))),
- array('Data | Delete | ', 'choice', 'Foo', array('safe' => false, 'catalogue' => 'SonataAdminBundle', 'choices' => array('Foo' => 'action_delete', 'Status2' => 'Alias2', 'Status3' => 'Alias3'))),
- array('Data | NoValidKeyInChoices | ', 'choice', array('NoValidKeyInChoices'), array('safe' => false, 'choices' => array('Status1' => 'Alias1', 'Status2' => 'Alias2', 'Status3' => 'Alias3'), 'multiple' => true)),
- array('Data | NoValidKeyInChoices, Alias2 | ', 'choice', array('NoValidKeyInChoices', 'Status2'), array('safe' => false, 'choices' => array('Status1' => 'Alias1', 'Status2' => 'Alias2', 'Status3' => 'Alias3'), 'multiple' => true)),
- array('Data | Alias1, Alias3 | ', 'choice', array('Status1', 'Status3'), array('safe' => false, 'choices' => array('Status1' => 'Alias1', 'Status2' => 'Alias2', 'Status3' => 'Alias3'), 'multiple' => true)),
- array('Data | Alias1 | Alias3 | ', 'choice', array('Status1', 'Status3'), array('safe' => false, 'choices' => array('Status1' => 'Alias1', 'Status2' => 'Alias2', 'Status3' => 'Alias3'), 'multiple' => true, 'delimiter' => ' | ')),
- array('Data | Delete, Alias3 | ', 'choice', array('Foo', 'Status3'), array('safe' => false, 'catalogue' => 'SonataAdminBundle', 'choices' => array('Foo' => 'action_delete', 'Status2' => 'Alias2', 'Status3' => 'Alias3'), 'multiple' => true)),
- array('Data | Alias1, Alias3 | ', 'choice', array('Status1', 'Status3'), array('safe' => true, 'choices' => array('Status1' => 'Alias1', 'Status2' => 'Alias2', 'Status3' => 'Alias3'), 'multiple' => true)),
- array('Data | <b>Alias1</b>, <b>Alias3</b> | ', 'choice', array('Status1', 'Status3'), array('safe' => false, 'choices' => array('Status1' => 'Alias1', 'Status2' => 'Alias2', 'Status3' => 'Alias3'), 'multiple' => true)),
- array('Data | http://example.com | ', 'url', 'http://example.com', array('safe' => false)),
- array('Data | https://example.com | ', 'url', 'https://example.com', array('safe' => false)),
- array('Data | example.com | ', 'url', 'http://example.com', array('safe' => false, 'hide_protocol' => true)),
- array('Data | example.com | ', 'url', 'https://example.com', array('safe' => false, 'hide_protocol' => true)),
- array('Data | http://example.com | ', 'url', 'http://example.com', array('safe' => false, 'hide_protocol' => false)),
- array('Data | https://example.com | ', 'url', 'https://example.com', array('safe' => false, 'hide_protocol' => false)),
- array('Data | Foo | ', 'url', 'Foo', array('safe' => false, 'url' => 'http://example.com')),
- array('Data | <b>Foo</b> | ', 'url', 'Foo', array('safe' => false, 'url' => 'http://example.com')),
- array('Data | Foo | ', 'url', 'Foo', array('safe' => true, 'url' => 'http://example.com')),
- array('Data | Foo | ', 'url', 'Foo', array('safe' => false, 'route' => array('name' => 'sonata_admin_foo'))),
- array('Data | Foo | ', 'url', 'Foo', array('safe' => false, 'route' => array('name' => 'sonata_admin_foo', 'absolute' => true))),
- array('Data | foo/bar?a=b&c=123456789 | ', 'url', 'http://foo/bar?a=b&c=123456789', array('safe' => false, 'route' => array('name' => 'sonata_admin_foo'), 'hide_protocol' => true)),
- array('Data | foo/bar?a=b&c=123456789 | ', 'url', 'http://foo/bar?a=b&c=123456789', array('safe' => false, 'route' => array('name' => 'sonata_admin_foo', 'absolute' => true), 'hide_protocol' => true)),
- array('Data | Foo | ', 'url', 'Foo', array('safe' => false, 'route' => array('name' => 'sonata_admin_foo_param', 'parameters' => array('param1' => 'abcd', 'param2' => 'efgh', 'param3' => 'ijkl')))),
- array('Data | Foo | ', 'url', 'Foo', array('safe' => false, 'route' => array('name' => 'sonata_admin_foo_param', 'absolute' => true, 'parameters' => array('param1' => 'abcd', 'param2' => 'efgh', 'param3' => 'ijkl')))),
- array('Data | Foo | ', 'url', 'Foo', array('safe' => false, 'route' => array('name' => 'sonata_admin_foo_object', 'parameters' => array('param1' => 'abcd', 'param2' => 'efgh', 'param3' => 'ijkl'), 'identifier_parameter_name' => 'barId'))),
- array('Data | Foo | ', 'url', 'Foo', array('safe' => false, 'route' => array('name' => 'sonata_admin_foo_object', 'absolute' => true, 'parameters' => array('param1' => 'abcd', 'param2' => 'efgh', 'param3' => 'ijkl'), 'identifier_parameter_name' => 'barId'))),
+ array(
+ 'Data | Alias1 | ',
+ 'choice',
+ 'Status1',
+ array('safe' => false, 'choices' => array(
+ 'Status1' => 'Alias1',
+ 'Status2' => 'Alias2',
+ 'Status3' => 'Alias3',
+ )),
+ ),
+ array(
+ 'Data | NoValidKeyInChoices | ',
+ 'choice',
+ 'NoValidKeyInChoices',
+ array('safe' => false, 'choices' => array(
+ 'Status1' => 'Alias1',
+ 'Status2' => 'Alias2',
+ 'Status3' => 'Alias3',
+ )),
+ ),
+ array(
+ 'Data | Delete | ',
+ 'choice',
+ 'Foo',
+ array('safe' => false, 'catalogue' => 'SonataAdminBundle', 'choices' => array(
+ 'Foo' => 'action_delete',
+ 'Status2' => 'Alias2',
+ 'Status3' => 'Alias3',
+ )),
+ ),
+ array(
+ 'Data | NoValidKeyInChoices | ',
+ 'choice',
+ array('NoValidKeyInChoices'),
+ array('safe' => false, 'choices' => array(
+ 'Status1' => 'Alias1',
+ 'Status2' => 'Alias2',
+ 'Status3' => 'Alias3',
+ ), 'multiple' => true),
+ ),
+ array(
+ 'Data | NoValidKeyInChoices, Alias2 | ',
+ 'choice',
+ array('NoValidKeyInChoices', 'Status2'),
+ array('safe' => false, 'choices' => array(
+ 'Status1' => 'Alias1',
+ 'Status2' => 'Alias2',
+ 'Status3' => 'Alias3',
+ ), 'multiple' => true),
+ ),
+ array(
+ 'Data | Alias1, Alias3 | ',
+ 'choice',
+ array('Status1', 'Status3'),
+ array('safe' => false, 'choices' => array(
+ 'Status1' => 'Alias1',
+ 'Status2' => 'Alias2',
+ 'Status3' => 'Alias3',
+ ), 'multiple' => true),
+ ),
+ array(
+ 'Data | Alias1 | Alias3 | ',
+ 'choice',
+ array('Status1', 'Status3'), array('safe' => false, 'choices' => array(
+ 'Status1' => 'Alias1',
+ 'Status2' => 'Alias2',
+ 'Status3' => 'Alias3',
+ ), 'multiple' => true, 'delimiter' => ' | '),
+ ),
+ array(
+ 'Data | Delete, Alias3 | ',
+ 'choice',
+ array('Foo', 'Status3'),
+ array('safe' => false, 'catalogue' => 'SonataAdminBundle', 'choices' => array(
+ 'Foo' => 'action_delete',
+ 'Status2' => 'Alias2',
+ 'Status3' => 'Alias3',
+ ), 'multiple' => true),
+ ),
+ array(
+ 'Data | Alias1, Alias3 | ',
+ 'choice',
+ array('Status1', 'Status3'),
+ array('safe' => true, 'choices' => array(
+ 'Status1' => 'Alias1',
+ 'Status2' => 'Alias2',
+ 'Status3' => 'Alias3',
+ ), 'multiple' => true),
+ ),
+ array(
+ 'Data | <b>Alias1</b>, <b>Alias3</b> | ',
+ 'choice',
+ array('Status1', 'Status3'),
+ array('safe' => false, 'choices' => array(
+ 'Status1' => 'Alias1',
+ 'Status2' => 'Alias2',
+ 'Status3' => 'Alias3',
+ ), 'multiple' => true),
+ ),
+ array(
+ 'Data | http://example.com | ',
+ 'url',
+ 'http://example.com',
+ array('safe' => false),
+ ),
+ array(
+ 'Data | https://example.com | ',
+ 'url',
+ 'https://example.com',
+ array('safe' => false),
+ ),
+ array(
+ 'Data | example.com | ',
+ 'url',
+ 'http://example.com',
+ array('safe' => false, 'hide_protocol' => true),
+ ),
+ array(
+ 'Data | example.com | ',
+ 'url',
+ 'https://example.com',
+ array('safe' => false, 'hide_protocol' => true),
+ ),
+ array(
+ 'Data | http://example.com | ',
+ 'url',
+ 'http://example.com',
+ array('safe' => false, 'hide_protocol' => false),
+ ),
+ array(
+ 'Data | https://example.com | ',
+ 'url',
+ 'https://example.com',
+ array('safe' => false,
+ 'hide_protocol' => false, ),
+ ),
+ array(
+ 'Data | Foo | ',
+ 'url',
+ 'Foo',
+ array('safe' => false, 'url' => 'http://example.com'),
+ ),
+ array(
+ 'Data | <b>Foo</b> | ',
+ 'url',
+ 'Foo',
+ array('safe' => false, 'url' => 'http://example.com'),
+ ),
+ array(
+ 'Data | Foo | ',
+ 'url',
+ 'Foo',
+ array('safe' => true, 'url' => 'http://example.com'),
+ ),
+ array(
+ 'Data | Foo | ',
+ 'url',
+ 'Foo',
+ array('safe' => false, 'route' => array('name' => 'sonata_admin_foo')),
+ ),
+ array(
+ 'Data | Foo | ',
+ 'url',
+ 'Foo',
+ array('safe' => false, 'route' => array(
+ 'name' => 'sonata_admin_foo',
+ 'absolute' => true,
+ )),
+ ),
+ array(
+ 'Data | foo/bar?a=b&c=123456789 | ',
+ 'url',
+ 'http://foo/bar?a=b&c=123456789',
+ array(
+ 'safe' => false,
+ 'route' => array('name' => 'sonata_admin_foo'),
+ 'hide_protocol' => true,
+ ),
+ ),
+ array(
+ 'Data | foo/bar?a=b&c=123456789 | ',
+ 'url',
+ 'http://foo/bar?a=b&c=123456789',
+ array('safe' => false, 'route' => array(
+ 'name' => 'sonata_admin_foo',
+ 'absolute' => true,
+ ), 'hide_protocol' => true),
+ ),
+ array(
+ 'Data | Foo | ',
+ 'url',
+ 'Foo',
+ array('safe' => false, 'route' => array(
+ 'name' => 'sonata_admin_foo_param',
+ 'parameters' => array('param1' => 'abcd', 'param2' => 'efgh', 'param3' => 'ijkl'),
+ )),
+ ),
+ array(
+ 'Data | Foo | ',
+ 'url',
+ 'Foo',
+ array('safe' => false, 'route' => array(
+ 'name' => 'sonata_admin_foo_param',
+ 'absolute' => true,
+ 'parameters' => array(
+ 'param1' => 'abcd',
+ 'param2' => 'efgh',
+ 'param3' => 'ijkl',
+ ),
+ )),
+ ),
+ array(
+ 'Data | Foo | ',
+ 'url',
+ 'Foo',
+ array('safe' => false, 'route' => array(
+ 'name' => 'sonata_admin_foo_object',
+ 'parameters' => array(
+ 'param1' => 'abcd',
+ 'param2' => 'efgh',
+ 'param3' => 'ijkl',
+ ),
+ 'identifier_parameter_name' => 'barId',
+ )),
+ ),
+ array(
+ 'Data | Foo | ',
+ 'url',
+ 'Foo',
+ array('safe' => false, 'route' => array(
+ 'name' => 'sonata_admin_foo_object',
+ 'absolute' => true,
+ 'parameters' => array(
+ 'param1' => 'abcd',
+ 'param2' => 'efgh',
+ 'param3' => 'ijkl',
+ ),
+ 'identifier_parameter_name' => 'barId',
+ )),
+ ),
array(
'Data | Creating a Template for the Field and form | ',
'html',
@@ -590,7 +1429,12 @@ public function getRenderViewElementTests()
array('Data | | ', 'text', new NoValueException(), array('safe' => false)),
array('Data | | ', 'textarea', new NoValueException(), array('safe' => false)),
array('Data | | ', 'datetime', new NoValueException(), array()),
- array('Data | | ', 'datetime', new NoValueException(), array('format' => 'd.m.Y H:i:s')),
+ array(
+ 'Data | | ',
+ 'datetime',
+ new NoValueException(),
+ array('format' => 'd.m.Y H:i:s'),
+ ),
array('Data | | ', 'date', new NoValueException(), array()),
array('Data | | ', 'date', new NoValueException(), array('format' => 'd.m.Y')),
array('Data | | ', 'time', new NoValueException(), array()),
@@ -600,13 +1444,43 @@ public function getRenderViewElementTests()
array('Data | | ', 'currency', new NoValueException(), array('currency' => 'EUR')),
array('Data | | ', 'currency', new NoValueException(), array('currency' => 'GBP')),
array('Data | | ', 'array', new NoValueException(), array('safe' => false)),
- array('Data | no | ', 'boolean', new NoValueException(), array()),
- array('Data | | ', 'trans', new NoValueException(), array('safe' => false, 'catalogue' => 'SonataAdminBundle')),
- array('Data | | ', 'choice', new NoValueException(), array('safe' => false, 'choices' => array())),
- array('Data | | ', 'choice', new NoValueException(), array('safe' => false, 'choices' => array(), 'multiple' => true)),
+ array(
+ 'Data | no | ',
+ 'boolean',
+ new NoValueException(),
+ array(),
+ ),
+ array(
+ 'Data | | ',
+ 'trans',
+ new NoValueException(),
+ array('safe' => false, 'catalogue' => 'SonataAdminBundle'),
+ ),
+ array(
+ 'Data | | ',
+ 'choice',
+ new NoValueException(),
+ array('safe' => false, 'choices' => array()),
+ ),
+ array(
+ 'Data | | ',
+ 'choice',
+ new NoValueException(),
+ array('safe' => false, 'choices' => array(), 'multiple' => true),
+ ),
array('Data | | ', 'url', new NoValueException(), array()),
- array('Data | | ', 'url', new NoValueException(), array('url' => 'http://example.com')),
- array('Data | | ', 'url', new NoValueException(), array('route' => array('name' => 'sonata_admin_foo'))),
+ array(
+ 'Data | | ',
+ 'url',
+ new NoValueException(),
+ array('url' => 'http://example.com'),
+ ),
+ array(
+ 'Data | | ',
+ 'url',
+ new NoValueException(),
+ array('route' => array('name' => 'sonata_admin_foo')),
+ ),
);
}
@@ -628,7 +1502,10 @@ public function testGetValueFromFieldDescriptionWithRemoveLoopException()
$fieldDescription = $this->getMock('Sonata\AdminBundle\Admin\FieldDescriptionInterface');
try {
- $this->assertSame('anything', $this->twigExtension->getValueFromFieldDescription($object, $fieldDescription, array('loop' => true)));
+ $this->assertSame(
+ 'anything',
+ $this->twigExtension->getValueFromFieldDescription($object, $fieldDescription, array('loop' => true))
+ );
} catch (\RuntimeException $e) {
$this->assertContains('remove the loop requirement', $e->getMessage());
@@ -699,12 +1576,32 @@ public function testOutput()
$template = $this->environment->loadTemplate('SonataAdminBundle:CRUD:base_list_field.html.twig');
- $this->assertSame(' foo | ',
- trim(preg_replace('/\s+/', ' ', $this->twigExtension->output($this->fieldDescription, $template, $parameters, $this->environment))));
+ $this->assertSame(
+ ' foo | ',
+ $this->removeExtraWhitespace($this->twigExtension->output(
+ $this->fieldDescription,
+ $template,
+ $parameters,
+ $this->environment
+ ))
+ );
$this->environment->enableDebug();
- $this->assertSame(' foo | ',
- trim(preg_replace('/\s+/', ' ', $this->twigExtension->output($this->fieldDescription, $template, $parameters, $this->environment))));
+ $this->assertSame(
+ $this->removeExtraWhitespace(<<
+ foo |
+
+EOT
+ ),
+ $this->removeExtraWhitespace(
+ $this->twigExtension->output($this->fieldDescription, $template, $parameters, $this->environment)
+ )
+ );
}
public function testRenderRelationElementNoObject()
@@ -768,7 +1665,10 @@ public function testRenderRelationElementMethodNotExist()
try {
$this->twigExtension->renderRelationElement($element, $this->fieldDescription);
} catch (\RuntimeException $e) {
- $this->assertContains('You must define an `associated_property` option or create a `stdClass::__toString', $e->getMessage());
+ $this->assertContains(
+ 'You must define an `associated_property` option or create a `stdClass::__toString',
+ $e->getMessage()
+ );
return;
}
@@ -809,7 +1709,10 @@ public function testRenderRelationElementWithClosure()
$element = new \stdClass();
$element->foo = 'bar';
- $this->assertSame('closure bar', $this->twigExtension->renderRelationElement($element, $this->fieldDescription));
+ $this->assertSame(
+ 'closure bar',
+ $this->twigExtension->renderRelationElement($element, $this->fieldDescription)
+ );
}
public function testGetUrlsafeIdentifier()
@@ -833,8 +1736,14 @@ public function testGetUrlsafeIdentifier_GivenAdmin_Foo()
$entity = new \stdClass();
// set admin to pool
- $this->pool->setAdminServiceIds(array('sonata_admin_foo_service', 'sonata_admin_bar_service'));
- $this->pool->setAdminClasses(array('stdClass' => array('sonata_admin_foo_service', 'sonata_admin_bar_service')));
+ $this->pool->setAdminServiceIds(array(
+ 'sonata_admin_foo_service',
+ 'sonata_admin_bar_service',
+ ));
+ $this->pool->setAdminClasses(array('stdClass' => array(
+ 'sonata_admin_foo_service',
+ 'sonata_admin_bar_service',
+ )));
$this->admin->expects($this->once())
->method('getUrlsafeIdentifier')
@@ -853,7 +1762,10 @@ public function testGetUrlsafeIdentifier_GivenAdmin_Bar()
// set admin to pool
$this->pool->setAdminServiceIds(array('sonata_admin_foo_service', 'sonata_admin_bar_service'));
- $this->pool->setAdminClasses(array('stdClass' => array('sonata_admin_foo_service', 'sonata_admin_bar_service')));
+ $this->pool->setAdminClasses(array('stdClass' => array(
+ 'sonata_admin_foo_service',
+ 'sonata_admin_bar_service',
+ )));
$this->admin->expects($this->never())
->method('getUrlsafeIdentifier');
diff --git a/Twig/Extension/SonataAdminExtension.php b/Twig/Extension/SonataAdminExtension.php
index d4a940ec43..d3b512de48 100644
--- a/Twig/Extension/SonataAdminExtension.php
+++ b/Twig/Extension/SonataAdminExtension.php
@@ -17,7 +17,6 @@
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
use Sonata\AdminBundle\Admin\Pool;
use Sonata\AdminBundle\Exception\NoValueException;
-use Twig_Environment;
/**
* Class SonataAdminExtension.
@@ -52,12 +51,35 @@ public function __construct(Pool $pool, LoggerInterface $logger = null)
public function getFilters()
{
return array(
- new \Twig_SimpleFilter('render_list_element', array($this, 'renderListElement'), array('is_safe' => array('html'), 'needs_environment' => true)),
- new \Twig_SimpleFilter('render_view_element', array($this, 'renderViewElement'), array('is_safe' => array('html'), 'needs_environment' => true)),
- new \Twig_SimpleFilter('render_view_element_compare', array($this, 'renderViewElementCompare'), array('is_safe' => array('html'))),
- new \Twig_SimpleFilter('render_relation_element', array($this, 'renderRelationElement')),
- new \Twig_SimpleFilter('sonata_urlsafeid', array($this, 'getUrlsafeIdentifier')),
- new \Twig_SimpleFilter('sonata_xeditable_type', array($this, 'getXEditableType')),
+ new \Twig_SimpleFilter(
+ 'render_list_element',
+ array($this, 'renderListElement'),
+ array('is_safe' => array('html'),
+ 'needs_environment' => true, )
+ ),
+ new \Twig_SimpleFilter(
+ 'render_view_element',
+ array($this, 'renderViewElement'),
+ array('is_safe' => array('html'),
+ 'needs_environment' => true, )
+ ),
+ new \Twig_SimpleFilter(
+ 'render_view_element_compare',
+ array($this, 'renderViewElementCompare'),
+ array('is_safe' => array('html'))
+ ),
+ new \Twig_SimpleFilter(
+ 'render_relation_element',
+ array($this, 'renderRelationElement')
+ ),
+ new \Twig_SimpleFilter(
+ 'sonata_urlsafeid',
+ array($this, 'getUrlsafeIdentifier')
+ ),
+ new \Twig_SimpleFilter(
+ 'sonata_xeditable_type',
+ array($this, 'getXEditableType')
+ ),
);
}
@@ -77,8 +99,11 @@ public function getName()
*
* @return \Twig_Template
*/
- protected function getTemplate(FieldDescriptionInterface $fieldDescription, $defaultTemplate, Twig_Environment $environment)
- {
+ protected function getTemplate(
+ FieldDescriptionInterface $fieldDescription,
+ $defaultTemplate,
+ \Twig_Environment $environment
+ ) {
$templateName = $fieldDescription->getTemplate() ?: $defaultTemplate;
try {
@@ -87,7 +112,13 @@ protected function getTemplate(FieldDescriptionInterface $fieldDescription, $def
$template = $environment->loadTemplate($defaultTemplate);
if (null !== $this->logger) {
- $this->logger->warning(sprintf('An error occured trying to load the template "%s" for the field "%s", the default template "%s" was used instead: "%s". ', $templateName, $fieldDescription->getFieldName(), $defaultTemplate, $e->getMessage()));
+ $this->logger->warning(sprintf(
+ 'An error occured trying to load the template "%s" for the field "%s", '.
+ 'the default template "%s" was used instead.',
+ $templateName,
+ $fieldDescription->getFieldName(),
+ $defaultTemplate
+ ), array('exception' => $e));
}
}
@@ -103,9 +134,17 @@ protected function getTemplate(FieldDescriptionInterface $fieldDescription, $def
*
* @return string
*/
- public function renderListElement(Twig_Environment $environment, $object, FieldDescriptionInterface $fieldDescription, $params = array())
- {
- $template = $this->getTemplate($fieldDescription, $fieldDescription->getAdmin()->getTemplate('base_list_field'), $environment);
+ public function renderListElement(
+ \Twig_Environment $environment,
+ $object,
+ FieldDescriptionInterface $fieldDescription,
+ $params = array()
+ ) {
+ $template = $this->getTemplate(
+ $fieldDescription,
+ $fieldDescription->getAdmin()->getTemplate('base_list_field'),
+ $environment
+ );
return $this->output($fieldDescription, $template, array_merge($params, array(
'admin' => $fieldDescription->getAdmin(),
@@ -122,12 +161,28 @@ public function renderListElement(Twig_Environment $environment, $object, FieldD
*
* @return string
*/
- public function output(FieldDescriptionInterface $fieldDescription, \Twig_Template $template, array $parameters = array(), Twig_Environment $environment)
- {
+ public function output(
+ FieldDescriptionInterface $fieldDescription,
+ \Twig_Template $template,
+ array $parameters,
+ \Twig_Environment $environment
+ ) {
$content = $template->render($parameters);
if ($environment->isDebug()) {
- return sprintf("\n\n%s\n",
+ $commentTemplate = <<
+ %s
+
+EOT;
+
+ return sprintf(
+ $commentTemplate,
$fieldDescription->getFieldName(),
$fieldDescription->getTemplate(),
$template->getTemplateName(),
@@ -151,8 +206,11 @@ public function output(FieldDescriptionInterface $fieldDescription, \Twig_Templa
*
* @return mixed
*/
- public function getValueFromFieldDescription($object, FieldDescriptionInterface $fieldDescription, array $params = array())
- {
+ public function getValueFromFieldDescription(
+ $object,
+ FieldDescriptionInterface $fieldDescription,
+ array $params = array()
+ ) {
if (isset($params['loop']) && $object instanceof \ArrayAccess) {
throw new \RuntimeException('remove the loop requirement');
}
@@ -177,9 +235,16 @@ public function getValueFromFieldDescription($object, FieldDescriptionInterface
*
* @return string
*/
- public function renderViewElement(Twig_Environment $environment, FieldDescriptionInterface $fieldDescription, $object)
- {
- $template = $this->getTemplate($fieldDescription, 'SonataAdminBundle:CRUD:base_show_field.html.twig', $environment);
+ public function renderViewElement(
+ \Twig_Environment $environment,
+ FieldDescriptionInterface $fieldDescription,
+ $object
+ ) {
+ $template = $this->getTemplate(
+ $fieldDescription,
+ 'SonataAdminBundle:CRUD:base_show_field.html.twig',
+ $environment
+ );
try {
$value = $fieldDescription->getValue($object);
@@ -204,9 +269,17 @@ public function renderViewElement(Twig_Environment $environment, FieldDescriptio
*
* @return string
*/
- public function renderViewElementCompare(Twig_Environment $environment, FieldDescriptionInterface $fieldDescription, $baseObject, $compareObject)
- {
- $template = $this->getTemplate($fieldDescription, 'SonataAdminBundle:CRUD:base_show_field.html.twig', $environment);
+ public function renderViewElementCompare(
+ \Twig_Environment $environment,
+ FieldDescriptionInterface $fieldDescription,
+ $baseObject,
+ $compareObject
+ ) {
+ $template = $this->getTemplate(
+ $fieldDescription,
+ 'SonataAdminBundle:CRUD:base_show_field.html.twig',
+ $environment
+ );
try {
$baseValue = $fieldDescription->getValue($baseObject);
@@ -265,14 +338,18 @@ public function renderRelationElement($element, FieldDescriptionInterface $field
$method = $fieldDescription->getOption('associated_tostring');
if ($method) {
- @trigger_error('Option "associated_tostring" is deprecated since version 2.3. Use "associated_property" instead.', E_USER_DEPRECATED);
+ @trigger_error(
+ 'Option "associated_tostring" is deprecated since version 2.3. Use "associated_property" instead.',
+ E_USER_DEPRECATED
+ );
} else {
$method = '__toString';
}
if (!method_exists($element, $method)) {
throw new \RuntimeException(sprintf(
- 'You must define an `associated_property` option or create a `%s::__toString` method to the field option %s from service %s is ',
+ 'You must define an `associated_property` option or '.
+ 'create a `%s::__toString` method to the field option %s from service %s is ',
get_class($element),
$fieldDescription->getName(),
$fieldDescription->getAdmin()->getCode()