Skip to content

Commit

Permalink
Merge pull request #18 from syberon/custom-attributes
Browse files Browse the repository at this point in the history
Added ability to use of custom attributes
  • Loading branch information
neilime authored Jun 3, 2019
2 parents d81786b + 55c4684 commit 6e7e730
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 7 deletions.
10 changes: 3 additions & 7 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
'submit',
'static',
],
'validTagAttributes' => [],
'validTagAttributePrefixes' => [],
'type_map' => [],
'class_map' => [],
],
Expand All @@ -30,7 +32,7 @@
'alert' => 'TwbsHelper\View\Helper\Alert',
'badge' => 'TwbsHelper\View\Helper\Badge',
'blockquote' => 'TwbsHelper\View\Helper\Blockquote',
'buttonGroup' => 'TwbsHelper\View\Helper\ButtonGroup',
'buttonGroup' => 'TwbsHelper\View\Helper\ButtonGroup',
'figure' => 'TwbsHelper\View\Helper\Figure',
'htmlList' => 'TwbsHelper\View\Helper\HtmlList',
'table' => 'TwbsHelper\View\Helper\Table',
Expand All @@ -48,12 +50,6 @@
'formStatic' => 'TwbsHelper\Form\View\Helper\FormStatic',
'formErrors' => 'TwbsHelper\Form\View\Helper\FormErrors',

// Glyphicon
'glyphicon' => 'TwbsHelper\View\Helper\Glyphicon',

// FontAwesome
'fontAwesome' => 'TwbsHelper\View\Helper\FontAwesome',

// ZF3
'form_button' => 'TwbsHelper\Form\View\Helper\FormButton',
'form_submit' => 'TwbsHelper\Form\View\Helper\FormButton',
Expand Down
25 changes: 25 additions & 0 deletions src/TwbsHelper/Form/View/Helper/FormElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,31 @@ public function render(ElementInterface $oElement)
return $sMarkup;
}

/**
* Render element by helper name
*
* @param string $name
* @param ElementInterface $element
* @return string
*/
protected function renderHelper($name, ElementInterface $element)
{
$helper = $this->getView()->plugin($name);

if ($this->options->getValidTagAttributes()) {
foreach ($this->options->getValidTagAttributes() as $attribute) {
$helper->addValidAttribute($attribute);
}
}

if ($this->options->getValidTagAttributePrefixes()) {
foreach ($this->options->getValidTagAttributePrefixes() as $prefix) {
$helper->addValidAttributePrefix($prefix);
}
}

return $helper($element);
}

/**
* renderAddOn
Expand Down
60 changes: 60 additions & 0 deletions src/TwbsHelper/Options/ModuleOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ class ModuleOptions extends AbstractOptions
// @var array
protected $ignoredViewHelpers;

// @var array
protected $validTagAttributes;

// @var array
protected $validTagAttributePrefixes;

// @var array
protected $classMap;

Expand Down Expand Up @@ -47,6 +53,60 @@ public function setIgnoredViewHelpers(array $aIgnoredViewHelpers)
}


/**
* getValidTagAttributes
*
* @access public
* @return array
*/
public function getValidTagAttributes()
{
return $this->validTagAttributes;
}


/**
* setIgnoredViewHelpers
*
* @param array $aValidTagAttributes
* @access public
* @return \TwbsHelper\Options\ModuleOptions
*/
public function setValidTagAttributes(array $aValidTagAttributes)
{
$this->validTagAttributes = $aValidTagAttributes;

return $this;
}


/**
* getValidTagAttributePrefixes
*
* @access public
* @return array
*/
public function getValidTagAttributePrefixes()
{
return $this->validTagAttributePrefixes;
}


/**
* setValidTagAttributePrefixes
*
* @param array $aValidTagAttributePrefixes
* @access public
* @return \TwbsHelper\Options\ModuleOptions
*/
public function setValidTagAttributePrefixes(array $aValidTagAttributePrefixes)
{
$this->validTagAttributePrefixes = $aValidTagAttributePrefixes;

return $this;
}


/**
* getClassMap
*
Expand Down

0 comments on commit 6e7e730

Please sign in to comment.