forked from zendframework/zendframework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a test to render with a custom element helper.
- Loading branch information
1 parent
8b2d389
commit 1e4b2c7
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_Form | ||
*/ | ||
|
||
namespace ZendTest\Form\TestAsset; | ||
|
||
use Zend\Form\ElementInterface; | ||
use Zend\Form\View\Helper\AbstractHelper; | ||
use Zend\Form\View\Helper\FormElement; | ||
|
||
class CustomViewHelper extends AbstractHelper | ||
{ | ||
/** | ||
* @var FormElement | ||
*/ | ||
protected $elementHelper; | ||
|
||
public function __invoke(ElementInterface $element) | ||
{ | ||
$elementHelper = $this->getElementHelper(); | ||
|
||
$name = preg_replace('/[^a-z0-9_-]+/', '', $element->getName()); | ||
|
||
$result = '<div id="custom' . $name . '">' . $elementHelper($element) . '</div>'; | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* Retrieve the FormElement helper | ||
* | ||
* @return FormElement | ||
*/ | ||
protected function getElementHelper() | ||
{ | ||
if ($this->elementHelper) { | ||
return $this->elementHelper; | ||
} | ||
|
||
if (method_exists($this->view, 'plugin')) { | ||
$this->elementHelper = $this->view->plugin('form_element'); | ||
} | ||
|
||
if (!$this->elementHelper instanceof FormElement) { | ||
$this->elementHelper = new FormElement(); | ||
} | ||
|
||
return $this->elementHelper; | ||
} | ||
} |
This file contains 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