Skip to content

Commit

Permalink
[Jobs] adds a stripTagText to our garden of input-elements
Browse files Browse the repository at this point in the history
(#5803)
  • Loading branch information
mathias-weitz-cross-solutions committed May 13, 2015
1 parent d6207b6 commit 1a1db92
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 14 deletions.
2 changes: 1 addition & 1 deletion module/Auth/src/Auth/Form/ForgotPassword.php
Expand Up @@ -23,7 +23,7 @@ public function __construct($name = 'forgot-password', $options = array())

$this->add(
array(
'type' => 'text',
'type' => 'StrippedTagText',
'name' => 'identity',
'options' => array(
'label' => /* @translate */ 'Username or email',
Expand Down
2 changes: 1 addition & 1 deletion module/Auth/src/Auth/Form/GroupFieldset.php
Expand Up @@ -38,7 +38,7 @@ public function init()
));

$this->add(array(
'type' => 'Text',
'type' => 'StrippedTagText',
'name' => 'name',
'options' => array(
'label' => /*@translate*/ 'Group name',
Expand Down
2 changes: 1 addition & 1 deletion module/Auth/src/Auth/Form/Register.php
Expand Up @@ -30,7 +30,7 @@ public function __construct($name = 'register-form', $options = array())

$fieldset->add(
array(
'type' => 'text',
'type' => 'StrippedTagText',
'name' => 'name',
'options' => array(
'label' => /*@translate*/ 'Name',
Expand Down
5 changes: 5 additions & 0 deletions module/Auth/src/Auth/Form/UserInfoFieldset.php
Expand Up @@ -73,13 +73,15 @@ public function init()
));

$this->add(array(
'type' => 'StrippedTagText',
'name' => 'postalcode',
'options' => array(
'label' => /* @translate */ 'Postalcode'
)
));

$this->add(array(
'type' => 'StrippedTagText',
'name' => 'city',
'options' => array(
'label' => /* @translate */ 'City'
Expand Down Expand Up @@ -112,6 +114,7 @@ public function init()
));

$this->add(array(
'type' => 'StrippedTagText',
'name' => 'lastName',
'options' => array(
'label' => /*@translate*/ 'Last name',
Expand All @@ -121,13 +124,15 @@ public function init()
));

$this->add(array(
'type' => 'StrippedTagText',
'name' => 'street',
'options' => array(
'label' => /*@translate*/ 'street'
)
));

$this->add(array(
'type' => 'StrippedTagText',
'name' => 'houseNumber',
'options' => array(
'label' => /*@translate*/ 'house number'
Expand Down
2 changes: 2 additions & 0 deletions module/Core/config/module.config.php
Expand Up @@ -321,6 +321,7 @@
'filters' => array(
'invokables' => array(
'Core/Repository/PropertyToKeywords' => 'Core\Repository\Filter\PropertyToKeywords',
'Core/StripTags' => 'Core\Filter\StripTags',
),
'factories' => array(
"Core/XssFilter" => "Core\Filter\XssFilterFactory",
Expand All @@ -343,6 +344,7 @@
'Core/PermissionsFieldset' => 'Core\Form\PermissionsFieldset',
'Core/PermissionsCollection' => 'Core\Form\PermissionsCollection',
'Location' => 'Zend\Form\Element\Text',
'StrippedTagText' => 'Core\Form\Element\StrippedTagText',
'Core/Spinner-Submit' => 'Core\Form\Element\SpinnerSubmit',
'togglebutton' => 'Core\Form\Element\ToggleButton',
'TextEditor' => 'Core\Form\Element\Editor',
Expand Down
22 changes: 22 additions & 0 deletions module/Core/src/Core/Filter/StripTags.php
@@ -0,0 +1,22 @@
<?php
/**
* YAWIK
*
* @filesource
* @copyright (c) 2013-2015 Cross Solution (http://cross-solution.de)
* @license MIT
* @author weitz@cross-solution.de
*/

namespace Core\Filter;

use Zend\Filter\FilterInterface;
use Zend\Filter\Exception;

class StripTags implements FilterInterface
{
public function filter($value)
{
return strip_tags($value);
}
}
34 changes: 34 additions & 0 deletions module/Core/src/Core/Form/Element/StrippedTagText.php
@@ -0,0 +1,34 @@
<?php
/**
* YAWIK
*
* @filesource
* @copyright (c) 2013-2015 Cross Solution (http://cross-solution.de)
* @license MIT
* @author weitz@cross-solution.de
*/

namespace Core\Form\Element;

use Zend\Form\Element\Text;
use Zend\InputFilter\InputProviderInterface;
use Zend\Stdlib\ArrayUtils;

class StrippedTagText extends Text implements InputProviderInterface
{
public function __construct($name = null, $options = array())
{
parent::__construct($name, $options);
}

public function getInputSpecification()
{
$specs = array(
'name' => $this->getName(),
'filters' => array(
array('name' => 'Core/StripTags'),
),
);
return $specs;
}
}
42 changes: 42 additions & 0 deletions module/Core/src/Core/Form/SummaryForm.php
Expand Up @@ -10,6 +10,11 @@
/** Core forms */
namespace Core\Form;

use Zend\Form\FieldsetInterface;
use Zend\InputFilter\InputFilterInterface;
use Zend\InputFilter\InputFilterProviderInterface;
use Zend\InputFilter\ReplaceableInputInterface;

/**
* Form which provides alternate rendering (summary).
*
Expand Down Expand Up @@ -107,5 +112,42 @@ public function setOptions($options)
$this->setDisplayMode($options['display_mode']);
}
}

/**
* for all Form, which use a Class for element-Spezification,
* set the default for merging the specification
*
* you stell need to implement the spezifications as ReplaceableInputInterface
*
* @param InputFilterInterface $inputFilter
* @param FieldsetInterface $fieldset
*/
public function attachInputFilterDefaults(InputFilterInterface $inputFilter, FieldsetInterface $fieldset)
{
if ($fieldset instanceof InputFilterProviderInterface) {
$fieldset->setPreferFormInputFilter(false);
}
parent::attachInputFilterDefaults($inputFilter, $fieldset);

// Just for failure-detection,
// if the fieldset is of the type InputFilterProviderInterface and it should merge the spezifications,
// the inputfilter still needs to be an instance of ReplaceableInputInterface
// since there is no general need for that, not being a ReplaceableInputInterface is not an error.
// This here should be just a reminder, maybe for debugging
if ($fieldset instanceof InputFilterProviderInterface) {
if (!$this->getPreferFormInputFilter()) {
// allMergedFilter contain all Filter, for which a merge has been applied
$allMergedFilter = [];
// this can not get fetched with getFilter() because it loops over this attachInput
if (isset($this->filter)) {
foreach ($this->filter->getInputs() as $filter) {
if ($filter instanceof ReplaceableInputInterface) {
$allMergedFilter[] = $filter;
}
}
}
}
}
}

}
4 changes: 2 additions & 2 deletions module/Jobs/src/Jobs/Form/AtsModeFieldset.php
Expand Up @@ -81,15 +81,15 @@ public function init()
));

$this->add(array(
'type' => 'Text',
'type' => 'StrippedTagText',
'name' => 'uri',
'options' => array(
'label' => /*@translate*/ 'URL',
)
));

$this->add(array(
'type' => 'Text',
'type' => 'StrippedTagText',
'name' => 'email',
'options' => array(
'label' => /*@translate*/ 'Email',
Expand Down
6 changes: 3 additions & 3 deletions module/Jobs/src/Jobs/Form/BaseFieldset.php
Expand Up @@ -38,13 +38,13 @@ public function init()
$this->setAttribute('id', 'job-fieldset');

$this->setName('jobBase');

$this->add(array(
'type' => 'Text',
'type' => 'StrippedTagText',
'name' => 'title',
'options' => array(
'label' => /*@translate*/ 'Job title',
'description' => /*@translate*/ 'Please enter the job title'
'description' => /*@translate*/ 'Please enter the job title',
),
));

Expand Down
2 changes: 2 additions & 0 deletions module/Jobs/src/Jobs/Form/CompanyNameElement.php
Expand Up @@ -16,6 +16,8 @@
/**
* this Class is a rudimentary base for the future extension of entering the hiring organization name
*
* @deprecated is now a select box
*
* Class JobNameElement
* @package Jobs\Form
*/
Expand Down
11 changes: 7 additions & 4 deletions module/Jobs/src/Jobs/Form/InputFilter/JobLocationEdit.php
Expand Up @@ -11,9 +11,10 @@
namespace Jobs\Form\InputFilter;

use Zend\InputFilter\InputFilter;
use Zend\InputFilter\ReplaceableInputInterface;
//use Zend\InputFilter\Input;

class JobLocationEdit extends InputFilter
class JobLocationEdit extends InputFilter implements ReplaceableInputInterface
{

public function init()
Expand All @@ -33,12 +34,13 @@ public function init()
// array('name' => 'StringTrim')
// ),
// ));

$this->add(array(
'name' => 'title',
'required' => true,
'filters' => array(
array('name' => 'StringTrim')
array('name' => 'StringTrim'),
array('name' => 'Core/XssFilter')
),
));

Expand All @@ -51,7 +53,8 @@ public function init()
'name' => 'location',
'required' => true,
'filters' => array(
array('name' => 'StringTrim')
array('name' => 'StringTrim'),
array('name' => 'Core/XssFilter')
),
));

Expand Down
4 changes: 2 additions & 2 deletions module/Jobs/test/JobsTest/Form/AtsModeFieldsetTest.php
Expand Up @@ -107,15 +107,15 @@ public function testInitialization()
);

$addUri = array(
'type' => 'Text',
'type' => 'StrippedTagText',
'name' => 'uri',
'options' => array(
'label' => 'URL',
)
);

$addEmail = array(
'type' => 'Text',
'type' => 'StrippedTagText',
'name' => 'email',
'options' => array(
'label' => 'Email',
Expand Down

0 comments on commit 1a1db92

Please sign in to comment.