Files
2019-11-17 19:14:07 +01:00

144 lines
3.4 KiB
PHP

<?php
if (!defined('_PS_VERSION_')){
exit;
}
class Cyb_Texteh1 extends Module {
public function __construct(){
$this->name = 'cyb_texteh1';
$this->tab = 'cyb_texteh1';
$this->version = '1';
$this->author = 'Cyberscope Bastien';
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
$this->bootstrap = true;
$this->display = 'view';
parent::__construct();
$this->displayName = $this->l('Cyberscope Texte H1 (home)');
$this->description = $this->l('');
$this->confirmUninstall = $this->l('Êtes-vous sûr de vouloir désinstaller ce module ?');
$this->templateFile = 'module:cyb_texteh1/cyb_texteh1.tpl';
}
public function install(){
if(!parent::install() || !Configuration::updateValue('h1_home', '') || !$this->registerHook('displayHome') || !$this->registerHook('header')){
return false;
}
else{
return true;
}
}
public function uninstall(){
if(!parent::uninstall() || !Configuration::deleteByName('h1_home')){
return false;
}
else{
return true;
}
}
public function getContent(){
return $this->postProcess().$this->renderForm();
}
private function postProcess(){
if(Tools::isSubmit('submitConfH1')) {
if(Configuration::updateValue('h1_home', htmlentities($_POST['h1_home']))){
return $this->displayConfirmation('Le champ a été enregistré');
}
else{
return $this->displayError('Une erreur a été rencontré');
}
}
}
private function renderForm(){
var_dump(Configuration::get('h1_home'));
$helper = new HelperForm();
$helper->submit_action = 'submitConfH1';
$fields_form = array(
// 'tinymce' => true,
'form' => array(
'legend' => array(
'title' => $this->trans('Settings', array(), 'Admin.Global'),
'icon' => 'icon-cogs'
),
'input' => array(
array(
'type' => 'textarea',
'label' => 'Votre phrase :',
'name' => 'h1_home',
'class' => '',
'required' => true,
'autoload_rte' => true,
)
),
'submit' => array(
'title' => 'Sauvegarder'
)
),
);
$helper->tpl_vars = array(
'fields_value' => array(
'h1_home' => html_entity_decode(Configuration::get('h1_home'))
)
);
return $helper->generateForm(array($fields_form));
}
public function hookHeader(){
$this->context->controller->registerStylesheet('css-cyb-texteh1', 'modules/' . $this->name. '/css/style.css',
[
'media' => 'all',
'priority' => 0,
]
);
}
public function hookDisplayHome(){
global $smarty;
$smarty->assign('message', array('title' => html_entity_decode(Configuration::get('h1_home'))));
return $this->display(__FILE__,'cyb_texteh1.tpl');
}
}