{"id":2126,"date":"2020-06-08T13:07:40","date_gmt":"2020-06-08T11:07:40","guid":{"rendered":"https:\/\/www.h-hennes.fr\/blog\/?p=2126"},"modified":"2020-06-08T13:07:44","modified_gmt":"2020-06-08T11:07:44","slug":"prestashop-utilisation-avancee-des-admincontroller-les-options","status":"publish","type":"post","link":"https:\/\/www.h-hennes.fr\/blog\/2020\/06\/08\/prestashop-utilisation-avancee-des-admincontroller-les-options\/","title":{"rendered":"Prestashop : Utilisation avanc\u00e9e des AdminController &#8211; Les options"},"content":{"rendered":"\n<p>Cet article fait partie d&rsquo;une s\u00e9rie d&rsquo;articles qui pr\u00e9sentent les fonctionnalit\u00e9s avanc\u00e9es disponibles dans un controller d&rsquo;administration Prestashop. ( adminController )<br \/>Les exemples sont r\u00e9alis\u00e9s dans le cadre d\u2019un module mais s&rsquo;appliquent \u00e9galement \u00e0 tous les anciens controllers de l&rsquo;administration qui n&rsquo;utilisent <strong>pas encore l&rsquo;infrastructure symfony<\/strong><br \/>Vous pouvez-consulter les autres articles de la s\u00e9rie :<\/p>\n<ul>\n<li><a href=\"https:\/\/www.h-hennes.fr\/blog\/2020\/06\/08\/prestashop-creer-un-controller-admin-pour-un-module-presentation-des-options-avancees\/\">Pr\u00e9sentation des informations<\/a><\/li>\n<li><a title=\"Prestashop : cr\u00e9er un admin controller pour un module\" href=\"https:\/\/www.h-hennes.fr\/blog\/2018\/11\/15\/prestashop-admincontroller-pour-un-module\/\">Fonctionnement basique<\/a><\/li>\n<li><a href=\"https:\/\/www.h-hennes.fr\/blog\/2019\/01\/30\/prestashop-utilisation-avancee-admincontroller\/\">Fonctionnalit\u00e9s avanc\u00e9es g\u00e9n\u00e9rales<\/a><\/li>\n<li><a href=\"https:\/\/www.h-hennes.fr\/blog\/2020\/06\/08\/prestashop-utilisation-avancee-des-admincontroller-les-listings\/\">Fonctionnalit\u00e9s du listing<\/a><\/li>\n<li><a href=\"https:\/\/www.h-hennes.fr\/blog\/2020\/06\/08\/prestashop-utilisation-avancee-des-admincontroller-les-formulaires\/\">Fonctionnalit\u00e9 des formulaires<\/a><\/li>\n<li><a href=\"https:\/\/www.h-hennes.fr\/blog\/2020\/06\/08\/prestashop-utilisation-avancee-des-admincontroller-les-options\/\">Fonctionnalit\u00e9s des options<\/a><\/li>\n<\/ul>\n\n\n\n<p>Dans cet article nous allons \u00e0 pr\u00e9sent nous int\u00e9resser \u00e0 la gestion des options de notre controller et voir les cas suivants :<\/p>\n<ul>\n<li>Ensemble des cas d\u2019affichage d\u2019options<\/li>\n<li>Traitement sp\u00e9cifique d\u2019une option<\/li>\n<\/ul>\n\n\n\n<p>Les options sont d\u00e9finies dans la fonction __construct() du controller<br>Voici un code qui g\u00e9n\u00e8re une grande partie des cas&nbsp; avec les commentaires explicatifs de leur fonctionnement.<\/p>\n<p>Attention car les valeurs des options seront stock\u00e9es dans la table globale de configuration de Prestashop.<br>Pensez donc \u00e0 bien supprimer ces informations lors de la d\u00e9sinstallation de votre module.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Ensemble des cas d&rsquo;affichage des options<\/h3>\n\n\n\n<pre escaped=\"true\" lang=\"php\">\/**\n  * Gestion des options\n  *\/\n        $this-&gt;fields_options = [\n            \/\/Groupe d'option n 1\n            'general' =&gt; [\n                \/\/Titre du groupe d'options\n                'title' =&gt; $this-&gt;l('General configuration'),\n                \/\/Champs du group d'options\n                'fields' =&gt; [\n                    \/\/Exemple option de type texte\n                    'OPTION_KEY_TEXT' =&gt; [ \/\/La cl\u00e9 du tableau correspond au nom de la configuration\n                        'title' =&gt; $this-&gt;l('Field Text'),\n                        'hint' =&gt; $this-&gt;l('Field Text Hint'),\n                        'validation' =&gt; 'isWeightUnit', \/\/Classe de validation ( de la classe Validate )\n                        'required' =&gt; true, \/\/Champ requis ou non\n                        'type' =&gt; 'text', \/\/Type de champ\n                        'class' =&gt; 'fixed-width-sm' \/\/classe css\n                    ],\n                    \/\/Exemple option de type texte avec langue\n                    'OPTION_KEY_TEXT_LANG' =&gt; [\n                        'title' =&gt; $this-&gt;l('Field Text Lang'),\n                        'hint' =&gt; $this-&gt;l('Field Text Lang Hint'),\n                        'validation' =&gt; 'isWeightUnit',\n                        'required' =&gt; true,\n                        'type' =&gt; 'textLang', \/\/Type de champ\n                        'class' =&gt; 'fixed-width-sm'\n                    ],\n                    \/\/Exemple option de type textarea\n                    'OPTION_KEY_TEXTAREA' =&gt; [\n                        'title' =&gt; $this-&gt;l('Field Textarea'),\n                        'hint' =&gt; $this-&gt;l('Field Textarea Hint'),\n                        'required' =&gt; true,\n                        'type' =&gt; 'textarea',\n                        'cols' =&gt; 150, \/\/Champ requis Textarea\n                        'rows' =&gt; 2 \/\/ Champ requis Textarea\n                    ],\n                    \/\/Exemple option de type textarea lang\n                    'OPTION_KEY_TEXTAREA_LANG' =&gt; [\n                        'title' =&gt; $this-&gt;l('Field Textarea Lang'),\n                        'hint' =&gt; $this-&gt;l('Field Textarea Hint'),\n                        'required' =&gt; true,\n                        'type' =&gt; 'textareaLang',\n                        'cols' =&gt; 150, \/\/Champ requis Textarea\n                        'rows' =&gt; 2 \/\/ Champ requis Textarea\n                    ],\n                    \/\/Exemple option de type textarea avec TinyMce\n                    'OPTION_KEY_TEXTAREA_MCE' =&gt; [\n                        'title' =&gt; $this-&gt;l('Field Textarea editor'),\n                        'hint' =&gt; $this-&gt;l('Field Textarea editor Hint'),\n                        'required' =&gt; true,\n                        'type' =&gt; 'textarea',\n                        'autoload_rte' =&gt; true ,\/\/Flag pour afficher l'\u00e9diteur de texte\n                        'cols' =&gt; 150, \/\/Champ requis Textarea\n                        'rows' =&gt; 2 \/\/ Champ requis Textarea\n                    ],\n                    \/\/Exemple d'option de type \"select\"\n                    'OPTION_KEY_SELECT' =&gt; [\n                        'title' =&gt; $this-&gt;l('Sample select fields'),\n                        'hint' =&gt; $this-&gt;l('This is a select field.'),\n                        'cast' =&gt; 'intval', \/\/Cast appliqu\u00e9 aux valeurs\n                        'type' =&gt; 'select',\n                        'identifier' =&gt; 'id_lang', \/\/Champs requis select cl\u00e9 de l'identifiant\n                        'list' =&gt; Language::getLanguages(false) \/\/Champ requis select source des donn\u00e9es\n                    ],\n                    \/\/Exemple d'option de type boolean\n                    'OPTION_KEY_BOOLEAN' =&gt; [\n                        'title' =&gt; $this-&gt;l('Bolean Field'),\n                        'hint' =&gt; $this-&gt;l('Bolean Field Hint'),\n                        'validation' =&gt; 'isBool',\n                        'cast' =&gt; 'intval',\n                        'type' =&gt; 'bool',\n                        'default' =&gt; '1' \/\/Valeur d\u00e9faut pour l'option boolean\n                    ],\n                    \/\/Exemple d'option de type file\n                    'OPTION_KEY_FILE' =&gt; [\n                        'title' =&gt; $this-&gt;l('File Field'),\n                        'hint' =&gt; $this-&gt;l('File Field Hint'),\n                        'type' =&gt; 'file',\n                        'name' =&gt; 'OPTION_KEY_FILE' \/\/Champ requis file\n                    ],\n                    \/\/Exemple d'option de type file avec un thumb\n                    'OPTION_KEY_THUMB' =&gt; [\n                        'title' =&gt; $this-&gt;l('Thumb Field'),\n                        'hint' =&gt; $this-&gt;l('Thumb Field Hint'),\n                        'type' =&gt; 'file',\n                        'name' =&gt; 'OPTION_KEY_FILE',\n                        'thumb' =&gt; 'https:\/\/upload.wikimedia.org\/wikipedia\/commons\/e\/ee\/Thumbup.jpg' \/\/Champ requis thumb\n                    ],\n                    \/\/Exemple d'option de type color\n                    'OPTION_KEY_COLOR' =&gt; [\n                        'title' =&gt; $this-&gt;l('Color Field'),\n                        'hint' =&gt; $this-&gt;l('Color Field Hint'),\n                        'validation' =&gt; 'isColor',\n                        'type' =&gt; 'color',\n                        'name' =&gt; 'OPTION_KEY_COLOR', \/\/ Champs requis Color\n                        'size' =&gt; 7, \/\/CHamps requis Color\n                    ],\n\n                ],\n                \/\/Bouton de soumission\n                'submit' =&gt; ['title' =&gt; $this-&gt;l('Save')]\n            ],\n            \/\/Groupe d'option n'2\n            'localization' =&gt; [\n                'title' =&gt; $this-&gt;l('Option bloc 2'),\n                'icon' =&gt; 'icon-globe',\n                'fields' =&gt; [\n                    'OPTION_KEY_TEXT_2' =&gt; [\n                        'title' =&gt; $this-&gt;l('Field Text'),\n                        'hint' =&gt; $this-&gt;l('Field Text Hint'),\n                        'validation' =&gt; 'isWeightUnit',\n                        'required' =&gt; true,\n                        'type' =&gt; 'text',\n                        'class' =&gt; 'fixed-width-sm'\n                    ],\n                ],\n                'submit' =&gt; ['title' =&gt; $this-&gt;l('Save')]\n            ],\n        ];\n<\/pre>\n\n\n\n<p>Le rendu sera ensuite le suivant pour le premier bloc d&rsquo;options<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"639\" src=\"https:\/\/www.h-hennes.fr\/blog\/wp-content\/uploads\/2019\/01\/options-form-admin-1024x639.png\" alt=\"\" class=\"wp-image-1976\"\/><\/figure>\n\n\n\n<p>Et pour le second bloc d&rsquo;options<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"130\" src=\"https:\/\/www.h-hennes.fr\/blog\/wp-content\/uploads\/2019\/01\/option-form-admin2-e1558430521239.png\" alt=\"\" class=\"wp-image-1977\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Traitement sp\u00e9cifique d\u2019une option<\/h3>\n\n\n\n<p>Ce point est en cours de r\u00e9daction<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dans cet article nous allons \u00e0 pr\u00e9sent nous int\u00e9resser \u00e0 la gestion des options de notre controller et voir les cas suivants : Ensemble des cas d\u2019affichage d\u2019options Traitement sp\u00e9cifique d\u2019une option Les options sont d\u00e9finies dans la fonction __construct() du controllerVoici un code qui g\u00e9n\u00e8re une grande partie des cas&nbsp; avec les commentaires explicatifs [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[245],"tags":[537,104],"class_list":["post-2126","post","type-post","status-publish","format-standard","hentry","category-prestashop-2","tag-admin-controller","tag-prestashop"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/posts\/2126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/comments?post=2126"}],"version-history":[{"count":4,"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/posts\/2126\/revisions"}],"predecessor-version":[{"id":2139,"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/posts\/2126\/revisions\/2139"}],"wp:attachment":[{"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/media?parent=2126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/categories?post=2126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h-hennes.fr\/blog\/wp-json\/wp\/v2\/tags?post=2126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}