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:
Etienne Roudeix
2013-10-16 17:10:53 +02:00
parent 60fd54d5c3
commit a2048bec24
22 changed files with 71 additions and 29 deletions

View File

@@ -39,7 +39,7 @@ class TheliaType extends AbstractType
public function getParent()
{
return 'form';
return 'text';
}
public function getName()

View File

@@ -152,6 +152,7 @@ class Form extends AbstractSmartyPlugin
}
$template->assign("attr", implode(" ", $attr));
$template->assign("attr_list", $fieldVars["attr"]);
}
protected function assignFormTypeValues($template, $formFieldConfig, $formFieldView)

View File

@@ -55,13 +55,6 @@ class TaxCreationForm extends BaseForm
"required" => true,
"constraints" => array(
new Constraints\NotBlank(),
new Constraints\Callback(
array(
"methods" => array(
array($this, "verifyRequirements"),
),
)
),
),
"label" => Translator::getInstance()->trans("Type"),
"label_attr" => array("for" => "type_field"),
@@ -77,7 +70,7 @@ class TaxCreationForm extends BaseForm
new Constraints\Callback(
array(
"methods" => array(
array($this, "verifyRequirements"),
array($requirementType, "verifyForm"),
),
)
),
@@ -104,10 +97,10 @@ class TaxCreationForm extends BaseForm
return "thelia_tax_creation";
}
public function verifyRequirements($value, ExecutionContextInterface $context)
public function verifyForm($value, ExecutionContextInterface $context)
{
$in = true;
//$this->getForm()->getChildren()
}
}

View File

@@ -28,7 +28,7 @@ namespace Thelia\Type;
*
*/
class AlphaNumStringListType implements TypeInterface
class AlphaNumStringListType extends BaseType
{
public function getType()
{

View File

@@ -28,7 +28,7 @@ namespace Thelia\Type;
*
*/
class AlphaNumStringType implements TypeInterface
class AlphaNumStringType extends BaseType
{
public function getType()
{

View File

@@ -28,7 +28,7 @@ namespace Thelia\Type;
*
*/
class AnyType implements TypeInterface
class AnyType extends BaseType
{
public function getType()
{

View 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");
}
}
}

View File

@@ -29,7 +29,7 @@ namespace Thelia\Type;
*
*/
class BooleanOrBothType implements TypeInterface
class BooleanOrBothType extends BaseType
{
const ANY = '*';

View File

@@ -28,7 +28,7 @@ namespace Thelia\Type;
*
*/
class BooleanType implements TypeInterface
class BooleanType extends BaseType
{
public function getType()
{

View File

@@ -28,7 +28,7 @@ namespace Thelia\Type;
*
*/
class EnumListType implements TypeInterface
class EnumListType extends BaseType
{
protected $values = array();

View File

@@ -28,7 +28,7 @@ namespace Thelia\Type;
*
*/
class EnumType implements TypeInterface
class EnumType extends BaseType
{
protected $values = array();

View File

@@ -28,7 +28,7 @@ namespace Thelia\Type;
*
*/
class FloatToFloatArrayType implements TypeInterface
class FloatToFloatArrayType extends BaseType
{
public function getType()
{

View File

@@ -28,7 +28,7 @@ namespace Thelia\Type;
*
*/
class FloatType implements TypeInterface
class FloatType extends BaseType
{
public function getType()
{

View File

@@ -28,7 +28,7 @@ namespace Thelia\Type;
*
*/
class IntListType implements TypeInterface
class IntListType extends BaseType
{
public function getType()
{

View File

@@ -28,7 +28,7 @@ namespace Thelia\Type;
*
*/
class IntToCombinedIntsListType implements TypeInterface
class IntToCombinedIntsListType extends BaseType
{
public function getType()
{

View File

@@ -28,7 +28,7 @@ namespace Thelia\Type;
*
*/
class IntToCombinedStringsListType implements TypeInterface
class IntToCombinedStringsListType extends BaseType
{
public function getType()
{

View File

@@ -28,7 +28,7 @@ namespace Thelia\Type;
*
*/
class IntType implements TypeInterface
class IntType extends BaseType
{
public function getType()
{

View File

@@ -28,7 +28,7 @@ namespace Thelia\Type;
*
*/
class JsonType implements TypeInterface
class JsonType extends BaseType
{
public function getType()
{

View File

@@ -30,7 +30,7 @@ use Thelia\Exception\TypeException;
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class ModelType implements TypeInterface
class ModelType extends BaseType
{
protected $expectedModelActiveRecord = null;

View File

@@ -30,7 +30,7 @@ use Thelia\Exception\TypeException;
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class ModelValidIdType implements TypeInterface
class ModelValidIdType extends BaseType
{
protected $expectedModelActiveRecordQuery = null;

View File

@@ -22,12 +22,13 @@
/*************************************************************************************/
namespace Thelia\Type;
use Symfony\Component\Validator\ExecutionContextInterface;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
interface TypeInterface
{
public function getType();
@@ -38,4 +39,5 @@ interface TypeInterface
public function getFormType();
public function getFormOptions();
public function verifyForm($value, ExecutionContextInterface $context);
}

View File

@@ -88,7 +88,7 @@
{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}>
<label for="{$label_attr.for}" class="control-label">
{intl l=$label} :
{intl l=$label} : {$formType}
</label>
{if $formType == 'choice'}
<select name="{$name}">