Merge settings.

@param Model $model
@param array $settings
778163
public function setup(Model $model, $settings = array()) {
        $this->settings[$model->alias] = array_merge($this->_defaults, $settings);
    }
335600
public function save(Model $model, $options = array())
    {
        $options = array_merge(array(
            'filter' => true,
            'observer' => true,
        ), $options);

        if ($options['filter']) {
            $this->filter($model);
        }

        if ($options['observer']) {
            $this->applyHook('saving', $model, $options);
        }

        $modified = $this->connection->persist($this, $model->dump());
        $model->setId($modified['$id']);

        if ($options['observer']) {
            $this->applyHook('saved', $model, $options);
        }

        $model->sync($modified);
        $this->resetCache();
    }
1374003
public function mergeAll(array $values)
    {
        foreach ($values as $key => $value) {
            $this->merge($key, $value);
        }
    }
1139110
public function addSettings(array $settings)
    {
        foreach ($settings as $key => $value) {
            $this->addSetting($key, $value);
        }
    }
1070478
public function setSettings( $settings )
    {
        if ( ! empty( $settings ) )
        {
            foreach ( $settings as $name => $value )
            {
                $this->setSetting( $name, $value );
            }
        }

        return $this;
    }
1344597
protected function mergeWithOrder($settings, &$merge)
    {
        if (isset($merge[$settings->order])) {
            $this->mergeWithOrder(++$settings->order, $merge);
        }

        return $merge[$settings->order] = $settings;
    }
680862
public function setup(Model $model, $config = []) {
		if (!isset($this->settings[$model->alias])) {
			$this->settings[$model->alias] = [
				'pluginName' => null,
				'checkPath' => null,
				'configFile' => null,
				'path' => null,
			];
		}
		$this->settings[$model->alias] = array_merge($this->settings[$model->alias], $config);
		extract($this->settings[$model->alias]);
		$this->_initConfig = new InitConfig($pluginName, $checkPath, $configFile);
		if (!empty($path)) {
			$this->_initConfig->path = $path;
		}

		$this->_initConfig->initConfig();
	}
1154807
public function renderField(Model $model, $attribute, array $settings = [])
    {
        $fieldOptions = ArrayHelper::getValue($settings, 'fieldOptions', []);
        $field = $this->field($model, $attribute, $fieldOptions);

        if (($label = ArrayHelper::getValue($settings, 'label')) !== null) {
            $field->label($label, ArrayHelper::getValue($settings, 'labelOptions', []));
        }
        if (($hint = ArrayHelper::getValue($settings, 'hint')) !== null) {
            $field->hint($hint, ArrayHelper::getValue($settings, 'hintOptions', []));
        }

        $type = ArrayHelper::getValue($settings, 'type', static::INPUT_TEXT);
        $this->prepareField($field, $type, $settings);

        return $field;
    }
1007903
private function setSettings($settings)
    {
        if ($settings) {
            foreach ($this->settings as $key => &$value) {
                if (!empty($settings->{$key}) && $settings->{$key}) {
                    if (is_object($settings->{$key})) {
                        $value = array_merge(
                            $value,
                            json_decode(json_encode($settings->{$key}, JSON_FORCE_OBJECT), true)
                        );
                    } else {
                        $value = $settings->{$key};
                    }
                }
            }
        }
    }
690757
public static function settings($settings = null)
    {
        if ($settings) {
            //set mode
            self::$settings = self::mergeSettings(self::$settings, $settings);
        } else {
            //get mode
        }

        //always return settings
        return self::$settings;
    }
931625
public function merge(ModelInformationInterface $with)
    {
        if ( ! empty($with->model)) {
            $this->model = $with->model;
        }

        if ( ! empty($with->original_model)) {
            $this->original_model = $with->original_model;
        }

        $mergeAttributes = [
            'single',
            'meta',
            'verbose_name',
            'translated_name',
            'verbose_name_plural',
            'translated_name_plural',
            'allow_delete',
            'delete_condition',
            'delete_strategy',
            'confirm_delete',
            'list',
            'form',
            'show',
            'export',
            'reference',
            'includes',
        ];

        foreach ($mergeAttributes as $attribute) {
            $this->mergeAttribute($attribute, $with->{$attribute});
        }
    }
748793
public function mergeSettings(array $savedSettings, array $definedSettings)
    {
        // Test if the saved settings are for site or page. Only site settings have the category key
        $pageSetting = isset($savedSettings[0]->category) ? false : true;

        // Make index of saved setting keys to setting array for easy lookup
        $settingIndex = array_combine(array_column($savedSettings, 'setting_key'), array_keys($savedSettings));

        // Loop through defined settings and update with saved values and meta info
        foreach ($definedSettings as $defKey => $setting) {
            if (isset($settingIndex[$setting->key])) {
                $definedSettings[$defKey]->id = $savedSettings[$settingIndex[$setting->key]]->id;
                $definedSettings[$defKey]->setting_value = $savedSettings[$settingIndex[$setting->key]]->setting_value;
                $definedSettings[$defKey]->created_by = $savedSettings[$settingIndex[$setting->key]]->created_by;
                $definedSettings[$defKey]->created_date = $savedSettings[$settingIndex[$setting->key]]->created_date;
                $definedSettings[$defKey]->updated_by = $savedSettings[$settingIndex[$setting->key]]->updated_by;
                $definedSettings[$defKey]->updated_date = $savedSettings[$settingIndex[$setting->key]]->updated_date;

                // Remove saved setting from array parameter now that we have updated the setting definition
                unset($savedSettings[$settingIndex[$setting->key]]);
            } else {
                // If a matching saved setting was NOT found, then set default value
                $definedSettings[$defKey]->setting_value = $definedSettings[$defKey]->value;
            }

            // Amend setting keys to what is expected in template
            $definedSettings[$defKey]->setting_key = $setting->key;
            $definedSettings[$defKey]->input_type = $definedSettings[$defKey]->inputType;

            // Include select options array
            if ($definedSettings[$defKey]->inputType === 'select') {
                $definedSettings[$defKey]->options = array_column($definedSettings[$defKey]->options, 'name', 'value');
            }

            // Add setting catagory. Not needed for page settings, but not in the way either
            $definedSettings[$defKey]->category = 'custom';

            // Remove JSON keys to avoid confusion in template
            unset($definedSettings[$defKey]->key);
            unset($definedSettings[$defKey]->value);
            unset($definedSettings[$defKey]->inputType);
        }

        // Check remaining saved settings for orphaned settings.
        array_walk($savedSettings, function(&$row) use ($pageSetting) {
            if ($pageSetting || (isset($row->category) && $row->category === 'custom')) {
                $row->orphaned = true;
            }
        });

        // Append defined settings to end of saved settings array and return
        return array_merge($savedSettings, $definedSettings);
    }
318955
private function applyOrders(array $settings): void
    {
        // Obtain a list of columns
        foreach ($settings as $column => $order) {
            $this->getSource()->addOrderBy($column, $order);
        }
    }
487502
protected function _softDeleteAssociations($model, $active) {
		if (empty($model->belongsTo)) {
			return;
		}

		$fields = array_keys($this->_normalizeFields($model));
		$parentModels = array_keys($model->belongsTo);

		foreach ($parentModels as $parentModel) {
			foreach (array('hasOne', 'hasMany') as $assocType) {
				if (empty($model->{$parentModel}->{$assocType})) {
					continue;
				}

				foreach ($model->{$parentModel}->{$assocType} as $assoc => $assocConfig) {
					$modelName = empty($assocConfig['className']) ? $assoc : @$assocConfig['className'];
					if ((!empty($model->plugin) && strstr($model->plugin . '.', $model->alias) === false ? $model->plugin . '.' : '') . $model->alias !== $modelName) {
						continue;
					}

					$conditions =& $model->{$parentModel}->{$assocType}[$assoc]['conditions'];
					if (!is_array($conditions)) {
						$model->{$parentModel}->{$assocType}[$assoc]['conditions'] = array();
					}

					$multiFields = 1 < count($fields);
					foreach ($fields as $field) {
						if ($active) {
							if (!isset($conditions[$field]) && !isset($conditions[$assoc . '.' . $field])) {
								if (is_string($active)) {
									if ($field == $active) {
										$conditions[$assoc . '.' . $field] = false;
									} elseif (isset($conditions[$assoc . '.' . $field])) {
										unset($conditions[$assoc . '.' . $field]);
									}
								} elseif (!$multiFields) {
									$conditions[$assoc . '.' . $field] = false;
								}
							}
						} elseif (isset($conditions[$assoc . '.' . $field])) {
							unset($conditions[$assoc . '.' . $field]);
						}
					}
				}
			}
		}
	}
360912
public function setup(Model $model, $settings = array()) {
        if ($settings) {
            foreach ($settings as $field => $options) {
                $this->settings[$model->alias][$field] = (array) $options + array('required' => true);
            }
        }
    }
1146008
public function setExtraModelValues(array $fields, &$model)
    {
        //make sure the relationships are loaded
        foreach ($fields as $name => $field) {
            if ($field->getOption('relationship')) {
                $this->setModelRelationship($model, $field);
            }

            //if this is a setter field, unset it
            if ($field->getOption('setter')) {
                $model->__unset($name);
            }
        }
    }
971797
public function setup(Model $model, $settings = array()) {
		if (!isset($this->settings[$model->alias])) {
			$this->settings[$model->alias] = array('label' => 'name', 'slug' => 'slug');
		}

		$this->settings[$model->alias] = array_merge(
			$this->settings[$model->alias], (array)$settings
		);

		if (!$model->hasField($this->settings[$model->alias]['label'])) {
			$this->settings[$model->alias]['label'] = $model->displayField;
		}
	}