Last active
August 29, 2015 14:03
-
-
Save webdevilopers/b22f7471fd2b8d60cdea to your computer and use it in GitHub Desktop.
Abstract Autocomplete Form View Helper ZF2 issue #4221
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Application\Form\View\Helper; | |
use Zend\Form\View\Helper\FormText; | |
use Zend\Form\ElementInterface as ElementInterface; | |
class AbstractFormAutocomplete extends FormText | |
{ | |
protected $foo; | |
public function render(ElementInterface $element) | |
{ | |
$this->getFoo($element); | |
return parent::render($element); | |
} | |
/** | |
* @return the $select | |
*/ | |
public function getFoo(ElementInterface $element) { | |
if (!$this->foo) { | |
$foo = 'foo'; | |
$this->setFoo($foo); | |
} | |
return $this->foo; | |
} | |
public function setFoo($foo) { | |
echo "foo set to $foo"; | |
$this->foo = $foo; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$this->add(array( | |
'name' => 'setfoo', | |
'type' => 'autocompletehidden', | |
'options' => array( | |
'label' => 'I will set Foo' | |
)); | |
$this->add(array( | |
'name' => 'foostillset', | |
'type' => 'autocompletehidden', | |
'options' => array( | |
'label' => 'Foo is already set' | |
)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function getViewHelperConfig() | |
{ | |
return array( | |
'invokables' => array( | |
'formelement' => 'Application\Form\View\Helper\FormElement', | |
'formautocompletehidden' => 'Application\Form\View\Helper\FormAutocompleteHidden' | |
), | |
'shared' => array( | |
'formelement' => false, | |
'formautocompletehidden' => false | |
), | |
); | |
} | |
public function getFormElementConfig() | |
{ | |
return array( | |
'invokables' => array( | |
'autocompletehidden' => 'Application\Form\Element\AutocompleteHidden', | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please see ZF2 issue #4221 zendframework/zendframework#4221 .