Child pages
  • Adapter votre module à Bootstrap

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Code Block
languagephp
public function renderForm()
{
	$fields_form = array(
		'form' => array(
			'legend' => array(
				'title' => $this->l('Settings'),
				'icon' => 'icon-cogs'
			),
			'input' => array(
				array(
					'type' => 'switch',
					'label' => $this->l('Ajax cart'),
					'name' => 'PS_BLOCK_CART_AJAX',
					'is_bool' => true,
					'desc' => $this->l('Activate AJAX mode for cart (compatible with the default theme)'),
					'values' => array(
						array(
							'id' => 'active_on',
							'value' => 1,
							'label' => $this->l('Enabled')
						),
						array(
							'id' => 'active_off',
							'value' => 0,
							'label' => $this->l('Disabled')
						)
					),
				)
			),
		'submit' => array(
			'title' => $this->l('Save'),
			'class' => 'btn btn-primarydefault pull-right')
		),
	);
	
	$helper = new HelperForm();
	$helper->show_toolbar = false;
	$helper->table = $this->table;
	$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
	$helper->default_form_language = $lang->id;
	$helper->allow_employee_form_lang = 
        Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
	$this->fields_form = array();

	$helper->identifier = $this->identifier;
	$helper->submit_action = 'submitBlockCart';
	$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
       .'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
	$helper->token = Tools::getAdminTokenLite('AdminModules');
	$helper->tpl_vars = array(
		'fields_value' => $this->getConfigFieldsValues(),
		'languages' => $this->context->controller->getLanguages(),
		'id_language' => $this->context->language->id
	);

	return $helper->generateForm(array($fields_form));
}		

Détails importants

La variable 'bootstrap'

Une dernière chose à laquelle faire attention : si votre module utilise un contrôleur bootstrappé, vous devez ajouter la variable bootstrap à la méthode constructeur du module.

...

Code Block
public function __construct()
{
	$this->bootstrap = true;
	$this->display = 'view';
	$this->meta_title = $this->l('Your Merchant Expertise');
	parent::__construct();
	if (!$this->module->active)
		Tools::redirectAdmin($this->context->link->getAdminLink('AdminHome'));
}

Cette ligne DOIT être placée dans la méthode __construct() de votre module – si vous utilisez des contrôleurs bootstrappés.

Si vous n'utilisez pas de contrôleurs bootstrappés, alors PrestaShop l'entourera d'une classe spécifique, qui fera de son mieux pour gérer le contrôleur de la meilleure manière possible, et ainsi assurer une certaine rétrocompatibilité.

Taille de champs textuels

Si vous souhaitez choisir la largeur de vos champs textuels, vous n'avez qu'à ajouter une classe à la balise input, directement le tableau décrit dans votre HelperForm.

Par exemple :

Code Block
array (
	'type' => 'text',
	'label' => $this->l('Field name'),
	'name' => 'field_name',
	'class' => 'fixed-width-xs',       // Add this line.
	'required' => true
),

Dans cet exemple, nous utilisons "xs" comme largeur du champ.

Il a plusieurs tailles que vous pouvez utiliser :

  • xs : très petite (extra small).
  • sm : petite (small).
  • md : moyenne (medium).
  • lg : grande (large).
  • xl : très grande (extra large).
  • xxl : très très grande (extra extra large).