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.')
]
]
);
}
}

View File

@@ -40,13 +40,8 @@
{form_hidden_fields form=$form}
{form_field form=$form field='success_url'}
<input type="hidden" name="{$name}" value="{url path="/admin/document/type/{$documentType}/{$ID}/update"}" />
{/form_field}
{form_field form=$form field='locale'}
<input type="hidden" name="{$name}" value="{$edit_language_locale}" />
{/form_field}
{admin_form_field form=$form name="success_url" value="{url path="/admin/document/type/{$documentType}/{$ID}/update"}"}
{admin_form_field form=$form name="locale" value="$edit_language_locale"}
{if $form_error}<div class="alert alert-danger">{$form_error_message}</div>{/if}
@@ -62,43 +57,15 @@
</div>
<div class="col-md-6">
{form_field form=$form field='file'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<input type="file" id="{$label_attr.for}" name="{$name}" value="" title="{$label}" placeholder="{intl l='File'}">
</div>
{/form_field}
{form_field form=$form field='title'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$TITLE}" title="{$label}" placeholder="{intl l='Title'}">
</div>
{/form_field}
{form_field form=$form field='chapo'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<textarea id="{$label_attr.for}" name="{$name}" class="form-control" title="{$label}" placeholder="{intl l='Chapo'}">{$CHAPO}</textarea>
</div>
{/form_field}
{form_field form=$form field='postscriptum'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<textarea id="{$label_attr.for}" name="{$name}" class="form-control" title="{$label}" placeholder="{intl l='Post Scriptum'}">{$POSTSCRIPTUM}</textarea>
</div>
{/form_field}
{admin_form_field form=$form name="file"}
{admin_form_field form=$form name="title" value=$TITLE}
{admin_form_field form=$form name="chapo" value=$CHAPO}
{admin_form_field form=$form name="postscriptum" value=$POSTSCRIPTUM}
</div>
</div>
<div class="row">
<div class="col-md-12">
{form_field form=$form field='description'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<textarea id="{$label_attr.for}" name="{$name}" class="form-control wysiwyg" title="{$label}" placeholder="{intl l='Description'}">{$DESCRIPTION}</textarea>
</div>
{/form_field}
{admin_form_field form=$form name="description" value=$DESCRIPTION extra_class="wysiwyg"}
</div>
</div>

View File

@@ -0,0 +1,90 @@
{form_field form=$form field=$field_name}
{* Use the optionnal $field_value parameter if no value is defined *}
{if empty($value)}
{$value = $field_value}
{/if}
{* Synthetize an ID if none was given *}
{if empty({$label_attr.for})}
{$label_attr.for = "id-{$field_name}"}
{/if}
{if $type == 'hidden'}
<input type="hidden" id="{$label_attr.for}" name="{$name}" value="{$value}" />
{elseif $type == 'checkbox'}
<div class="checkbox {if $error}has-error{/if}">
<label>
<input class="{$field_extra_class}" type="checkbox" id="{$label_attr.for}" name="{$name}" value="{$value}" {if $checked}checked="checked"{/if}>
{$label} {if $required} <span class="required">*</span>{/if}
{form_error form=$form field=$field_name}
<br />
<span class="error">{$message}</span>
{/form_error}
</label>
</div>
{else}
<div class="form-group {if $error}has-error{/if}">
{admin_form_field_label form=$form name=$field_name label_attr=$label_attr}
{if $multiple}
<span class="label-help-block">{intl l='Use Ctrl+click to select (or deselect) more that one item'}</span>
{/if}
{$lang_code = 0}
{if $label_attr.i18n == 'default'}
{loop type="lang" name="default-lang" default_only="1"}
{$lang_code = $CODE}
{$lang_title = $TITLE}
<div class="input-group">
{/loop}
{/if}
{if $type == 'choice'}
<select {if $multiple}multiple{/if} {if $label_attr.size}size="{$label_attr.size}"{/if} {if $required}aria-required="true" required{/if} id="{$label_attr.for}" name="{$name}"class="form-control {$field_extra_class}">
{foreach $choices as $choice}
<option value="{$choice->value}" {if (is_array($value) && in_array($choice->value, $value)) || $choice->value == $value}selected="selected"{/if}>{$choice->label}
{/foreach}
</select>
{elseif $type == 'textarea'}
<textarea {if $label_attr.rows}rows="{$label_attr.rows}"{/if} {if $required}aria-required="true" required{/if} placeholder="{$label_attr.placeholder|default:$label}" id="{$label_attr.for}" name="{$name}" class="form-control {$field_extra_class}" title="{$label}">{$value}</textarea>
{elseif $type == 'money'}
<div class="input-group">
<input type="number" {if $required}aria-required="true" required{/if} placeholder="{$label_attr.placeholder|default:$label}" id="{$label_attr.for}" name="{$name}" value="{$value}" class="form-control {$field_extra_class}" />
<span class="input-group-addon">{loop name="input.addon" type="currency" default_only="true"}{$SYMBOL}{/loop}</span>
</div>
{else}
{$text_types = ['text', 'password', 'number', 'money', 'integer', 'time', 'date', 'datetime', 'email', 'url', 'file']}
{if in_array($type, $text_types)}
{if $type == 'integer' || $type == 'money'}{$type='number'}{/if}
<input type="{$type}" {if $required}aria-required="true" required{/if} placeholder="{$label_attr.placeholder|default:$label}" id="{$label_attr.for}" name="{$name}" value="{$value}" class="form-control {$field_extra_class}" />
{else}
<div class="alert alert-danger">{intl l="Unsupported field type '%type' in form-field.html" type=$type}</div>
{/if}
{/if}
{if $lang_code}
<span class="input-group-addon"><img src="{image file="assets/img/flags/{$lang_code}.png"}" alt="{$lang_title}" /></span>
</div>
{/if}
{if ! empty($label_attr.help)}
<span class="help-block">{$label_attr.help}</span>
{/if}
</div>
{/if}
{/form_field}

View File

@@ -0,0 +1,8 @@
<label for="{$label_attr.for}" class="control-label">
{$label} {if $required} <span class="required">*</span>{/if}
{form_error form=$form field=$field_name}
<br />
<span class="error">{$message}</span>
{/form_error}
</label>

View File

@@ -40,13 +40,8 @@
{form_hidden_fields form=$form}
{form_field form=$form field='success_url'}
<input type="hidden" name="{$name}" value="{url path="/admin/image/type/{$imageType}/{$ID}/update"}" />
{/form_field}
{form_field form=$form field='locale'}
<input type="hidden" name="{$name}" value="{$edit_language_locale}" />
{/form_field}
{admin_form_field form=$form name="success_url" value="{url path="/admin/image/type/{$imageType}/{$ID}/update"}"}
{admin_form_field form=$form name="locale" value="$edit_language_locale"}
{if $form_error}<div class="alert alert-danger">{$form_error_message}</div>{/if}
@@ -65,43 +60,15 @@
</div>
<div class="col-md-6">
{form_field form=$form field='file'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<input type="file" id="{$label_attr.for}" name="{$name}" value="" title="{$label}" placeholder="{intl l='File'}">
</div>
{/form_field}
{form_field form=$form field='title'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$TITLE}" title="{$label}" placeholder="{intl l='Title'}">
</div>
{/form_field}
{form_field form=$form field='chapo'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<textarea id="{$label_attr.for}" name="{$name}" class="form-control" title="{$label}" placeholder="{intl l='Chapo'}">{$CHAPO}</textarea>
</div>
{/form_field}
{form_field form=$form field='postscriptum'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<textarea id="{$label_attr.for}" name="{$name}" class="form-control" title="{$label}" placeholder="{intl l='Post Scriptum'}">{$POSTSCRIPTUM}</textarea>
</div>
{/form_field}
{admin_form_field form=$form name="file"}
{admin_form_field form=$form name="title" value=$TITLE}
{admin_form_field form=$form name="chapo" value=$CHAPO}
{admin_form_field form=$form name="postscriptum" value=$POSTSCRIPTUM}
</div>
</div>
<div class="row">
<div class="col-md-12">
{form_field form=$form field='description'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<textarea id="{$label_attr.for}" name="{$name}" class="form-control wysiwyg" title="{$label}" placeholder="{intl l='Description'}">{$DESCRIPTION}</textarea>
</div>
{/form_field}
{admin_form_field form=$form name="description" value=$DESCRIPTION extra_class="wysiwyg"}
</div>
</div>
@@ -113,8 +80,6 @@
page_url = "{url path="/admin/image/type/{$imageType}/{$ID}/update"}"
close_url = "{url path="{$redirectUrl}"}"
}
</form>
{/form}

View File

@@ -16,59 +16,26 @@
{form_hidden_fields form=$form}
{form_field form=$form field='success_url'}
<input type="hidden" name="{$name}" value="{$closeUrl}">
{/form_field}
{admin_form_field form=$form name="success_url"}
{* Display error message if exist *}
{include file='includes/notifications.html' message=$form_error_message}
{form_field form=$form field='url'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">
{$label} :{if $required} <span class="required">*</span>{/if}
</label>
{admin_form_field_label form=$form name='url'}
<div class="input-group">
<span class="input-group-addon">{$url_language|default:{config key="url_site"}}</span>
<input type="text" id="{$label_attr.for}" name="{$name}" value="{$value}" title="{intl l='Rewritten URL'}" {if $required} aria-required="true" required{/if} class="form-control" placeholder="{intl l='Use the keyword phrase in your URL.'}">
<span class="input-group-addon">{$url_language|default:{config key="url_site"}}/</span>
<input type="text" id="{$label_attr.for}" name="{$name}" value="{$value}" title="{$label}" {if $required} aria-required="true" required{/if} class="form-control" placeholder="{$label_attr.placeholder}">
</div>
</div>
{/form_field}
{form_field form=$form field='meta_title'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">
{$label} :{if $required} <span class="required">*</span>{/if}
<span class="label-help-block">{intl l='The HTML TITLE element is the most important element on your web page.'}</span>
</label>
<div class="control-input">
<input type="text" id="{$label_attr.for}" name="{$name}" class="form-control" value="{$value}"{if $required} aria-required="true" required{/if} title="{$label}" placeholder="{intl l='Make sure that your title is clear, and contains many of the keywords within the page itself.'}">
</div>
</div>
{/form_field}
{form_field form=$form field='meta_description'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">
{$label} :{if $required} <span class="required">*</span>{/if}
<span class="label-help-block">{intl l='Keep the most important part of your description in the first 150-160 characters.'}</span>
</label>
<textarea name="{$name}" id="{$label_attr.for}" rows="6"{if $required} aria-required="true" required{/if} placeholder="{intl l='Make sure it uses keywords found within the page itself.'}" class="form-control">{$value}</textarea>
</div>
{/form_field}
{form_field form=$form field='meta_keywords'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">
{$label} :{if $required} <span class="required">*</span>{/if}
<span class="label-help-block">{intl l='You don\'t need to use commas or other punctuations.'}</span>
</label>
<textarea name="{$name}" id="{$label_attr.for}" rows="3"{if $required} aria-required="true" required{/if} placeholder="{intl l='Don\'t repeat keywords over and over in a row. Rather, put in keyword phrases.'}" class="form-control">{$value}</textarea>
</div>
{/form_field}
{admin_form_field form=$form name="meta_title"}
{admin_form_field form=$form name="meta_description"}
{admin_form_field form=$form name="meta_keywords"}
{include
file = "includes/inner-form-toolbar.html"

View File

@@ -1,43 +1,6 @@
{*
The standard description fields, used by many Thelia objects
*}
{* The standard description fields, used by many Thelia objects *}
{form_field form=$form field='title'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">{$label} : </label>
<input type="text" id="{$label_attr.for}" name="{$name}" required="required" title="{intl l='Title'}" placeholder="{intl l='Title'}" class="form-control" value="{$value}">
</div>
{/form_field}
{form_field form=$form field='chapo'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">
{$label} :
<span class="label-help-block">{intl l="A short description, used when a summary or an introduction is required"}</span>
</label>
<textarea name="{$name}" id="{$label_attr.for}" rows="3" title="{intl l='Short description'}" placeholder="{intl l='Short description'}" class="form-control">{$value}</textarea>
</div>
{/form_field}
{form_field form=$form field='description'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">
{$label} :
<span class="label-help-block">{intl l="The detailed description."}</span>
</label>
<textarea name="{$name}" id="{$label_attr.for}" rows="10" class="form-control wysiwyg">{$value}</textarea>
</div>
{/form_field}
{form_field form=$form field='postscriptum'}
<div class="form-group {if $error}has-error{/if}">
<label for="{$label_attr.for}" class="control-label">
{$label} :
<span class="label-help-block">{intl l="A short post-description information"}</span>
</label>
<textarea name="{$name}" id="{$label_attr.for}" rows="3" title="{intl l='Short conclusion'}" placeholder="{intl l='Short conclusion'}" class="form-control">{$value}</textarea>
</div>
{/form_field}
{admin_form_field form=$form name='title'}
{admin_form_field form=$form name="chapo"}
{admin_form_field form=$form name="description" extra_class="wysiwyg"}
{admin_form_field form=$form name="postscriptum"}