Jump to content
Webotool

Comment lier un CSS à un module maison ?

Recommended Posts

Bonjour,

 

Je suis entrain de suivre le « Debeloper Guide » sur la création de module mais je n’arrive pas à lier de CSS.

 

A l’étape « Displaying content on the front office » apres avoir créé template et un css, j’ajoute une méthode hookDisplayHeader mais rien n’y fait… Help

 

Voici la structure des fichiers

 

Le code

class BelgaModule extends Module
{
    public function __construct()
    {
        $this->name         = 'belgamodule';   // technical name
        $this->tab          = 'front_office_features';
        $this->version      = '0.1';
        $this->author       = "BELGA Dam'z";

        parent::__construct();

        $this->displayName  = $this->l('Belga Module');  // public name
        $this->description  = $this->l('Premier module de laboratoire.');

        $this->confirmUninstall = $this->l('Are you sure you want to uninstal?');

        if (!Configuration::get('MYMODULE_NAME'))
            $this->warning = $this->l('No name provide.');
    }


    public function install()
    {
        if (Shop::isFeatureActive())
            Shop::setContext(Shop::CONTEXT_ALL);

        return parent::install() &&
            $this->registerHook('hookDisplayHeader') &&
            $this->registerHook('leftColumn') &&
            $this->registerHook('header') &&
            Configuration::updateValue('MYMODULE_NAME', 'BelgaWeb Module');
    }

    public function uninstall()
    {
        if (!parent::uninstall() || !Configuration::deleteByName('MYMODULE_NAME'))
            return false;
        return true;
    }


    public function hookDisplayLeftColumn($params)
    {
        $this->context->smarty->assign(
            array(
                'my_module_name' => Configuration::get('MYMODULE_NAME'),
                'my_module_link' => $this->context->link->getModuleLink('belgamodule', 'display')
            )
        );
        return $this->display(__FILE__, 'belgamodule.tpl');
    }

    public function hookDisplayRightColumn($params)
    {
        return $this->hookDisplayLeftColumn($params);
    }

    public function hookDisplayHeader()
    {
        $this->context->controller->addCSS($this->_path.'css/belgamodule.css', 'all');
    }

    public function getContent()
    {
       $output = null;

       if (Tools::isSubmit('submit'.$this->name))
       {
           $module_name = strval(Tools::getValue('MYMODULE_NAME'));
           if (!$module_name || empty($module_name) || !Validate::isGenericName($module_name))
           {
               $output .= $this->displayError($this->l('Invalid Configuration value'));
           }
           else
           {
               Configuration::updateValue('MYMODULE_NAME', $module_name);
               $output .= $this->displayConfirmation($this->l('Settings updated'));
           }
       }
       return $output.$this->displayForm();
    }
    public function displayForm()
    {
        // Get default language
        $default_lang = (int)Configuration::get('PS_LANG_DEFAULT');

        // Init Fields form array
        $fields_form[0]['form'] = array(
                                     'legend' => array('title' => $this->l('Settings'),
                                     ),
                                     'input' => array(
                                         array(
                                             'type'  => 'text',
                                             'label' => $this->l('Configuration value'),
                                             'name'  => 'MYMODULE_NAME',
                                             'size'  => 20,
                                             'required' => true
                                         )
                                     ),
                                     'submit' => array(
                                         'title' => $this->l('Save'),
                                         'class' => 'btn btn-default pull-right'
                                     )
                                  );

        $helper = new HelperForm();

        // Module, token and currentIndex
        $helper->module = $this; //requires the instance of the module that will use the form
        $helper->name_controller = $this->name; // reuires the name of the module
        $helper->token = Tools::getAdminTokenLite('AdminModules'); // requires a unique token for the module
        $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;

        // Language
        $helper->default_form_language = $default_lang;
        $helper->allow_employee_form_lang = $default_lang;

        // Title and toolbar
        $helper->title = $this->displayName; // Title form
        $helper->show_toolbar = true;        // false -> remove toolbar
        $helper->toolbar_scroll = true;      // yes -> Toolbar is always visible on the top of the screen
        $helper->submit_action = 'submit'.$this->name; // requires the action attribute
        $helper->toolbar_btn = array(  // requires the btn that are display in the toolbar(Save & Back)
            'save' => array(
                'desc' => $this->l('Save'),
                'href' => AdminController::$currentIndex.'$configure='.$this->name.
                                                         '$save'.$this->name.
                                                         '$token='.Tools::getAdminTokenLite('AdminModules'),
                ),
                'back' => array(
                    'href' => AdminController::$currentIndex.'$token='.Tools::getAdminTokenLite('AdminModules'),
                    'desc' => $this->l('Back to list')
                )
        );

        // Load current value
        $helper->fields_value['MYMODULE_NAME'] = Configuration::get('MYMODULE_NAME'); // Valeur of the named tag

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

Merci :)

Share this post


Link to post
Share on other sites

Bonjour,

 

Tu passes bien dans la fonction hookDisplayHeader ? Ton CSS est dans quel répertoire ? 

Share this post


Link to post
Share on other sites

Bonjour,

 

Le CSS est dans belgamodule \ css \ belgamodule.css

 

J'ai une fonction hookDisplayHeader()

   public function hookDisplayHeader()
    {
        $this->context->controller->addCSS($this->_path.'css/belgamodule.css', 'all');
    }

Et un registerHook dans la fonction install()

    public function install()
    {
        return parent::install() &&
            $this->registerHook('displayHeader') &&
            $this->registerHook('leftColumn') &&
            $this->registerHook('header') &&
            Configuration::updateValue('MYMODULE_NAME', 'BelgaWeb Module');
    }

Voila, merci pour l'aide

Edited by BelgaWeb (see edit history)

Share this post


Link to post
Share on other sites

Merci,

 

Ton cache est activé ou pas ? Tu as essayé de la vider ? 

Share this post


Link to post
Share on other sites

Le cache est déactiver et il a été vider quelque fois mais rien n'y fait...La compilation est forcé à chaque appel aussi.

Edited by BelgaWeb (see edit history)

Share this post


Link to post
Share on other sites

Si tu met un gros diedans ton hook tu as une page blanche ?

Share this post


Link to post
Share on other sites

et si tu met ton

$this->context->controller->addCSS($this->_path.'css/belgamodule.css', 'all');

juste avant le

return $output.$this->displayForm();

dans la fonction 'getContent()' cela fonctionne ou pas ?

Share this post


Link to post
Share on other sites

Merci pour votre aide ;) 

 

Mais l'erreur venait du fait que j'ai oublier le return dans la fonction displayHeader() <_<

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More