Skip to content

Commit e848d8c

Browse files
authored
Merge pull request #53 from ADmad/issue-52
Fix TypeError.
2 parents 860ed36 + 318a671 commit e848d8c

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

src/View/Widget/TimezoneWidget.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace ADmad\I18n\View\Widget;
55

6+
use Cake\View\Form\ContextInterface;
67
use Cake\View\Widget\SelectBoxWidget;
78
use DateTimeZone;
89

@@ -12,20 +13,24 @@
1213
class TimezoneWidget extends SelectBoxWidget
1314
{
1415
/**
15-
* Render the contents of the select element.
16+
* {@inheritDoc}
17+
*
18+
* ### Options format
1619
*
1720
* `$data['options']` is expected to be associative array of regions for which
1821
* you want identifiers list. The key will be used as optgroup.
1922
* Eg. `['Asia' => DateTimeZone::ASIA, 'Europe' => DateTimeZone::EUROPE]`
2023
*
21-
* @param array $data The context for rendering a select.
22-
* @return array
24+
* @param array $data Data to render with.
25+
* @param \Cake\View\Form\ContextInterface $context The current form context.
26+
* @return string A generated select box.
27+
* @throws \RuntimeException when the name attribute is empty.
2328
*/
24-
protected function _renderContent(array $data): array
29+
public function render(array $data, ContextInterface $context): string
2530
{
26-
$data['options'] = $this->_identifierList($data['options']);
31+
$data['options'] = $this->_identifierList($data['options'] ?? []);
2732

28-
return parent::_renderContent($data);
33+
return parent::render($data, $context);
2934
}
3035

3136
/**

tests/TestCase/View/Widget/TimezoneWidgetTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,20 @@ public function testRender()
7474
];
7575
$this->assertHtml($expected, $result);
7676
}
77+
78+
/**
79+
* @see https://github.com/ADmad/cakephp-i18n/pull/52
80+
* @doesNotPerformAssertions
81+
* @return void
82+
*/
83+
public function testRenderOptionsNull()
84+
{
85+
$data = [
86+
'name' => 'timezone',
87+
'options' => null,
88+
];
89+
90+
$select = new TimezoneWidget($this->templates);
91+
$select->render($data, $this->context);
92+
}
7793
}

0 commit comments

Comments
 (0)