admin/controllers/Settings.php
public function component($sType = 'component')
    {
        $oInput             = Factory::service('Input');
        $this->data['slug'] = $oInput->get('slug');

        $oComponent = Components::getBySlug($this->data['slug']);

        if (empty($oComponent->data->settings)) {
            show404();
        }

        //  Move all the settings which aren't already in fieldsets/groups into groups
        $this->data['fieldsets'] = [];
        $this->aFields           = [];
        $this->extractFieldsets($oComponent->slug, $oComponent->data->settings);
        $this->data['fieldsets'] = array_values($this->data['fieldsets']);

        if ($oInput->post()) {

            //  Validate
            $oFormValidation = Factory::service('FormValidation');
            $aRules          = [];

            foreach ($this->aFields as $oField) {

                $aFieldRule   = ['trim'];
                $aFieldRule[] = !empty($oField->required) ? 'required' : '';

                if (!empty($oField->validation_rules)) {
                    $aFieldRule = array_merge($aFieldRule, explode('|', $oField->validation_rules));
                }

                $aFieldRule = array_filter($aFieldRule);
                $aFieldRule = array_unique($aFieldRule);

                $aRules[] = [
                    'field' => $oField->key,
                    'label' => $oField->label,
                    'rules' => implode('|', $aFieldRule),
                ];
            }

            $oFormValidation->set_rules($aRules);

            if ($oFormValidation->run()) {

                $aSettings          = [];
                $aSettingsEncrypted = [];

                foreach ($this->aFields as $oField) {

                    //  @todo respect data types

                    //  Encrypted or not?
                    if (!empty($oField->encrypted)) {
                        $aSettingsEncrypted[$oField->key] = $oInput->post($oField->key);
                    } else {
                        $aSettings[$oField->key] = $oInput->post($oField->key);
                    }
                }

                //  Begin transaction
                $oAppSettingService = Factory::service('AppSetting');
                $oDb                = Factory::service('Database');
                $oDb->trans_begin();

                //  Normal settings
                if (!$oAppSettingService->set($aSettings, $oComponent->slug)) {
                    $sError = $oAppSettingService->lastError();
                }

                //  Encrypted settings
                if (!$oAppSettingService->set($aSettingsEncrypted, $oComponent->slug, null, true)) {
                    $sError = $oAppSettingService->lastError();
                }

                if (empty($sError)) {
                    $oDb->trans_commit();
                    $this->data['success'] = $sType . ' settings were saved.';
                } else {
                    $oDb->trans_rollback();
                    $this->data['error'] = 'There was a problem saving shop settings. ' . $sError;
                }

            } else {
                $this->data['error'] = lang('fv_there_were_errors');
            }
        }

        // --------------------------------------------------------------------------

        //  Get all the settings for this component
        $this->data['settings'] = appSetting(null, $oComponent->slug);

        // --------------------------------------------------------------------------

        $this->data['page']->title = 'Configure ' . $sType . ' &rsaquo; ' . $oComponent->name;

        // --------------------------------------------------------------------------

        Helper::loadView('component');
    }
public function component($sType = 'component')
    {
        $oInput             = Factory::service('Input');
        $this->data['slug'] = $oInput->get('slug');

        $oComponent = Components::getBySlug($this->data['slug']);

        if (empty($oComponent->data->settings)) {
            show404();
        }

        //  Move all the settings which aren't already in fieldsets/groups into groups
        $this->data['fieldsets'] = [];
        $this->aFields           = [];
        $this->extractFieldsets($oComponent->slug, $oComponent->data->settings);
        $this->data['fieldsets'] = array_values($this->data['fieldsets']);

        if ($oInput->post()) {

            //  Validate
            $oFormValidation = Factory::service('FormValidation');
            $aRules          = [];

            foreach ($this->aFields as $oField) {

                $aFieldRule   = ['trim'];
                $aFieldRule[] = !empty($oField->required) ? 'required' : '';

                if (!empty($oField->validation_rules)) {
                    $aFieldRule = array_merge($aFieldRule, explode('|', $oField->validation_rules));
                }

                $aFieldRule = array_filter($aFieldRule);
                $aFieldRule = array_unique($aFieldRule);

                $aRules[] = [
                    'field' => $oField->key,
                    'label' => $oField->label,
                    'rules' => implode('|', $aFieldRule),
                ];
            }

            $oFormValidation->set_rules($aRules);

            if ($oFormValidation->run()) {

                $aSettings          = [];
                $aSettingsEncrypted = [];

                foreach ($this->aFields as $oField) {

                    //  @todo respect data types

                    //  Encrypted or not?
                    if (!empty($oField->encrypted)) {
                        $aSettingsEncrypted[$oField->key] = $oInput->post($oField->key);
                    } else {
                        $aSettings[$oField->key] = $oInput->post($oField->key);
                    }
                }

                //  Begin transaction
                $oAppSettingService = Factory::service('AppSetting');
                $oDb                = Factory::service('Database');
                $oDb->trans_begin();

                //  Normal settings
                if (!$oAppSettingService->set($aSettings, $oComponent->slug)) {
                    $sError = $oAppSettingService->lastError();
                }

                //  Encrypted settings
                if (!$oAppSettingService->set($aSettingsEncrypted, $oComponent->slug, null, true)) {
                    $sError = $oAppSettingService->lastError();
                }

                if (empty($sError)) {
                    $oDb->trans_commit();
                    $this->data['success'] = $sType . ' settings were saved.';
                } else {
                    $oDb->trans_rollback();
                    $this->data['error'] = 'There was a problem saving shop settings. ' . $sError;
                }

            } else {
                $this->data['error'] = lang('fv_there_were_errors');
            }
        }

        // --------------------------------------------------------------------------

        //  Get all the settings for this component
        $this->data['settings'] = appSetting(null, $oComponent->slug);

        // --------------------------------------------------------------------------

        $this->data['page']->title = 'Configure ' . $sType . ' &rsaquo; ' . $oComponent->name;

        // --------------------------------------------------------------------------

        Helper::loadView('component');
    }
Configure components which have settings described in their composer.json/config.json file

@param string $sType The type of component

@return void