Skip to content

Commit

Permalink
Fix type error when using control() outside of an open form.
Browse files Browse the repository at this point in the history
  • Loading branch information
ndm2 committed Nov 12, 2023
1 parent 32105f2 commit e884c92
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/View/Helper/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ protected function _containerOptions(?string $fieldName, array $options): array
if (
$this->_align !== static::ALIGN_INLINE &&
isset($options['type']) &&
isset($options['spacing']) &&
$options['spacing'] !== false
) {
$options['container'] = $this->injectClasses($options['spacing'], (array)($options['container'] ?? []));
Expand Down
43 changes: 43 additions & 0 deletions tests/TestCase/View/Helper/FormHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,49 @@ public function testTooltipWithDisabledLabel()
$this->assertHtml($expected, $result);
}

/**
* Tests that the `control()` method can be used outside of an open form.
*
* This should result in controls being created with the default templates,
* and without alignment/grid, and spacing related classes and structures.
*
* @return void
*/
public function testFormControlWithoutOpenForm()
{
$Form = new FormHelper($this->View);

$result = $Form->control('title');
$expected = [
['div' => ['class' => 'form-group text']],
['label' => ['class' => 'form-label', 'for' => 'title']],
'Title',
'/label',
'input' => [
'type' => 'text',
'name' => 'title',
'id' => 'title',
'class' => 'form-control',
],
'/div',
];
$this->assertHtml($expected, $result);

$Form->create($this->article, [
'align' => [
'sm' => [
FormHelper::GRID_COLUMN_ONE => 5,
FormHelper::GRID_COLUMN_TWO => 7,
],
],
'spacing' => 'mb-1',
]);
$Form->end();

$result = $Form->control('title');
$this->assertHtml($expected, $result);
}

/**
* Test that "form-*" classes are added when using methods for specific input.
*
Expand Down

0 comments on commit e884c92

Please sign in to comment.