PHP code example of arkonsoft / ps-module-core

1. Go to this page and download the library: Download arkonsoft/ps-module-core library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

arkonsoft / ps-module-core example snippets



if (!defined('_PS_VERSION_')) {
    exit;
}

use Arkonsoft\PsModule\Core\Module\AbstractModule;

class MyModule extends AbstractModule
{
    public function __construct()
    {
        $this->name = 'mymodule';

        // ps-module-core
        $this->tab = ModuleCategory::FRONT_OFFICE_FEATURES;
        $this->version = '1.0.0';
        $this->author = 'Firstname Lastname';
        $this->need_instance = 0;
        $this->ps_versions_compliancy = [
            'min' => '1.7.0.0',
            'max' => '8.99.99',
        ];
        $this->bootstrap = true;

        parent::__construct();

        $this->displayName = $this->trans('My module', [], 'Modules.Mymodule.Admin');
        $this->description = $this->trans('Description of my module.', [], 'Modules.Mymodule.Admin');

        $this->confirmUninstall = $this->trans('Are you sure you want to uninstall?', [], 'Modules.Mymodule.Admin');

        // ps-module-core
        if ($this->canBeUpgraded()) {
            $this->warning = $this->trans('The module %s needs to be updated. Use the "update" option in the list of modules. The module without an update may not work properly.', [ $this->name ], 'Modules.Mymodule.Admin');
        }
    }
}



use Arkonsoft\PsModule\Core\Controller\AbstractAdminSettingsController;

if (!defined('_PS_VERSION_')) {
    exit;
}

class AdminMyModuleSettingsController extends AbstractAdminSettingsController
{
    public function prepareOptions(): void
    {
        $form = [
            'form' => [
                'tabs' => [
                    'general' => $this->module->getTranslator()->trans('General', [], 'Modules.MyModule.Admin'),
                    'other1' => $this->module->getTranslator()->trans('Other 1', [], 'Modules.MyModule.Admin'),
                    'other2' => $this->module->getTranslator()->trans('Other 2', [], 'Modules.MyModule.Admin'),
                ],
                'legend' => [
                    'title' => $this->module->getTranslator()->trans('Settings', [], 'Modules.MyModule.Admin'),
                    'icon' => 'icon-cogs'
                ],
                'submit' => [
                    'title' => $this->module->getTranslator()->trans('Save', [], 'Modules.MyModule.Admin'),
                    'class' => 'btn btn-default pull-right'
                ],
            ],
        ];

        $form['form']['input'][] = [
            'label' => $this->module->getTranslator()->trans('Example field 1', [], 'Modules.MyModule.Admin'),
            'type' => 'text',
            'name' => $this->module->name . 'example_field_1',
            'lang' => true,
            'tab' => 'general'
        ];

        $form['form']['input'][] = [
            'label' => $this->module->getTranslator()->trans('Example field 2', [], 'Modules.MyModule.Admin'),
            'type' => 'text',
            'name' => $this->module->name . 'example_field_2',
            'lang' => true,
            'tab' => 'general'
        ];

        $this->forms[] = $form;
    }
}


/**
 * Returns the database version of the module
 * 
 * @return ?string
 */
protected function getDatabaseVersion()

/**
 * Checks if the database version is lower than the specified version for potential upgrade.
 * 
 * @return bool
 */
protected function canBeUpgraded(): bool

public function __construct()
    {
        // other code

        if ($this->canBeUpgraded()) {
            $this->warning = $this->trans('The module %s needs to be updated. Use the "update" option in the list of modules. The module without an update may not work properly.', [ $this->name ], 'Modules.Mymodule.Admin');
        }
    }

public function __construct()
    {
        // other code

        $this->tab = ModuleCategory::FRONT_OFFICE_FEATURES;
    }

public function installTab(): bool
    {
        if (Tab::getIdFromClassName($this->settingsAdminController)) {
            return true;
        }

        $tab = new Tab();

        $parentTabClassName = TabDictionary::CATALOG;

        // other code
    }

public function __construct()

abstract public function prepareOptions();

public function initContent()

public function postProcess()

public function dispatchAction()

public function renderForm()

public function loadFormValues(HelperForm $helper)

public function saveForm()