diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php index 47fb45d8d..0a8fe68e2 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/AdminUtilities.php @@ -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'), ); } } diff --git a/core/lib/Thelia/Form/SeoFieldsTrait.php b/core/lib/Thelia/Form/SeoFieldsTrait.php index cb64ad6c0..91ee54f0d 100644 --- a/core/lib/Thelia/Form/SeoFieldsTrait.php +++ b/core/lib/Thelia/Form/SeoFieldsTrait.php @@ -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 ) diff --git a/core/lib/Thelia/Form/StandardDescriptionFieldsTrait.php b/core/lib/Thelia/Form/StandardDescriptionFieldsTrait.php index e050cce1f..ba3beca2b 100644 --- a/core/lib/Thelia/Form/StandardDescriptionFieldsTrait.php +++ b/core/lib/Thelia/Form/StandardDescriptionFieldsTrait.php @@ -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.') + ] + ] + ); + } } diff --git a/templates/backOffice/default/document-edit.html b/templates/backOffice/default/document-edit.html index 7d7e12cf8..c95c2daf2 100644 --- a/templates/backOffice/default/document-edit.html +++ b/templates/backOffice/default/document-edit.html @@ -40,13 +40,8 @@ {form_hidden_fields form=$form} - {form_field form=$form field='success_url'} - - {/form_field} - - {form_field form=$form field='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}
{$form_error_message}
{/if} @@ -62,43 +57,15 @@
- {form_field form=$form field='file'} -
- - -
- {/form_field} - - {form_field form=$form field='title'} -
- - -
- {/form_field} - - {form_field form=$form field='chapo'} -
- - -
- {/form_field} - - {form_field form=$form field='postscriptum'} -
- - -
- {/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}
- {form_field form=$form field='description'} -
- - -
- {/form_field} + {admin_form_field form=$form name="description" value=$DESCRIPTION extra_class="wysiwyg"}
diff --git a/templates/backOffice/default/forms/form-field.html b/templates/backOffice/default/forms/form-field.html new file mode 100644 index 000000000..48bd40471 --- /dev/null +++ b/templates/backOffice/default/forms/form-field.html @@ -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'} + +{elseif $type == 'checkbox'} + +
+ +
+ +{else} + +
+ + {admin_form_field_label form=$form name=$field_name label_attr=$label_attr} + + {if $multiple} + {intl l='Use Ctrl+click to select (or deselect) more that one item'} + {/if} + + {$lang_code = 0} + {if $label_attr.i18n == 'default'} + {loop type="lang" name="default-lang" default_only="1"} + {$lang_code = $CODE} + {$lang_title = $TITLE} +
+ {/loop} + {/if} + + {if $type == 'choice'} + + + {elseif $type == 'textarea'} + + + + {elseif $type == 'money'} + +
+ + {loop name="input.addon" type="currency" default_only="true"}{$SYMBOL}{/loop} +
+ + {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} + + + + {else} +
{intl l="Unsupported field type '%type' in form-field.html" type=$type}
+ {/if} + {/if} + + {if $lang_code} + {$lang_title} +
+ {/if} + + {if ! empty($label_attr.help)} + {$label_attr.help} + {/if} +
+{/if} +{/form_field} diff --git a/templates/backOffice/default/forms/form-label.html b/templates/backOffice/default/forms/form-label.html new file mode 100644 index 000000000..ce2af2a58 --- /dev/null +++ b/templates/backOffice/default/forms/form-label.html @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/templates/backOffice/default/image-edit.html b/templates/backOffice/default/image-edit.html index 464e3a9ad..4a97112e2 100644 --- a/templates/backOffice/default/image-edit.html +++ b/templates/backOffice/default/image-edit.html @@ -40,13 +40,8 @@ {form_hidden_fields form=$form} - {form_field form=$form field='success_url'} - - {/form_field} - - {form_field form=$form field='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}
{$form_error_message}
{/if} @@ -65,43 +60,15 @@
- {form_field form=$form field='file'} -
- - -
- {/form_field} - - {form_field form=$form field='title'} -
- - -
- {/form_field} - - {form_field form=$form field='chapo'} -
- - -
- {/form_field} - - {form_field form=$form field='postscriptum'} -
- - -
- {/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}
- {form_field form=$form field='description'} -
- - -
- {/form_field} + {admin_form_field form=$form name="description" value=$DESCRIPTION extra_class="wysiwyg"}
@@ -113,8 +80,6 @@ page_url = "{url path="/admin/image/type/{$imageType}/{$ID}/update"}" close_url = "{url path="{$redirectUrl}"}" } - - {/form} diff --git a/templates/backOffice/default/includes/seo-tab.html b/templates/backOffice/default/includes/seo-tab.html index 17d64575c..490078132 100644 --- a/templates/backOffice/default/includes/seo-tab.html +++ b/templates/backOffice/default/includes/seo-tab.html @@ -16,59 +16,26 @@ {form_hidden_fields form=$form} - {form_field form=$form field='success_url'} - - {/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'}
- + + {admin_form_field_label form=$form name='url'} +
- {$url_language|default:{config key="url_site"}} - + {$url_language|default:{config key="url_site"}}/ +
{/form_field} - - {form_field form=$form field='meta_title'} -
- -
- -
-
- {/form_field} - - {form_field form=$form field='meta_description'} -
- - - -
- {/form_field} - - {form_field form=$form field='meta_keywords'} -
- - - -
- {/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" diff --git a/templates/backOffice/default/includes/standard-description-form-fields.html b/templates/backOffice/default/includes/standard-description-form-fields.html index 26f262893..2072d83df 100644 --- a/templates/backOffice/default/includes/standard-description-form-fields.html +++ b/templates/backOffice/default/includes/standard-description-form-fields.html @@ -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'} -
- - -
-{/form_field} - -{form_field form=$form field='chapo'} -
- - - -
-{/form_field} - -{form_field form=$form field='description'} -
- - - -
-{/form_field} - -{form_field form=$form field='postscriptum'} -
- - - -
-{/form_field} \ No newline at end of file +{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"} \ No newline at end of file