Introduced the automatic form fields binding.

This commit is contained in:
Franck Allimant
2014-06-26 10:41:26 +02:00
parent 114a55c1e8
commit ce3ed19b67
9 changed files with 238 additions and 212 deletions

View File

@@ -142,6 +142,34 @@ class AdminUtilities extends AbstractSmartyPlugin
));
}
public function buildFormField($params, &$smarty)
{
$form = $this->getParam($params, 'form', false);
$field_name = $this->getParam($params, 'name', false);
$field_extra_class = $this->getParam($params, 'extra_class', '');
$field_value = $this->getParam($params, 'value', '');
return $this->fetchSnippet($smarty, 'forms'.DS.'form-field', array(
'form' => $form,
'field_name' => $field_name,
'field_extra_class' => $field_extra_class,
'field_value' => $field_value
));
}
public function buildFormFieldLabel($params, &$smarty)
{
$form = $this->getParam($params, 'form', false);
$field_name = $this->getParam($params, 'name', false);
$label_attr = $this->getParam($params, 'label_attr', array());
return $this->fetchSnippet($smarty, 'forms'.DS.'form-label', array(
'form' => $form,
'field_name' => $field_name,
'label_attr' => $label_attr
));
}
/**
* Define the various smarty plugins handled by this class
*
@@ -150,8 +178,10 @@ class AdminUtilities extends AbstractSmartyPlugin
public function getPluginDescriptors()
{
return array(
new SmartyPluginDescriptor('function', 'admin_sortable_header', $this, 'generateSortableColumnHeader'),
new SmartyPluginDescriptor('function', 'admin_position_block' , $this, 'generatePositionChangeBlock'),
new SmartyPluginDescriptor('function', 'admin_sortable_header' , $this, 'generateSortableColumnHeader'),
new SmartyPluginDescriptor('function', 'admin_position_block' , $this, 'generatePositionChangeBlock'),
new SmartyPluginDescriptor('function', 'admin_form_field' , $this, 'buildFormField'),
new SmartyPluginDescriptor('function', 'admin_form_field_label' , $this, 'buildFormFieldLabel'),
);
}
}

View File

@@ -28,13 +28,13 @@ trait SeoFieldsTrait
*/
protected function addSeoFields($exclude = array())
{
if (! in_array('url', $exclude))
$this->formBuilder
->add('url', 'text', array(
'label' => Translator::getInstance()->trans('Rewriten URL'),
'label_attr' => array(
'for' => 'rewriten_url_field'
'for' => 'rewriten_url_field',
'placeholder' => Translator::getInstance()->trans('Use the keyword phrase in your URL.')
),
'required' => false
)
@@ -45,7 +45,9 @@ trait SeoFieldsTrait
->add('meta_title', 'text', array(
'label' => Translator::getInstance()->trans('Page Title'),
'label_attr' => array(
'for' => 'meta_title'
'for' => 'meta_title',
'placeholder' => Translator::getInstance()->trans('Make sure that your title is clear, and contains many of the keywords within the page itself.'),
'help' => Translator::getInstance()->trans('The HTML TITLE element is the most important element on your web page.')
),
'required' => false
)
@@ -53,10 +55,13 @@ trait SeoFieldsTrait
if (! in_array('meta_description', $exclude))
$this->formBuilder
->add('meta_description', 'text', array(
->add('meta_description', 'textarea', array(
'label' => Translator::getInstance()->trans('Meta Description'),
'label_attr' => array(
'for' => 'meta_description'
'for' => 'meta_description',
'rows' => 6,
'placeholder' => Translator::getInstance()->trans('Make sure it uses keywords found within the page itself.'),
'help' => Translator::getInstance()->trans('Keep the most important part of your description in the first 150-160 characters.')
),
'required' => false
)
@@ -64,10 +69,13 @@ trait SeoFieldsTrait
if (! in_array('meta_keywords', $exclude))
$this->formBuilder
->add('meta_keywords', 'text', array(
->add('meta_keywords', 'textarea', array(
'label' => Translator::getInstance()->trans('Meta Keywords'),
'label_attr' => array(
'for' => 'meta_keywords'
'for' => 'meta_keywords',
'rows' => 3,
'placeholder' => Translator::getInstance()->trans('Don\'t repeat keywords over and over in a row. Rather, put in keyword phrases.'),
'help' => Translator::getInstance()->trans('You don\'t need to use commas or other punctuations.')
),
'required' => false
)

View File

@@ -31,50 +31,78 @@ trait StandardDescriptionFieldsTrait
protected function addStandardDescFields($exclude = array())
{
if (! in_array('locale', $exclude))
$this->formBuilder
->add("locale", "hidden", array(
"constraints" => array(
new NotBlank()
)
)
);
$this->formBuilder->add(
'locale',
'hidden',
[
'constraints' => [ new NotBlank() ],
'required' => true,
]
);
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_field")
)
$this->formBuilder->add(
'title',
'text',
[
'constraints' => [ new NotBlank() ],
'required' => true,
'label' => Translator::getInstance()->trans('Title'),
'label_attr' => [
'for' => 'title_field',
'placeholder' => Translator::getInstance()->trans('A descriptive title')
]
]
);
if (! in_array('chapo', $exclude))
$this->formBuilder
->add("chapo", "text", array(
"label" => Translator::getInstance()->trans("Summary"),
"label_attr" => array(
"for" => "summary_field"
)
));
$this->formBuilder->add(
'chapo',
'textarea',
[
'constraints' => [ ],
'required' => false,
'label' => Translator::getInstance()->trans('Summary'),
'label_attr' => [
'for' => 'summary_field',
'rows' => 3,
'placeholder' => Translator::getInstance()->trans('Short description text'),
'help' => Translator::getInstance()->trans('A short description, used when a summary or an introduction is required')
]
]
);
if (! in_array('description', $exclude))
$this->formBuilder
->add("description", "text", array(
"label" => Translator::getInstance()->trans("Detailed description"),
"label_attr" => array(
"for" => "detailed_description_field"
)
));
$this->formBuilder->add(
'description',
'textarea',
[
'constraints' => [ ],
'required' => false,
'label' => Translator::getInstance()->trans('Detailed description'),
'label_attr' => [
'for' => 'detailed_description_field',
'rows' => 10,
'help' => Translator::getInstance()->trans('The detailed description.')
]
]
);
if (! in_array('postscriptum', $exclude))
$this->formBuilder
->add("postscriptum", "text", array(
"label" => Translator::getInstance()->trans("Conclusion"),
"label_attr" => array(
"for" => "conclusion_field"
)
));
}
$this->formBuilder->add(
'postscriptum',
'textarea',
[
'constraints' => [ ],
'required' => false,
'label' => Translator::getInstance()->trans('Conclusion'),
'label_attr' => [
'for' => 'conclusion_field',
'rows' => 3,
'placeholder' => Translator::getInstance()->trans('Short additional text'),
'help' => Translator::getInstance()->trans('A short text, used when an additional or supplemental information is required.')
]
]
);
}
}