Started category modification

This commit is contained in:
franck
2013-09-07 10:59:43 +02:00
parent f304caa88f
commit 3bd3a4d943
11 changed files with 288 additions and 335 deletions

View File

@@ -37,6 +37,7 @@ use Thelia\Model\Lang;
use Thelia\Core\Translation\Translator;
use Thelia\Core\Event\CategoryUpdatePositionEvent;
use Thelia\Model\CategoryQuery;
use Thelia\Form\CategoryModificationForm;
class CategoryController extends BaseAdminController
{
@@ -46,13 +47,10 @@ class CategoryController extends BaseAdminController
* @return Symfony\Component\HttpFoundation\Response the response
*/
protected function renderList() {
$args = $this->setupArgs();
return $this->render('categories', $args);
return $this->render('categories', $this->getTemplateArgs());
}
protected function setupArgs() {
protected function getTemplateArgs() {
// Get the category ID
$category_id = $this->getRequest()->get('category_id', 0);
@@ -164,8 +162,14 @@ class CategoryController extends BaseAdminController
// Prepare the data that will hydrate the form
$data = array(
'id' => $category->getId(),
'name' => $category->getTitle(),
'locale' => $category->getLocale(),
'title' => $category->getTitle(),
'chapo' => $category->getChapo(),
'description' => $category->getDescription(),
'postscriptum' => $category->getPostscriptum(),
'parent' => $category->getParent(),
'visible' => $category->getVisible() ? true : false,
'url' => $category->getUrl($this->getCurrentEditionLocale())
// tbc !!!
);
@@ -177,7 +181,7 @@ class CategoryController extends BaseAdminController
}
// Render the edition template.
return $this->render('category-edit', array('category_id' => $this->getRequest()->get('category_id')));
return $this->render('category-edit', $this->getTemplateArgs());
}
/**

View File

@@ -126,7 +126,7 @@ class AsseticHelper
//
// before generating 3bc974a-ad3ef47.css, delete 3bc974a-* files.
//
if (/*$dev_mode == true || */! file_exists($target_file)) {
if ($dev_mode == true || ! file_exists($target_file)) {
// Delete previous version of the file
list($commonPart, $dummy) = explode('-', $asset_target_path);

View File

@@ -23,51 +23,33 @@
namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Model\LangQuery;
use Propel\Runtime\ActiveQuery\Criteria;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Thelia\Core\Translation\Translator;
/**
* A base form for all objects with standard contents.
*
* @author Franck Allimant <franck@cqfdev.fr>
*/
abstract class BaseDescForm extends BaseForm
class CategoryModificationForm extends CategoryCreationForm
{
use StandardDescriptionFieldsTrait;
protected function buildForm()
{
parent::buildForm(true);
$this->formBuilder
->add("locale", "hidden", array(
"constraints" => array(
new NotBlank()
)
)
)
->add("title", "text", array(
"constraints" => array(
new NotBlank()
),
"label" => "Title",
"label_attr" => array(
"for" => "title"
)
)
)
->add("chapo", "text", array(
"label" => "Summary",
"label_attr" => array(
"for" => "summary"
)
))
->add("description", "text", array(
"label" => "Detailed description",
"label_attr" => array(
"for" => "detailed_description"
)
))
->add("postscriptum", "text", array(
"label" => "Conclusion",
"label_attr" => array(
"for" => "conclusion"
)
->add("id", "hidden", array("constraints" => array(new GreaterThan(array('value' => 0)))))
->add("visible", "checkbox", array(
"label" => Translator::getInstance()->trans("This category is online on the front office.")
))
;
}
// Add standard description fields
$this->addStandardDescFields(array('title', 'locale'));
}
public function getName()
{
return "thelia_category_modification";
}
}

View File

@@ -27,12 +27,12 @@ use Thelia\Model\LangQuery;
use Propel\Runtime\ActiveQuery\Criteria;
use Symfony\Component\Validator\Constraints\GreaterThan;
class ConfigModificationForm extends BaseDescForm
class ConfigModificationForm extends BaseForm
{
use StandardDescriptionFieldsTrait;
protected function buildForm()
{
parent::buildForm(true);
$this->formBuilder
->add("id", "hidden", array(
"constraints" => array(
@@ -61,6 +61,9 @@ class ConfigModificationForm extends BaseDescForm
"label" => "Prevent variable modification or deletion, except for super-admin"
))
;
// Add standard description fields
$this->addStandardDescFields();
}
public function getName()

View File

@@ -24,35 +24,69 @@ namespace Thelia\Form;
use Symfony\Component\Validator\Constraints\NotBlank;
use Thelia\Core\Translation\Translator;
/**
* This form defines all standard description fields:
* - title
* - chapo
* - description
* - postscriptum
* A trait to add standard localized description fields to a form.
*
* @author Franck Allimant <franck@cqfdev.fr>
*/
Trait StandardDescriptionFieldsTrait
trait StandardDescriptionFieldsTrait
{
protected function addStandardDescriptionFields()
/**
* Add standard description fields + locale tot the form
*
* @param array $exclude name of the fields that should not be added to the form
*/
protected function addStandardDescFields($exclude = array())
{
$this->formBuilder
->add("locale", "hidden", array(
if (! in_array('locale', $exclude))
$this->formBuilder
->add("locale", "hidden", array(
"constraints" => array(
new NotBlank()
)
)
);
if (! in_array('title', $exclude))
$this->formBuilder
->add("title", "text", array(
"constraints" => array(
new NotBlank()
),
"label" => Translator::getInstance()->trans("Title"),
"label_attr" => array(
"for" => "title"
)
)
)
->add("title", "text", array(
"constraints" => array(
new NotBlank()
);
if (! in_array('chapo', $exclude))
$this->formBuilder
->add("chapo", "text", array(
"label" => Translator::getInstance()->trans("Summary"),
"label_attr" => array(
"for" => "summary"
)
)
)
->add("chapo", "text", array())
->add("description", "text", array())
->add("postscriptum", "text", array())
;
));
if (! in_array('description', $exclude))
$this->formBuilder
->add("description", "text", array(
"label" => Translator::getInstance()->trans("Detailed description"),
"label_attr" => array(
"for" => "detailed_description"
)
));
if (! in_array('postscriptum', $exclude))
$this->formBuilder
->add("postscriptum", "text", array(
"label" => Translator::getInstance()->trans("Conclusion"),
"label_attr" => array(
"for" => "conclusion"
)
));
}
}