theliatype in form : types now extends bastype which implement typeinterface
basetype provides verifiyForm method wich can be call in Callback constraint
This commit is contained in:
@@ -39,7 +39,7 @@ class TheliaType extends AbstractType
|
|||||||
|
|
||||||
public function getParent()
|
public function getParent()
|
||||||
{
|
{
|
||||||
return 'form';
|
return 'text';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName()
|
public function getName()
|
||||||
|
|||||||
@@ -152,6 +152,7 @@ class Form extends AbstractSmartyPlugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
$template->assign("attr", implode(" ", $attr));
|
$template->assign("attr", implode(" ", $attr));
|
||||||
|
$template->assign("attr_list", $fieldVars["attr"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function assignFormTypeValues($template, $formFieldConfig, $formFieldView)
|
protected function assignFormTypeValues($template, $formFieldConfig, $formFieldView)
|
||||||
|
|||||||
@@ -55,13 +55,6 @@ class TaxCreationForm extends BaseForm
|
|||||||
"required" => true,
|
"required" => true,
|
||||||
"constraints" => array(
|
"constraints" => array(
|
||||||
new Constraints\NotBlank(),
|
new Constraints\NotBlank(),
|
||||||
new Constraints\Callback(
|
|
||||||
array(
|
|
||||||
"methods" => array(
|
|
||||||
array($this, "verifyRequirements"),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
"label" => Translator::getInstance()->trans("Type"),
|
"label" => Translator::getInstance()->trans("Type"),
|
||||||
"label_attr" => array("for" => "type_field"),
|
"label_attr" => array("for" => "type_field"),
|
||||||
@@ -77,7 +70,7 @@ class TaxCreationForm extends BaseForm
|
|||||||
new Constraints\Callback(
|
new Constraints\Callback(
|
||||||
array(
|
array(
|
||||||
"methods" => array(
|
"methods" => array(
|
||||||
array($this, "verifyRequirements"),
|
array($requirementType, "verifyForm"),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
@@ -104,10 +97,10 @@ class TaxCreationForm extends BaseForm
|
|||||||
return "thelia_tax_creation";
|
return "thelia_tax_creation";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function verifyRequirements($value, ExecutionContextInterface $context)
|
public function verifyForm($value, ExecutionContextInterface $context)
|
||||||
{
|
{
|
||||||
$in = true;
|
$in = true;
|
||||||
|
|
||||||
|
//$this->getForm()->getChildren()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class AlphaNumStringListType implements TypeInterface
|
class AlphaNumStringListType extends BaseType
|
||||||
{
|
{
|
||||||
public function getType()
|
public function getType()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class AlphaNumStringType implements TypeInterface
|
class AlphaNumStringType extends BaseType
|
||||||
{
|
{
|
||||||
public function getType()
|
public function getType()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class AnyType implements TypeInterface
|
class AnyType extends BaseType
|
||||||
{
|
{
|
||||||
public function getType()
|
public function getType()
|
||||||
{
|
{
|
||||||
|
|||||||
46
core/lib/Thelia/Type/BaseType.php
Normal file
46
core/lib/Thelia/Type/BaseType.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
/*************************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* Thelia */
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) OpenStudio */
|
||||||
|
/* email : info@thelia.net */
|
||||||
|
/* web : http://www.thelia.net */
|
||||||
|
/* */
|
||||||
|
/* This program is free software; you can redistribute it and/or modify */
|
||||||
|
/* it under the terms of the GNU General Public License as published by */
|
||||||
|
/* the Free Software Foundation; either version 3 of the License */
|
||||||
|
/* */
|
||||||
|
/* This program is distributed in the hope that it will be useful, */
|
||||||
|
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||||
|
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||||
|
/* GNU General Public License for more details. */
|
||||||
|
/* */
|
||||||
|
/* You should have received a copy of the GNU General Public License */
|
||||||
|
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
/* */
|
||||||
|
/*************************************************************************************/
|
||||||
|
namespace Thelia\Type;
|
||||||
|
|
||||||
|
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
abstract class BaseType implements TypeInterface
|
||||||
|
{
|
||||||
|
abstract public function getType();
|
||||||
|
abstract public function isValid($value);
|
||||||
|
abstract public function getFormattedValue($value);
|
||||||
|
abstract public function getFormType();
|
||||||
|
abstract public function getFormOptions();
|
||||||
|
|
||||||
|
public function verifyForm($value, ExecutionContextInterface $context)
|
||||||
|
{
|
||||||
|
if( ! $this->isValid($value) ) {
|
||||||
|
$context->addViolation("Thelia Type not matched");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,7 +29,7 @@ namespace Thelia\Type;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class BooleanOrBothType implements TypeInterface
|
class BooleanOrBothType extends BaseType
|
||||||
{
|
{
|
||||||
|
|
||||||
const ANY = '*';
|
const ANY = '*';
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class BooleanType implements TypeInterface
|
class BooleanType extends BaseType
|
||||||
{
|
{
|
||||||
public function getType()
|
public function getType()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class EnumListType implements TypeInterface
|
class EnumListType extends BaseType
|
||||||
{
|
{
|
||||||
protected $values = array();
|
protected $values = array();
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class EnumType implements TypeInterface
|
class EnumType extends BaseType
|
||||||
{
|
{
|
||||||
protected $values = array();
|
protected $values = array();
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class FloatToFloatArrayType implements TypeInterface
|
class FloatToFloatArrayType extends BaseType
|
||||||
{
|
{
|
||||||
public function getType()
|
public function getType()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class FloatType implements TypeInterface
|
class FloatType extends BaseType
|
||||||
{
|
{
|
||||||
public function getType()
|
public function getType()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class IntListType implements TypeInterface
|
class IntListType extends BaseType
|
||||||
{
|
{
|
||||||
public function getType()
|
public function getType()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class IntToCombinedIntsListType implements TypeInterface
|
class IntToCombinedIntsListType extends BaseType
|
||||||
{
|
{
|
||||||
public function getType()
|
public function getType()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class IntToCombinedStringsListType implements TypeInterface
|
class IntToCombinedStringsListType extends BaseType
|
||||||
{
|
{
|
||||||
public function getType()
|
public function getType()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class IntType implements TypeInterface
|
class IntType extends BaseType
|
||||||
{
|
{
|
||||||
public function getType()
|
public function getType()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace Thelia\Type;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class JsonType implements TypeInterface
|
class JsonType extends BaseType
|
||||||
{
|
{
|
||||||
public function getType()
|
public function getType()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ use Thelia\Exception\TypeException;
|
|||||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class ModelType implements TypeInterface
|
class ModelType extends BaseType
|
||||||
{
|
{
|
||||||
protected $expectedModelActiveRecord = null;
|
protected $expectedModelActiveRecord = null;
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ use Thelia\Exception\TypeException;
|
|||||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class ModelValidIdType implements TypeInterface
|
class ModelValidIdType extends BaseType
|
||||||
{
|
{
|
||||||
protected $expectedModelActiveRecordQuery = null;
|
protected $expectedModelActiveRecordQuery = null;
|
||||||
|
|
||||||
|
|||||||
@@ -22,12 +22,13 @@
|
|||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
namespace Thelia\Type;
|
namespace Thelia\Type;
|
||||||
|
|
||||||
|
use Symfony\Component\Validator\ExecutionContextInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
interface TypeInterface
|
interface TypeInterface
|
||||||
{
|
{
|
||||||
public function getType();
|
public function getType();
|
||||||
@@ -38,4 +39,5 @@ interface TypeInterface
|
|||||||
|
|
||||||
public function getFormType();
|
public function getFormType();
|
||||||
public function getFormOptions();
|
public function getFormOptions();
|
||||||
|
public function verifyForm($value, ExecutionContextInterface $context);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,7 @@
|
|||||||
{form_tagged_fields form=$form tag='requirements'}
|
{form_tagged_fields form=$form tag='requirements'}
|
||||||
<div class="form-group {if $error}has-error{/if} js-tax-requirements" data-tax-type="{$data.tax_type}" {if $data.tax_type != $TYPE}style="display: none"{/if}>
|
<div class="form-group {if $error}has-error{/if} js-tax-requirements" data-tax-type="{$data.tax_type}" {if $data.tax_type != $TYPE}style="display: none"{/if}>
|
||||||
<label for="{$label_attr.for}" class="control-label">
|
<label for="{$label_attr.for}" class="control-label">
|
||||||
{intl l=$label} :
|
{intl l=$label} : {$formType}
|
||||||
</label>
|
</label>
|
||||||
{if $formType == 'choice'}
|
{if $formType == 'choice'}
|
||||||
<select name="{$name}">
|
<select name="{$name}">
|
||||||
|
|||||||
Reference in New Issue
Block a user