Load in existing data as form defaults

@param stdClass|array $default_values object or array of default values
508303
public function set_data($badge) {
        $default_values = array();
        parent::set_data($badge);

        if (!empty($badge->expiredate)) {
            $default_values['expiry'] = 1;
            $default_values['expiredate'] = $badge->expiredate;
        } else if (!empty($badge->expireperiod)) {
            $default_values['expiry'] = 2;
            $default_values['expireperiod'] = $badge->expireperiod;
        }
        $default_values['currentimage'] = print_badge_image($badge, $badge->get_context(), 'large');

        parent::set_data($default_values);
    }
386740
protected function setupDefaults()
    {
        $defaults = (isset($this->config['defaults'])) ?
            $this->config['defaults'] :
            [];

        foreach ($defaults as $key => $value) {
            if ($key == 'images') {
                if (empty($this->images)) {
                    $this->images = $value;
                }
            } elseif ($key == 'url' && $value === null) {
                $this->setUrl(app('url')->current());
            } elseif (! empty($value) && ! array_key_exists($key, $this->properties)) {
                $this->addProperty($key, $value);
            }
        }
    }
365251
protected function loadFormData() {
        if ($this->request->isPost()) {
            $this->formData = $this->request->getPost() + $this->formData;
        } else {
            foreach ($this->model->getColNames('default') as $name) {
                if (!(isset($this->formData[$name]) && $this->formData[$name])) {
                    $this->formData[$name] = $this->model->get($name, 'default');
                }
            }
        }
        if (!(isset($this->formData['import_id']) && $this->formData['import_id'])) {
            $this->formData['import_id'] = mt_rand(10000, 99999) . time();
        }

        if (array_key_exists('source_survey', $this->formData) && $this->formData['source_survey']) {
            $this->sourceSurveyId = $this->formData['source_survey'];
        }
        if (array_key_exists('target_survey', $this->formData) && $this->formData['target_survey']) {
            $this->targetSurveyId = $this->formData['target_survey'];
        }

        $this->_session = new \Zend_Session_Namespace(__CLASS__ . '-' . $this->formData['import_id']);

        if (array_key_exists('target', $this->formData)) {
            $this->_session->target = $this->formData['target'];
        } else {
            if (isset($this->_session->target)) {
                $this->formData['target'] = $this->_session->target;
            }
        }
    }
1249674
protected function initializeDefaultValues()
    {
        $defaults = [];

        $filters = $this->getFilterInformation();

        foreach (array_keys($filters) as $key) {
            $defaults[ $key ] = null;
        }

        $this->defaults = $defaults;

        return $this;
    }
692634
protected function loadFormData()
    {
        parent::loadFormData();
        $this->loadMailer();

        if (isset($this->formData['gctt'])) {
            $multi = false;
            if (count($this->formData['gctt']) > 1) {
                $multi = true;
                $allLanguages = $this->util->getLocalized()->getLanguages();
            }

            $preview = $this->getPreview($this->formData['gctt']);

            $this->formData['preview_html'] = $preview['html'];
            $this->formData['preview_text'] = $preview['text'];
        }
        if (!isset($this->formData['to'])) {
            $organization = $this->mailer->getOrganization();
            $this->formData['to'] = $this->formData['from'] = $this->currentUser->getEmailAddress();
            if ($organization->getEmail()) {
                $this->formData['from'] = $organization->getEmail();
            } elseif ($this->project->getSiteEmail ()) {
                $this->formData['from'] = $this->project->getSiteEmail();
            }
        }

        $this->formData['available_fields'] = $this->mailElements->displayMailFields($this->mailer->getMailFields());
    }
208335
protected function getDefaultFormValues()
    {
        $defaultValues = $this->acumulusConfig->getCredentials()
             + $this->acumulusConfig->getShopSettings()
             + $this->acumulusConfig->getShopEventSettings()
             + $this->acumulusConfig->getCustomerSettings()
             + $this->acumulusConfig->getInvoiceSettings()
             + $this->acumulusConfig->getEmailAsPdfSettings()
             + $this->acumulusConfig->getPluginSettings();
        return $defaultValues;
    }
527490
protected function setDefaultData()
    {
        $this->data = array_merge($this->data, $this->getDefaultData());

        $this->data['_version'] = gplcart_version();
        $this->data['_user'] = $this->current_user;
        $this->data['_store'] = $this->current_store;
        $this->data['_language'] = $this->current_language;
        $this->data['_maintenance'] = $this->is_maintenance;
        $this->data['_messages'] = $this->session->getMessage();

        $default_langcode = $this->language->getDefault();

        foreach ($this->language->getList() as $code => $language) {
            if (!empty($language['status']) || $code === $default_langcode) {
                $this->data['_languages'][$code] = $language;
            }
        }

        $this->data['_store_title'] = $this->store->getTranslation('title', $this->langcode);

        if (!empty($this->current_store['data']['logo'])) {
            $this->data['_store_logo'] = $this->image($this->current_store['data']['logo']);
        }

        if (!empty($this->current_store['data']['favicon'])) {
            $this->data['_store_favicon'] = $this->image($this->current_store['data']['favicon']);
        }

        $this->setClasses();
        $this->setDefaultJs();
    }
842087
private function _addDefaultValues()
    {
        if (!isset($this->_sp['assertionConsumerService']['binding'])) {
            $this->_sp['assertionConsumerService']['binding'] = OneLogin_Saml2_Constants::BINDING_HTTP_POST;
        }
        if (isset($this->_sp['singleLogoutService']) && !isset($this->_sp['singleLogoutService']['binding'])) {
            $this->_sp['singleLogoutService']['binding'] = OneLogin_Saml2_Constants::BINDING_HTTP_REDIRECT;
        }

        if (!isset($this->_compress['requests'])) {
            $this->_compress['requests'] = true;
        }

        if (!isset($this->_compress['responses'])) {
            $this->_compress['responses'] = true;
        }

        // Related to nameID
        if (!isset($this->_sp['NameIDFormat'])) {
            $this->_sp['NameIDFormat'] = OneLogin_Saml2_Constants::NAMEID_UNSPECIFIED;
        }
        if (!isset($this->_security['nameIdEncrypted'])) {
            $this->_security['nameIdEncrypted'] = false;
        }
        if (!isset($this->_security['requestedAuthnContext'])) {
            $this->_security['requestedAuthnContext'] = true;
        }

        // sign provided
        if (!isset($this->_security['authnRequestsSigned'])) {
            $this->_security['authnRequestsSigned'] = false;
        }
        if (!isset($this->_security['logoutRequestSigned'])) {
            $this->_security['logoutRequestSigned'] = false;
        }
        if (!isset($this->_security['logoutResponseSigned'])) {
            $this->_security['logoutResponseSigned'] = false;
        }
        if (!isset($this->_security['signMetadata'])) {
            $this->_security['signMetadata'] = false;
        }

        // sign expected
        if (!isset($this->_security['wantMessagesSigned'])) {
            $this->_security['wantMessagesSigned'] = false;
        }
        if (!isset($this->_security['wantAssertionsSigned'])) {
            $this->_security['wantAssertionsSigned'] = false;
        }

        // NameID element expected
        if (!isset($this->_security['wantNameId'])) {
            $this->_security['wantNameId'] = true;
        }

        // Relax Destination validation
        if (!isset($this->_security['relaxDestinationValidation'])) {
            $this->_security['relaxDestinationValidation'] = false;
        }

        // encrypt expected
        if (!isset($this->_security['wantAssertionsEncrypted'])) {
            $this->_security['wantAssertionsEncrypted'] = false;
        }
        if (!isset($this->_security['wantNameIdEncrypted'])) {
            $this->_security['wantNameIdEncrypted'] = false;
        }

        // XML validation
        if (!isset($this->_security['wantXMLValidation'])) {
            $this->_security['wantXMLValidation'] = true;
        }

        // SignatureAlgorithm
        if (!isset($this->_security['signatureAlgorithm'])) {
            $this->_security['signatureAlgorithm'] = XMLSecurityKey::RSA_SHA1;
        }

        // DigestAlgorithm
        if (!isset($this->_security['digestAlgorithm'])) {
            $this->_security['digestAlgorithm'] = XMLSecurityDSig::SHA1;
        }

        if (!isset($this->_security['lowercaseUrlencoding'])) {
            $this->_security['lowercaseUrlencoding'] = false;
        }

        // Certificates / Private key /Fingerprint
        if (!isset($this->_idp['x509cert'])) {
            $this->_idp['x509cert'] = '';
        }
        if (!isset($this->_idp['certFingerprint'])) {
            $this->_idp['certFingerprint'] = '';
        }
        if (!isset($this->_idp['certFingerprintAlgorithm'])) {
            $this->_idp['certFingerprintAlgorithm'] = 'sha1';
        }

        if (!isset($this->_sp['x509cert'])) {
            $this->_sp['x509cert'] = '';
        }
        if (!isset($this->_sp['privateKey'])) {
            $this->_sp['privateKey'] = '';
        }
    }
158358
protected function loadFormData()
    {
        if ($this->createData && (! $this->request->isPost())) {
            $now            = new \MUtil_Date();
            $organizationId = $this->request->getParam(\MUtil_Model::REQUEST_ID2);
            $patientId      = $this->request->getParam(\MUtil_Model::REQUEST_ID1);
            $respondentData = $this->util->getDbLookup()->getRespondentIdAndName($patientId, $organizationId);

            $this->formData = array(
                'gr2o_patient_nr'        => $patientId,
                'gto_id_organization'    => $organizationId,
                'gto_id_respondent'      => $respondentData['id'],
                'respondent_name'        => $respondentData['name'],
                'gto_id_survey'          => $this->request->getParam(\Gems_Model::SURVEY_ID),
                'gto_id_track'           => $this->request->getParam(\Gems_Model::TRACK_ID),
                'gto_valid_from_manual'  => 1,
                'gto_valid_from'         => $now,
                'gto_valid_until_manual' => 0,
                'gto_valid_until'        => null, // Set in loadSurvey
                );

            $this->getModel()->processAfterLoad(array($this->formData), $this->createData, false);
        } else {
            parent::loadFormData();
        }

        $this->loadSurvey();
        $this->loadTrackSettings();
        $this->loadRoundSettings();

        // \MUtil_Echo::track($this->formData);
    }
1262889
public function populate(array $values, bool $overrideExistingVars = false): void
    {
        $updateLoadedVars = false;
        $loadedVars = array_flip(explode(',', $_SERVER['SYMFONY_DOTENV_VARS'] ?? $_ENV['SYMFONY_DOTENV_VARS'] ?? ''));

        foreach ($values as $name => $value) {
            $notHttpName = 0 !== strpos($name, 'HTTP_');
            // don't check existence with getenv() because of thread safety issues
            if (!isset($loadedVars[$name]) && (!$overrideExistingVars && (isset($_ENV[$name]) || (isset($_SERVER[$name]) && $notHttpName)))) {
                continue;
            }

            if ($this->usePutenv) {
                putenv("$name=$value");
            }

            $_ENV[$name] = $value;
            if ($notHttpName) {
                $_SERVER[$name] = $value;
            }

            if (!isset($loadedVars[$name])) {
                $loadedVars[$name] = $updateLoadedVars = true;
            }
        }

        if ($updateLoadedVars) {
            unset($loadedVars['']);
            $loadedVars = implode(',', array_keys($loadedVars));
            $_ENV['SYMFONY_DOTENV_VARS'] = $_SERVER['SYMFONY_DOTENV_VARS'] = $loadedVars;

            if ($this->usePutenv) {
                putenv('SYMFONY_DOTENV_VARS='.$loadedVars);
            }
        }
    }
1111625
private function _setDefaults()
    {
        if (!isset(self::$_template))
            self::_initializeDefaults();
        foreach (self::$_template as $k=>$v) {
            if ($k[0] != '_')
                $this->$k = $v;
        }
        return $this;
    }
189505
public function populateDefaults()
    {
        parent::populateDefaults();

        if (!isset($this->Date) || $this->Date === null) {
            $this->Date = DBDatetime::now()->Format('y-MM-dd 09:00:00');
        }
    }
61767
protected function setDefaultParams()
    {
        foreach ($this->allowedParams as $param => $options) {
            $this->params[$param] = null;
            if (! empty($options['arguments'])) {
                $this->params[$param] = array();
                foreach ($options['arguments'] as $arg => $opts) {
                    if (! empty($opts['default'])) {
                        $cast = ! empty($opts['cast']) ? $opts['cast'] : 'string';
                        $this->params[$param][$arg] = $this->castValue($cast, $opts['default']);
                    }
                }
            } elseif (! empty($options['default'])) {
                $cast = ! empty($options['cast']) ? $options['cast'] : 'string';
                $this->params[$param] = $this->castValue($cast, $options['default']);
            }
        }
    }
1063149
public function data_preprocessing(&$defaultvalues) {
        parent::data_preprocessing($defaultvalues);
        $defaultvalues['completionentriesenabled'] = !empty($defaultvalues['completionentries']) ? 1 : 0;
        if (empty($defaultvalues['completionentries'])) {
            $defaultvalues['completionentries'] = 1;
        }
    }
860583
protected function loadFormData()
    {
        parent::loadFormData();

        if ($this->createData && ($this->request->isPost() && (! isset($this->formData[$this->saveButtonId])))) {
            if ((! $this->_saveButton) || (! $this->_saveButton->isChecked())) {
                if (isset($this->formData['grs_ssn']) && $this->formData['grs_ssn'])  {
                    $filter = array(
                        'grs_ssn' => $this->formData['grs_ssn'],
                        'gr2o_id_organization' => true, // Make sure all organizations are checked in RespModel
                        );

                    if ($this->formData['gr2o_id_organization']) {
                        $orgId = $this->formData['gr2o_id_organization'];
                    } else {
                        $orgId = $this->model->get('gr2o_id_organization', 'default');
                    }
                    $order = array(
                        $this->db->quoteInto(
                                "CASE WHEN gr2o_id_organization = ? THEN 1 ELSE 2 END",
                                $orgId
                                ) => SORT_ASC
                        );

                    $data = $this->model->loadFirst($filter, $order);

                    // Fallback for when just a respondent row was saved but no resp2org exists
                    if (! $data) {
                        $data = $this->db->fetchRow(
                                "SELECT * FROM gems__respondents WHERE grs_ssn = ?",
                                $this->formData['grs_ssn']
                                );

                        if ($data) {
                            $data['gr2o_id_organization'] = false;
                        }
                    }

                    if ($data) {
                        // \MUtil_Echo::track($this->formData);
                        // \MUtil_Echo::track($data);
                        // Do not use this value
                        unset($data['grs_ssn']);

                        if ($data['gr2o_id_organization'] == $orgId) {
                            // gr2o_patient_nr
                            // gr2o_id_organization

                            $this->addMessage($this->_('Known respondent.'));

                            //*
                            foreach ($data as $name => $value) {
                                if ((substr($name, 0, 4) == 'grs_') || (substr($name, 0, 5) == 'gr2o_')) {
                                    if (array_key_exists($name, $this->formData)) {
                                        $this->formData[$name] = $value;
                                    }
                                    $cname = $this->model->getKeyCopyName($name);
                                    if (array_key_exists($cname, $this->formData)) {
                                        $this->formData[$cname] = $value;
                                    }
                                }
                            } // */
                        } else {
                            if ($data['gr2o_id_organization']) {
                                $org = $this->loader->getOrganization($data['gr2o_id_organization']);
                                $this->addMessage(sprintf(
                                        $this->_('Respondent data retrieved from %s.'),
                                        $org->getName()
                                        ));
                            } else {
                                $this->addMessage($this->_('Respondent data found.'));
                            }

                            foreach ($data as $name => $value) {
                                if ((substr($name, 0, 4) == 'grs_') && array_key_exists($name, $this->formData)) {
                                    $this->formData[$name] = $value;
                                }
                                $this->formData['gr2o_id_user'] = $data['grs_id_user'];
                            }
                        }

                    }
                }
            }
        }
    }
949326
protected function collectValues(array $values, array $defaults = [])
    {
        foreach ($values as $value) {
            $defaults = $this->collectValue($value, $defaults);
        }

        return $defaults;
    }
465818
protected function defaultData()
    {
        parent::defaultData();
        if($this->hasRequestParameter('uri')){
            $uri = $this->getRequestParameter('uri');
            $classUri = $this->getRequestParameter('classUri');
            if(!empty($uri)){
                $item = $this->getResource(tao_helpers_Uri::decode($uri));
                $this->setData('label', $item->getLabel());
                $this->setData('authoringUrl', _url('authoring', 'Items', 'taoItems', array('uri' => $uri, 'classUri' => $classUri)));
                $this->setData('previewUrl', $this->getClassService()->getPreviewUrl($item));
            }
        }
    }