Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Form view helpers' invoke method should be chainable for options #1478

Merged
merged 2 commits into from Jun 13, 2012

Conversation

Projects
None yet
3 participants
Contributor

akandels commented Jun 11, 2012

View Helper Elements:

  • Select
  • Input
  • Textarea
  • Multicheckbox
  • Element

It does not seem to be possible to set options (separator, label position, etc.) on the above form view helpers directly from the view. It can be set at a higher level, but there are cases where you might want to set view-level options on a per-element basis when building out the view.

This simply makes it so that you can call the invoke() of the view helper to fluently get the helper object in which case option methods can be directly called, such as:

$this->formMulticheckbox()->setSeparator('')->render($element);

This functionality is already present in the label view helpers, I'm simply extending it to all other helpers.

Tests:

  • Invoke with no element chains helper (x5, one per form view helper test)
Owner

weierophinney commented Jun 11, 2012

Looks good. Just a note: you can always call $this->plugin('plugin_name')
to retrieve the helper instance, and thus configure it. (I did this with
the label helper in the examples.)

On Monday, June 11, 2012, Andrew Kandels wrote:

View Helper Elements:

  • Select
  • Input
  • Textarea
  • Multicheckbox
  • Element

It does not seem to be possible to set options (separator, label position,
etc.) on the above form view helpers directly from the view. It can be set
at a higher level, but there are cases where you might want to set
view-level options on a per-element basis when building out the view.

This simply makes it so that you can call the invoke() of the view helper
to fluently get the helper object in which case option methods can be
directly called, such as:

$this->formMulticheckbox()->setSeparator('')->render($element);

This functionality is already present in the label view helpers, I'm
simply extending it to all other helpers.

Tests:

  • Invoke with no element chains helper (x5, one per form view helper test)

You can merge this Pull Request by running:

git pull https://github.com/akandels/zf2hotfix/form-view-helpers-chainable-for-options

Or you can view, comment on it, or merge it online at:

zendframework#1478

-- Commit Summary --

  • The formMulticheckbox view helper should chain when invoked with no
    element so that options can be set easily from the view
  • extending the fluent interface to other non-compatible elmeents

-- File Changes --

M library/Zend/Form/View/Helper/FormElement.php (8)
M library/Zend/Form/View/Helper/FormInput.php (8)
M library/Zend/Form/View/Helper/FormMultiCheckbox.php (8)
M library/Zend/Form/View/Helper/FormSelect.php (8)
M library/Zend/Form/View/Helper/FormTextarea.php (8)
M tests/Zend/Form/View/Helper/FormElementTest.php (6)
M tests/Zend/Form/View/Helper/FormInputTest.php (6)
M tests/Zend/Form/View/Helper/FormMultiCheckboxTest.php (6)
M tests/Zend/Form/View/Helper/FormSelectTest.php (6)
M tests/Zend/Form/View/Helper/FormTextareaTest.php (6)

-- Patch Links --

https://github.com/zendframework/zf2/pull/1478.patch
https://github.com/zendframework/zf2/pull/1478.diff


Reply to this email directly or view it on GitHub:
zendframework#1478

Matthew Weier O'Phinney
matthew@weierophinney.net
http://mwop.net/

Contributor

akandels commented Jun 11, 2012

Oh, makes sense. Thanks!

Contributor

mwillbanks commented Jun 12, 2012

Matthew,

I understand that but in terms of the documentation it shows it being utilized the other way as well... I also believe I have attempted $this->plugin('plugin_name') which seems to also call invoke.

Owner

weierophinney commented Jun 12, 2012

Mike - plugin() only ever returns the instance; it never calls other
methods. Also, not saying we shouldn't use the patch, but, rather, giving
an alternate workflow until applied.

On Tuesday, June 12, 2012, Mike Willbanks wrote:

Matthew,

I understand that but in terms of the documentation it shows it being
utilized the other way as well... I also believe I have attempted
$this->plugin('plugin_name') which seems to also call invoke.


Reply to this email directly or view it on GitHub:
zendframework#1478 (comment)

Matthew Weier O'Phinney
matthew@weierophinney.net
http://mwop.net/

weierophinney added a commit that referenced this pull request Jun 13, 2012

[#1478] fix some helpers to introduce fluent interface
- FormCheckbox, Captcha\AbstractWord, and Captcha\ReCaptcha needed
  updates for __invoke() due to changes higher in the inheritance tree

@weierophinney weierophinney merged commit 4961d7b into zendframework:master Jun 13, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment