Updating form manager

@param $config
@param $serviceData
@return mixed
352817
private function updateFormManager(stdClass $config, stdClass $serviceData)
    {
        $config->formData = json_decode(json_encode($config->formData), true);

        if( ! isset($config->formData[$serviceData->formID]) )
            $config->formData[$serviceData->formID] = $serviceData->formNameSpace . '\\' . $serviceData->formName;

        return $config;
    }
126771
public function createRequest($config)
    {
        $this->fileService->mkdir($config['_path_request_'], 0777, true);

        $createRequest = $this->fileService->get($config['template_source'].'/CreateRequest.txt');
        $updateRequest = $this->fileService->get($config['template_source'].'/UpdateRequest.txt');

        foreach ($config as $key => $value) {
            $createRequest = str_replace($key, $value, $createRequest);
            $updateRequest = str_replace($key, $value, $updateRequest);
        }

        $createRequest = $this->putIfNotExists($config['_path_request_'].'/'.$config['_camel_case_'].'CreateRequest.php', $createRequest);
        $updateRequest = $this->putIfNotExists($config['_path_request_'].'/'.$config['_camel_case_'].'UpdateRequest.php', $updateRequest);

        return $createRequest;
    }
590665
public function addImport(string $serviceDir)
    {
        $projectConfig = $this->projectYamlDao->loadProjectConfigFile();

        $projectConfig->addImport($serviceDir . DIRECTORY_SEPARATOR . static::SERVICE_FILE_NAME);

        $this->projectYamlDao->saveProjectConfigFile($projectConfig);
    }
563283
protected function appendCommandsToConfig(array &$config)
    {
        collect($this->entityCommandHandlers)
            ->merge(collect($this->instanceCommandHandlers))
            ->each(function($handler, $commandName) use(&$config) {
                $formFields = $handler->form();
                $formLayout = $formFields ? $handler->formLayout() : null;
                $hasFormInitialData = $formFields
                    ? is_method_implemented_in_concrete_class($handler, 'initialData')
                    : false;

                $config["commands"][$handler->type()][$handler->groupIndex()][] = [
                    "key" => $commandName,
                    "label" => $handler->label(),
                    "description" => $handler->description(),
                    "type" => $handler->type(),
                    "confirmation" => $handler->confirmationText() ?: null,
                    "form" => $formFields ? [
                        "fields" => $formFields,
                        "layout" => $formLayout
                    ] : null,
                    "fetch_initial_data" => $hasFormInitialData,
                    "authorization" => $handler->getGlobalAuthorization()
                ];
            });
    }
1245645
public function autocomplete($config = array())
    {
        $config = new KObjectConfigJson($config);
        $config->append(array(
            'element'  => null,
            'options_callback' => null, // wraps the call to select2 options in JavaScript, can be used to add JS code
            'options'  => array(
                'minimumInputLength' => 2,
                'validate'      => false, //Toggle if the forms validation helper is loaded
                'queryVarName'  => 'search',
                'width'         => 'resolve',
                'model'		    => $config->model,
                'placeholder'   => $config->prompt,
                'allowClear'    => $config->deselect,
                'value'         => $config->value,
                'text'          => $config->text,
                'selected'      => $config->selected,
                'url'           => $config->url,
                'multiple'      => false
            )
        ))->append(array(
            'options' => array(
                'label' => $config->text
            )
        ));

        $html ='';

        if (!$config->options->url instanceof KHttpUrl) {
            $config->options->url = $this->getObject('lib:http.url', array('url' => $config->options->url));
        }

        $config->options->url->setQuery(array('fields' => $config->value.','.$config->text), true);

        $config->options->url = (string)$config->options->url;

        $options   = $config->options;
        $signature = md5('autocomplete-'.$config->element.$config->options_callback.$options);

        if($config->element && !static::isLoaded($signature))
        {
            $options = (string) $options;

            if ($config->options_callback) {
                $options = $config->options_callback.'('.$options.')';
            }

            $html .= $this->select2(array('element' => false));

            if (!static::isLoaded('koowa-select2-autocomplete')) {
                $html .= '<script>
                if(!Koowa) {
                    var Koowa = {};
                }
                
                Koowa.getSelect2Options = function(options) {
                    var defaults = {
                        width: "resolve",
                        minimumInputLength: 2,
                        theme: "bootstrap",
                        ajax: {
                            url: options.url,
                            delay: 100,
                            data: function (params) {
                                var page  = params.page || 1,  // page is the one-based page number tracked by Select2
                                    query = {
                                        limit: 10, // page size
                                        offset: (page-1)*10
                                    };
                                query[options.queryVarName] = params.term;
            
                                return query;
                            },
                            processResults: function (data, page) {
                                var results = [],
                                    more = (page * 10) < data.meta.total; // whether or not there are more results available
            
                                kQuery.each(data.entities, function(i, item) {
                                    // Change format to what select2 expects
                                    item.id   = item[options.value];
                                    item.text = item[options.text];
            
                                    results.push(item);
                                });
            
                                // notice we return the value of more so Select2 knows if more results can be loaded
                                return {results: results, more: more};
                            }
                        }
                    };
                    
                    var settings = kQuery.extend( {}, defaults, options);
                    
                    return settings;
                };
                </script>';

                static::setLoaded('koowa-select2-autocomplete');
            }

            $html .= '<script>
            kQuery(function($){
                $("'.$config->element.'").select2(Koowa.getSelect2Options('.$options.'));
            });</script>';

            static::setLoaded($signature);
        }

        return $html;
    }
184706
public function updateMetadata(SiteConfig $config, SiteTree $owner, &$metadata) {

		// decode into array
		$data = json_decode($owner->OpenGraphData, true);

		// check for data or throw an error
		if ($data) {

			// check if off
			if ($data['og:type'] !== 'off') {

				// Header
				$metadata .= $owner->MarkupComment('Open Graph');

				// Type
				$metadata .= $owner->MarkupOpenGraph('og:type', $data['og:type']);

				// URL
				$metadata .= $owner->MarkupOpenGraph('og:url', $owner->AbsoluteLink());

				// Site Name
				$siteName = ($data['og:site_name']) ? $data['og:site_name'] : $config->Title;
				$metadata .= $owner->MarkupOpenGraph('og:site_name', $siteName, true);

				// Title
				$title = ($data['og:title']) ? $data['og:title'] : $owner->Title;
				$metadata .= $owner->MarkupOpenGraph('og:title', $title, true);

				// Description
				$description = ($data['og:description']) ? $data['og:description'] : $owner->GenerateDescription();
				$metadata .= $owner->MarkupOpenGraph('og:description', $description, true);

				// Image
				if ($owner->OpenGraphImage()->exists()) {
					$metadata .= $owner->MarkupOpenGraph('og:image', $owner->OpenGraphImage()->getAbsoluteURL());
				}

			} else {

				// OFF
				$metadata .= $owner->MarkupComment('Open Graph [ off ]');

			}

		} else {

			// ERROR
			$metadata .= $owner->MarkupComment('Open Graph [ error ]');

		}

	}
827150
public function updateByParams( $params = [], $config = [] ) {

		$modelId	= $params[ 'modelId' ];
		$name		= $params[ 'name' ];
		$type		= $params[ 'type' ];

		$model = $this->getByNameType( $modelId, $name, $type );

		if( isset( $model ) ) {

			$model->value = $params[ 'value' ];

			return parent::update( $model, [
				'selective' => false,
				'attributes' => [ 'value' ]
			]);
		}
	}
1202048
public function update_config(&$data) {

        if (!empty($data->criteria_grade)) {
            $formatedgrade = unformat_float($data->criteria_grade_value);
            // TODO validation
            if (!empty($formatedgrade) && is_numeric($formatedgrade)) {
                $this->course = $data->id;
                $this->gradepass = $formatedgrade;
                $this->insert();
            }
        }
    }
370357
public function load(array $config, ContainerBuilder $container)
    {
        $config = $this->processConfiguration(new Configuration(), $config);
        $loader = new XMLFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/'));
        $loader->load('services.xml');
        $serviceDefDataFetcher = $container->getDefinition('chameleon_system_amazon_payment.config_provider');
        $serviceDefDataFetcher->replaceArgument(0, $config);
    }
588287
public function init( $config = NULL )
    {
        $this->mailer = new PHPMailer();

        foreach ( $config as $key => $value )
        {
            switch ( $key )
            {
                case 'from_email':
                    $this->mailer->From = $value;
                    break;

                case 'from_name':
                    $this->mailer->FromName = $value;
                    break;

                case 'is_html':
                    $this->mailer->isHTML( ( bool ) $value );
                    break;

                case 'smtp':
                    if ( !empty( $value ) )
                    {
                        // mark it as SMTP mail
                        $this->mailer->isSMTP();

                        $this->mailer->Host       = $value[ 'host' ];
                        $this->mailer->SMTPAuth   = $value[ 'auth' ];
                        $this->mailer->Username   = $value[ 'username' ];
                        $this->mailer->Password   = $value[ 'password' ];
                        $this->mailer->SMTPSecure = $value[ 'security' ];
                        $this->mailer->Port       = $value[ 'port' ];
                    }
                    break;

                case 'reply_to':
                    if ( !empty( $value ) )
                    {
                        $this->mailer->addReplyTo( $value[ 'email' ], $value[ 'name' ] );
                    }
                    break;

                default:
                    // do nothing
                    break;
            }
        }
    }
732615
public function setFieldFormatting(&$config)
    {
        $fieldFormatting = array();
        // Parse the column information
        foreach ($this->columns() as $source => $info) {
            if (isset($info['link']) && $info['link']) {
                $fieldFormatting[$source] = '<a href=\"$ObjectRecordLink\">$value</a>';
            }
            if (isset($info['text']) && $info['text']) {
                $fieldFormatting[$source] = $info['text'];
            }
        }
        return $fieldFormatting;
    }
475019
public function update( $model, $config = [] ) {

		$existingModel = $this->getByNameType( $model->parentId, $model->parentType, $model->name, $model->type );

		// Create if it does not exist
		if( !isset( $existingModel ) ) {

			return $this->create( $model );
		}

		if( isset( $model->valueType ) ) {

			$existingModel->copyForUpdateFrom( $model, [ 'valueType', 'value' ] );
		}
		else {

			$existingModel->copyForUpdateFrom( $model, [ 'value' ] );
		}

		$existingModel->update();

		return $existingModel;
	}
1241408
protected function doConnect($config)
    {
        $connectionString = "mysql:dbname={$config['database']}";
        
        if (isset($config['host'])) {
            $connectionString .= ";host={$config['host']}";
        }
        
        if (isset($config['port'])) {
            $connectionString .= ";port={$config['port']}";
        }

        if (isset($config['unix_socket'])) {
            $connectionString .= ";unix_socket={$config['unix_socket']}";
        }

        $connection = $this->container->build(
            '\PDO',
            array($connectionString, $config['username'], $config['password'], $config['options'])
        );

        if (isset($config['charset'])) {
            $connection->prepare("SET NAMES '{$config['charset']}'")->execute();
        }

        return $connection;
    }
855490
private function getServiceArgs(array $serviceHandler, array $serviceData): array
    {
        list($className, $method) = $serviceHandler;
        $rc = new \ReflectionClass($className);
        $rm = $rc->getMethod($method);
        $mps = $rm->getParameters();
        $params = $serviceData['params'] ?? [];

        if (empty($params)) {
            return [];
        }

        $index = 0;
        $args = [];
        foreach ($mps as $mp) {
            $name = $mp->getName();
            if (! isset($params[$index])) {
                break;
            }
            $args[$name] = $params[$index];
            $index++;
        }

        return $args;
    }
1335342
public function update( models\SwitchPort\Config $config){
        $service = sprintf( static::API_SWITCH_PORT_CONFIG, $config->getId());
        $rest = $this->getService( $service);
        $rest->PUT( $config);

        return $rest->getResult( models\SwitchPort\Config::class);
    }
268331
private function commitMsgProcess(Config $configData)
    {
        /** @var CommitMsg $commitMsgData */
        $commitMsgData = $configData->getCommitMsg();

        return $this->commitMsgProcessor->process($commitMsgData, $this->io);
    }
697363
public function updateMetadata(SiteConfig $config, SiteTree $owner, &$metadata)
    {

        // Facebook App ID
        if ($config->FacebookAppID) {

            $metadata .= $owner->MarkupComment('Facebook Insights');
            $metadata .= $owner->MarkupFacebook('fb:app_id', $config->FacebookAppID, false);

            // Admins (if App ID)
            foreach ($config->FacebookAdmins() as $admin) {
                if ($admin->FacebookProfileID) {
                    $metadata .= $owner->MarkupFacebook('fb:admins', $admin->FacebookProfileID, false);
                }
            }

        }

    }