How to pass a variable to module settings

Hello guys,

I am using Oxid 6 with PHP version 5.6
I have a function for generating random string in a class in the file modules/moduleName/admin/function-file:

public static function generateRandomString($length = 30) {
return substr(str_shuffle(str_repeat($x=‘0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’, ceil($length/strlen($x)) )),1,$length);
}

In the same class I have other function:

public static function onActivate()
{

    try {

        self::generateRandomString();
        self::alterTableColumns();
        self::updateDBViews();
        self::clearShopTmp();

        $newApi = self::generateRandomString();
        
        // var_dump($newApi);die();

    } catch(Exception $e) {
        oxRegistry::get("oxutilsview")->addErrorToDisplay(new oxException($e->getMessage()));    
    }
}

My question is: How can I pass this variable ($newApi) in the module settings in: moduleName/application/views/admin/en(de)/here_lang.php ?
E.g:
$aLang = array(
‘charset’ => ‘UTF-8’,
‘SHOP_MODULE_GROUP_name’ => ‘Something’,
‘SHOP_MODULE_configuration’ => ‘Something’,
‘SHOP_MODULE_api_key’ => ‘API Key’,
‘SHOP_MODULE_checkbox_generateApiKey’ => $here,

);
Thanks

$aLang = array(
...
'SHOP_MODULE_checkbox_generateApiKey' => substr(str_shuffle(str_repeat($x='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil(30/strlen($x)) )),1,30)

but it will be random every time you reset reset language cache

1 Like

Thank you, this works.

Do you know how can I make on click on the checkbox this same string to appear in the higher text input element as value or in placeholder but not to be saved in the database?

oxid does not support that.