Save the new settings passed in $data

@todo Add vartype handling to ensure $data is array
@param array $data Associative array of value=>xx, forced=>xx, adv=>xx
@return string empty or error message
964373
public function write_setting($data) {
        global $CFG;

        $value  = $data['value'];
        $forced = empty($data['forced']) ? 0 : 1;
        $adv    = empty($data['adv'])    ? 0 : 2;
        $flag   = ($forced | $adv); //bitwise or

        if (!in_array($value, array_keys($this->choices))) {
            return 'Error setting ';
        }

        $oldvalue  = $this->config_read($this->name);
        $oldflag   = (int)$this->config_read($this->name.'_flag');
        $oldforced = (1 & $oldflag); // first bit

        $result1 = $this->config_write($this->name, $value);
        $result2 = $this->config_write($this->name.'_flag', $flag);

        // force regrade if needed
        if ($oldforced != $forced or ($forced and $value != $oldvalue)) {
            require_once($CFG->libdir.'/gradelib.php');
            grade_category::updated_forced_settings();
        }

        if ($result1 and $result2) {
            return '';
        } else {
            return get_string('errorsetting', 'admin');
        }
    }
1105896
public function write_setting($data) {
    // If all is selected, remove any explicit options.
        if (in_array('$@ALL@$', $data)) {
            $data = array('$@ALL@$');
        }
        // None never needs to be written to the DB.
        if (in_array('$@NONE@$', $data)) {
            unset($data[array_search('$@NONE@$', $data)]);
        }
        return parent::write_setting($data);
    }
1288732
public function setData(array $data) {
		$this->data = $data;

		$this->resetFields();

		foreach($data as $name=>$data)
			$this->newField($name, $data);

		$this->updateChilds();

		return $this;
	}
535982
public static function fromArray(array $data)
    {
        $result = '';
        foreach ($data as $name => $value) {
            $value = StringHelper::toString($value, "'", Serialize::SERIALIZE_JSON);
            $result .= "$name=$value; ";
        }

        return $result === '' ? null : rtrim($result);
    }
482290
protected static function saveConfigParams(array $data, array $extra)
    {
        Logger::log('Saving required config parameters');
        //En caso de tener parámetros nuevos los guardamos
        if (array_key_exists('label', $extra) && is_array($extra['label'])) {
            foreach ($extra['label'] as $index => $field) {
                if (array_key_exists($index, $extra['value']) && !empty($extra['value'][$index])) {
                    /** @var $data array */
                    $data[$field] = $extra['value'][$index];
                }
            }
        }
        return $data;
    }
134144
public function setData(array $data)
    {
        parent::setData($data);

        if (isset($data['condition'])) {
            $this->setCondition($data['condition']);
        }

        return $this;
    }
118236
public function setData(array $data)
    {
        $data = $this->setIdFromData($data);

        parent::setData($data);
        return $this;
    }
1149744
public function write_setting($data) {
        if (!is_array($data)) {
            return ''; // ignore it
        }
        if (!$this->load_choices() or empty($this->choices)) {
            return '';
        }
        unset($data['xxxxx']);
        $result = array();
        foreach ($data as $key => $value) {
            if ($value and array_key_exists($key, $this->choices)) {
                $result[] = $key;
            }
        }
        return $this->config_write($this->name, implode(',', $result)) ? '' : get_string('errorsetting', 'admin');
    }
908296
public function create(array $data)
    {
        $parameters = ['name' => $data['name']];

        foreach ($data['config'] as $key => $value) {
            $parameters["config.$key"] = $value;
        }

        return $this->post('plugins/', [
            'json' => $parameters
        ]);
    }
911619
public function update(array $data)
    {
        $affected = 0;
        foreach ($this->table->data['data'] as &$rs) {
            if ($this->matchWhere($rs)) {
                $rs = array_merge($rs, $data);
                $affected++;
            }
        }

        if ($affected) {
            $this->table->save();
        }

        return $affected;
    }
1225715
public static function save($data)
	{
		$instance = self::getInstance();

		// Merge and make sure values are unique
		$data = $instance->merge($instance->config->toArray(), $data);
		$data = $instance->unique($data);

		// Set data back to the instance
		$instance->config = new Registry($data);

		// Actually write out the data
		$instance->write();

		return true;
	}
520447
public function write_setting($data) {
        if ($this->paramtype === PARAM_INT and $data === '') {
            // Do not complain if '' used instead of 0.
            $data = 0;
        }

        // Try to convert any non-ascii domains to ACE prior to validation - we can't modify anything in validate!
        if (function_exists('idn_to_ascii')) {
            $data = $this->ace_encode($data);
        }

        $validated = $this->validate($data);
        if ($validated !== true) {
            return $validated;
        }
        return ($this->config_write($this->name, $data) ? '' : get_string('errorsetting', 'admin'));
    }
1316015
public function write_setting($data) {
        // Try to remove duplicates before storing the contexts (to avoid problems in sync_users()).
        $data = explode(';', $data);
        $data = array_map(function($x) {
            return core_text::strtolower(trim($x));
        }, $data);
        $data = implode(';', array_unique($data));
        return parent::write_setting($data);
    }
630573
public function create(array $data) {
        $this->_checkAcl('create');
        $pk = $this->_model->insert($data);
        return $pk;
    }
872221
protected function _getData(array $data): array
    {
        // Stringify empty values
        if (!empty($data)) {
            foreach ($data as $fieldName => $value) {
                $data[$fieldName] = $this->_stringifyEmptyValue($value);
            }
        }

        return $data;
    }
1036680
public function setData(array $data)
    {
        foreach ($data as $key => $val) {
            $setter = $this->setter($key);
            if (is_callable([ $this, $setter ])) {
                $this->{$setter}($val);
            } else {
                $this->{$key} = $val;
            }
        }

        return $this;
    }
811282
public function write_setting($data) {
        if (!is_array($data)) {
            return '';
        }

        $result = $this->config_write($this->name, (int)$data['h']) && $this->config_write($this->name2, (int)$data['m']);
        return ($result ? '' : get_string('errorsetting', 'admin'));
    }