Skip to content
Permalink
Browse files

Allow passing ContextInterface instance to Form::create().

  • Loading branch information...
ADmad committed Aug 6, 2017
1 parent 086dc61 commit 3b0c29d3ec11bc96a0b88805807ee74be37633a4
Showing with 14 additions and 8 deletions.
  1. +12 −8 src/View/Helper/FormHelper.php
  2. +2 −0 tests/TestCase/View/Helper/FormHelperTest.php
@@ -327,9 +327,9 @@ protected function _addDefaultContextProviders()
* - `valueSources` The sources that values should be read from. See FormHelper::setValueSources()
* - `templateVars` Provide template variables for the formStart template.
*
* @param mixed $context The context for which the form is being defined. Can
* be an ORM entity, ORM resultset, or an array of meta data. You can use false or null
* to make a context-less form.
* @param mixed $context The context for which the form is being defined.
* Can be a ContextInterface instance, ORM entity, ORM resultset, or an
* array of meta data. You can use false or null to make a context-less form.
* @param array $options An array of html attributes and options.
* @return string An formatted opening FORM tag.
* @link https://book.cakephp.org/3.0/en/views/helpers/form.html#Cake\View\Helper\FormHelper::create
@@ -338,12 +338,16 @@ public function create($context = null, array $options = [])
{
$append = '';
if (empty($options['context'])) {
$options['context'] = [];
if ($context instanceof ContextInterface) {
$this->context($context);
} else {
if (empty($options['context'])) {
$options['context'] = [];
}
$options['context']['entity'] = $context;
$context = $this->_getContext($options['context']);
unset($options['context']);
}
$options['context']['entity'] = $context;
$context = $this->_getContext($options['context']);
unset($options['context']);
$isCreate = $context->isCreate();
@@ -415,6 +415,7 @@ public function contextSelectionProvider()
]
];
$form = new Form();
$custom = $this->getMockBuilder('Cake\View\Form\ContextInterface')->getMock();
return [
'entity' => [$entity, 'Cake\View\Form\EntityContext'],
@@ -425,6 +426,7 @@ public function contextSelectionProvider()
'form' => [$form, 'Cake\View\Form\FormContext'],
'none' => [null, 'Cake\View\Form\NullContext'],
'false' => [false, 'Cake\View\Form\NullContext'],
'custom' => [$custom, get_class($custom)]
];
}

0 comments on commit 3b0c29d

Please sign in to comment.
You can’t perform that action at this time.