Skip to content

Instantly share code, notes, and snippets.

@webdevilopers
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webdevilopers/b22f7471fd2b8d60cdea to your computer and use it in GitHub Desktop.
Save webdevilopers/b22f7471fd2b8d60cdea to your computer and use it in GitHub Desktop.
Abstract Autocomplete Form View Helper ZF2 issue #4221
<?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->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'
));
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',
),
);
}
@webdevilopers
Copy link
Author

Please see ZF2 issue #4221 zendframework/zendframework#4221 .

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