Skip to content
This repository was archived by the owner on Sep 30, 2020. It is now read-only.
4 changes: 1 addition & 3 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

class Module implements AutoloaderProviderInterface, ConfigProviderInterface
{

public function getAutoloaderConfig()
{
return array(
Expand All @@ -26,5 +25,4 @@ public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}

}
}
21 changes: 20 additions & 1 deletion autoload_classmap.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
<?php
return array();
// Generated by ZF2's ./bin/classmap_generator.php
return array(
'AgvBootstrap\Module' => __DIR__ . '/Module.php',
'AgvBootstrap\Form\View\Helper\Form' => __DIR__ . '/src/AgvBootstrap/Form/View/Helper/Form.php',
'AgvBootstrap\Form\View\Helper\FormActions' => __DIR__ . '/src/AgvBootstrap/Form/View/Helper/FormActions.php',
'AgvBootstrap\Form\View\Helper\FormButton' => __DIR__ . '/src/AgvBootstrap/Form/View/Helper/FormButton.php',
'AgvBootstrap\Form\View\Helper\FormCollection' => __DIR__ . '/src/AgvBootstrap/Form/View/Helper/FormCollection.php',
'AgvBootstrap\Form\View\Helper\FormDate' => __DIR__ . '/src/AgvBootstrap/Form/View/Helper/FormDate.php',
'AgvBootstrap\Form\View\Helper\FormElementErrors' => __DIR__ . '/src/AgvBootstrap/Form/View/Helper/FormElementErrors.php',
'AgvBootstrap\Form\View\Helper\FormInput' => __DIR__ . '/src/AgvBootstrap/Form/View/Helper/FormInput.php',
'AgvBootstrap\Form\View\Helper\FormRadio' => __DIR__ . '/src/AgvBootstrap/Form/View/Helper/FormRadio.php',
'AgvBootstrap\Form\View\Helper\FormRow' => __DIR__ . '/src/AgvBootstrap/Form/View/Helper/FormRow.php',
'AgvBootstrap\Form\View\Helper\FormSelect' => __DIR__ . '/src/AgvBootstrap/Form/View/Helper/FormSelect.php',
'AgvBootstrap\Form\View\Helper\FormSubmit' => __DIR__ . '/src/AgvBootstrap/Form/View/Helper/FormSubmit.php',
'AgvBootstrap\Form\View\Helper\FormTextarea' => __DIR__ . '/src/AgvBootstrap/Form/View/Helper/FormTextarea.php',
'AgvBootstrap\View\Helper\Alert' => __DIR__ . '/src/AgvBootstrap/View/Helper/Alert.php',
'AgvBootstrap\View\Helper\Navigation\AbstractHelper' => __DIR__ . '/src/AgvBootstrap/View/Helper/Navigation/AbstractHelper.php',
'AgvBootstrap\View\Helper\Navigation\AbstractNavigationHelper' => __DIR__ . '/src/AgvBootstrap/View/Helper/Navigation/AbstractNavigationHelper.php',
'AgvBootstrap\View\Helper\Navigation\Navbar' => __DIR__ . '/src/AgvBootstrap/View/Helper/Navigation/Navbar.php',
);
3 changes: 2 additions & 1 deletion config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'alert' => 'AgvBootstrap\View\Helper\Alert',
'formSelect' => 'AgvBootstrap\Form\View\Helper\FormSelect',
'formElementErrors' => 'AgvBootstrap\Form\View\Helper\FormElementErrors',
'formDate' => 'AgvBootstrap\Form\View\Helper\FormDate',
),
),
);
);
12 changes: 5 additions & 7 deletions src/AgvBootstrap/Form/View/Helper/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Form extends ZendForm
/**
* Generate an opening form tag
*
* @param FormInterface $form
* @param FormInterface $form
* @return string
*/
public function openTag(FormInterface $form = null)
Expand All @@ -66,7 +66,7 @@ public function openTag(FormInterface $form = null)
'action' => '',
'method' => 'get',
'role' => 'form',
'class' => ''
'class' => '',
);

if ($form instanceof FormInterface) {
Expand All @@ -77,9 +77,8 @@ public function openTag(FormInterface $form = null)
}
$attributes = array_merge($attributes, $formAttributes);
}

if (!empty($this->type) && !empty($this->validTypes[$this->type])) {

if (isset($attributes['class'])) {
$attributes['class'] = $attributes['class'] . ' ';
}
Expand All @@ -99,8 +98,7 @@ public function openTag(FormInterface $form = null)
public function setType($type)
{
$this->type = $type;

return $this;
}

}
}
18 changes: 9 additions & 9 deletions src/AgvBootstrap/Form/View/Helper/FormActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@

class FormActions extends AbstractHelper
{

/**
* Renders the form-actions div tag
* @param array $content Either a string or an array of elements
* @param array $content Either a string or an array of elements
* @return string
*/
public function render($content)
Expand All @@ -23,13 +22,14 @@ public function render($content)
}

$html .= PHP_EOL . $this->closeTag();

return $html;
}

/**
* Returns the form-renderActions open tag
* @param null|string $formType
* @param array $displayOptions
* @param null|string $formType
* @param array $displayOptions
* @return string
*/
public function openTag()
Expand All @@ -39,7 +39,7 @@ public function openTag()

/**
* Returns the control group closing tag
* @param null|string $formType
* @param null|string $formType
* @return string
*/
public function closeTag()
Expand All @@ -50,17 +50,17 @@ public function closeTag()
/**
* Invoke helper as function
* Proxies to {@link render()}.
* @param string|array|null $content Either a string or an array of elements
* @param null|string $formType
* @param array $displayOptions
* @param string|array|null $content Either a string or an array of elements
* @param null|string $formType
* @param array $displayOptions
* @return string|FormActionsTwb
*/
public function __invoke($content = array())
{
if (!$content) {
return $this;
}

return $this->render($content);
}

}
61 changes: 48 additions & 13 deletions src/AgvBootstrap/Form/View/Helper/FormButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

class FormButton extends ZendFormButton
{
const HTML_CLASS_ATTRIBUTE = 'btn btn-default';
const HTML_SUBMIT_CLASS_ATTRIBUTE = ' btn btn-primary ';

/**
* Invoke helper as functor
Expand All @@ -18,7 +20,8 @@ class FormButton extends ZendFormButton
* @param null|string $buttonContent
* @return string|FormButton
*/
public function __invoke(ElementInterface $element = null, $buttonContent = null)
public function __invoke(ElementInterface $element = null,
$buttonContent = null)
{
if (!$element) {
return $this;
Expand All @@ -31,8 +34,8 @@ public function __invoke(ElementInterface $element = null, $buttonContent = null
* Render a form <button> element from the provided $element,
* using content from $buttonContent or the element's "label" attribute
*
* @param ElementInterface $element
* @param null|string $buttonContent
* @param ElementInterface $element
* @param null|string $buttonContent
* @throws Exception\DomainException
* @return string
*/
Expand All @@ -45,7 +48,7 @@ public function render(ElementInterface $element, $buttonContent = null)
if (null === $buttonContent) {
throw new Exception\DomainException(sprintf(
'%s expects either button content as the second argument, ' .
'or that the element provided has a label value; neither found',
'or that the element provided has a label value; neither found',
__METHOD__
));
}
Expand All @@ -59,13 +62,19 @@ public function render(ElementInterface $element, $buttonContent = null)

$escape = $this->getEscapeHtmlHelper();

return $openTag . $escape($buttonContent) . $this->closeTag();
$attributes = $element->getAttributes();
$icon = '';
if(isset($attributes['icon'])) {
$icon = sprintf('<i class="%s"></i> ', $attributes['icon']);
}

return $openTag . $icon . $escape($buttonContent) . $this->closeTag();
}

/**
* Generate an opening button tag
*
* @param null|array|ElementInterface $attributesOrElement
* @param null|array|ElementInterface $attributesOrElement
* @throws Exception\InvalidArgumentException
* @throws Exception\DomainException
* @return string
Expand All @@ -77,36 +86,62 @@ public function openTag($attributesOrElement = null)
}

if (is_array($attributesOrElement)) {
$attributesOrElement = $this->classTagExists($attributesOrElement);
$attributes = $this->createAttributesString($attributesOrElement);
return sprintf('<button class="btn btn-default" %s>', $attributes);

return sprintf(
'<button class="%s" %s>',
self::HTML_CLASS_ATTRIBUTE,
$attributes
);
}

if (!$attributesOrElement instanceof ElementInterface) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects an array or Zend\Form\ElementInterface instance; received "%s"',
__METHOD__,
(is_object($attributesOrElement) ? get_class($attributesOrElement) : gettype($attributesOrElement))
(is_object($attributesOrElement) ? get_class($attributesOrElement)
: gettype($attributesOrElement))
));
}

$element = $attributesOrElement;
$name = $element->getName();
$name = $element->getName();
if (empty($name) && $name !== 0) {
throw new Exception\DomainException(sprintf(
'%s requires that the element has an assigned name; none discovered',
__METHOD__
));
}

$attributes = $element->getAttributes();
$attributes['name'] = $name;
$attributes['type'] = $this->getType($element);
$attributes = $element->getAttributes();
$attributes['name'] = $name;
$attributes['type'] = $this->getType($element);
$attributes['value'] = $element->getValue();

$attributes = $this->classTagExists($attributes);

return sprintf(
'<button class="btn btn-default" %s>',
'<button %s>',
$this->createAttributesString($attributes)
);
}

/**
* Verify if class tag was setted up if not it will set it up
* @param array $attributes
* @return boolean
*/
private function classTagExists($attributes)
{
if (!isset($attributes['class'])) {
$attributes['class'] = self::HTML_CLASS_ATTRIBUTE;
}

if($attributes['type'] == 'submit' && isset($attributes['class'])) {
$attributes['class'] = self::HTML_SUBMIT_CLASS_ATTRIBUTE . $attributes['class'] ;
}

return $attributes;
}
}
Loading