So, been working on it for a fair bit, and I’m stuck.
What I wish to do is a to create a custom “type”, Markdown
. So, I’ve created the Element class Markdown
, and set the attributes to 'type' => 'markdown'
, like so:
use Zend\Form\Element;
final class Markdown extends Element
{
protected $attributes = [
'type' => 'markdown',
];
}
That works, it’s passed on for rendering. But then, I want to render it like a <textarea>
get’s rendered. However, I wish to do a few custom things in the ViewHelper. As such, for the type
“markdown” I want a custom ViewHelper.
use Markdown\Form\Element\Markdown;
use Zend\Form\ElementInterface;
use Zend\Form\Exception\DomainException;
use Zend\Form\View\Helper\FormInput;
use Zend\Form\View\Helper\FormTextarea;
final class FormMarkdown extends FormInput // or extends FormElement
{
protected $validTypes = [ // or not this when FormElement
'markdown' => true,
];
public function __construct()
{
$this->addClass(Markdown::class, FormMarkdown::class);
}
}
And lastly, make sure this is all registered:
'view_helper' => [
'aliases' => [
'mark_down' => FormMarkdown::class,
'markdown' => FormMarkdown::class,
'Markdown' => FormMarkdown::class,
'MarkDown' => FormMarkdown::class,
],
'factories' => [
FormMarkdown::class => InvokableFactory::class,
],
],
However, when debugging, I found that it goes all the way to the FormElement::renderType(..)
function, where it decides that no renderHelper
is known for at the key “markdown” ($this->typeMap[$type])
- \Zend\Form\View\Helper\FormElement::renderType()
).
That array ($typeMap
) in the FormElement class, is there a way of extending it from an external module, e.g. “markdown”, to have this new type used by the new ViewHelper?
Been scouring the docs, SO and now here for hours and got zip
p.s. - just to clarify -> not trying to modify behaviour of existing ones, I want to realize a completely new “type”
p.p.s - if you read the above and thought: why? doing it “like this” is much simpler, then I’m all ears