Skip to content

Commit

Permalink
Merge pull request #53 from ADmad/issue-52
Browse files Browse the repository at this point in the history
Fix TypeError.
  • Loading branch information
ADmad authored Jul 13, 2020
2 parents 860ed36 + 318a671 commit e848d8c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/View/Widget/TimezoneWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace ADmad\I18n\View\Widget;

use Cake\View\Form\ContextInterface;
use Cake\View\Widget\SelectBoxWidget;
use DateTimeZone;

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

return parent::_renderContent($data);
return parent::render($data, $context);
}

/**
Expand Down
16 changes: 16 additions & 0 deletions tests/TestCase/View/Widget/TimezoneWidgetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,20 @@ public function testRender()
];
$this->assertHtml($expected, $result);
}

/**
* @see https://github.com/ADmad/cakephp-i18n/pull/52
* @doesNotPerformAssertions
* @return void
*/
public function testRenderOptionsNull()
{
$data = [
'name' => 'timezone',
'options' => null,
];

$select = new TimezoneWidget($this->templates);
$select->render($data, $this->context);
}
}

0 comments on commit e848d8c

Please sign in to comment.