Add custom parameters to pass to the JS via JSON.

@since  1.0.0
@access public
@return void
9830
public function to_json() {
		parent::to_json();

		// We need to make sure we have the correct image URL.
		foreach ( $this->choices as $value => $args ) {
			$this->choices[ $value ]['url'] = esc_url( sprintf( $args['url'], get_template_directory_uri(), get_stylesheet_directory_uri() ) );
		}
		$this->json['choices'] = $this->choices;
		$this->json['link']    = $this->get_link();
		$this->json['value']   = $this->value();
		$this->json['id']      = $this->id;
	}
1297564
public function renderJson()
    {
        $totalCount = $this->getDatasource()->totalCount();
        $rows = $this->getDatasource()->listRows();

        $tmpData = [];
        foreach ($rows as $row) {
            $tmp = [];

            $this->currentRow = new DefaultRow();
            if ($this->rowCallback instanceof \Closure) {
                $this->rowCallback->call($this, $row);
            }

            foreach ($this->getColumns() as $key => $column) {
                $this->currentColumn = $key;
                $tmp[$column->getName()] = $column->format($row);
            }

            $tmpData[] = $tmp;
        }

        $data = [
            'draw' => $this->getRequest()->get('draw'), // @todo param names configurable
            'recordsTotal' => $totalCount,
            'recordsFiltered' => $totalCount,
            'data' => $tmpData,
        ];

        header('Content-Type: application/json');
        echo json_encode($data);die;
    }
518362
public function addParameters(array $aParameters)
    {
        foreach($aParameters as $xParameter)
        {
            if($xParameter instanceof JsCall)
            {
                $this->addParameter(Jaxon::JS_VALUE, 'function(){' . $xParameter->getScript() . ';}');
            }
            else
            {
                $this->pushParameter(Parameter::make($xParameter));
            }
        }
    }
527575
public function prepareVars()
    {
        // Refresh the loaded data to support being modified by filterFields
        // @see https://github.com/octobercms/october/issues/2613
        if (!self::$onAddItemCalled) {
            $this->processExistingItems();
        }

        if ($this->previewMode) {
            foreach ($this->formWidgets as $widget) {
                $widget->previewMode = true;
            }
        }

        $this->vars['indexInputName'] = $this->indexInputName;
        $this->vars['groupInputName'] = $this->groupInputName;

        $this->vars['prompt'] = $this->prompt;
        $this->vars['formWidgets'] = $this->formWidgets;
        $this->vars['titleFrom'] = $this->titleFrom;
        $this->vars['minItems'] = $this->minItems;
        $this->vars['maxItems'] = $this->maxItems;

        $this->vars['useGroups'] = $this->useGroups;
        $this->vars['groupDefinitions'] = $this->groupDefinitions;
    }
290841
public function addOrUpdate()
    {
        $this->request->allowMethod(['post']);
        if (!$this->request->is('ajax')) {
            throw new \RuntimeException('Wrong type of request!');
        }
        $params = is_array($this->request->getData()) ? $this->request->getData() : [];
        /**
         * @var \Cake\Datasource\EntityInterface $translation
         */
        $translation = $this->Translations->getTranslations(
            $params['object_model'],
            $params['object_foreign_key'],
            [
                'language' => $params['language_id'],
                'toEntity' => true,
                'field' => $params['object_field'],
            ]
        );
        if (empty($translation)) {
            /**
             * @var \Cake\Datasource\EntityInterface $translation
             */
            $translation = $this->Translations->newEntity();
        }

        $translation = $this->Translations->patchEntity($translation, $params);
        $result = $this->Translations->save($translation);
        $body = (string)json_encode(!empty($result) ? true : false);
        $this->response = $this->response->withType('application/json')->withStringBody($body);
        $this->autoRender = false;
    }
1143634
private function bindParameters()
    {
        $bindedParameterReferences = array(implode('', $this->bindedTypes));
        $lobParameters = array();
        $null = null;

        foreach ($this->bindedParameters as $key => &$parameter) {
            if (isset($this->bindedTypes[$key - 1])
                && ($this->bindedTypes[$key - 1] === self::$mappedTypes[\PDO::PARAM_LOB])) {
                $lobParameters[$key - 1] = $parameter;
                $bindedParameterReferences[$key] = &$null;
            } else {
                $bindedParameterReferences[$key] = &$parameter;
            }
        }

        call_user_func_array(array($this->mysqliStatement, 'bind_param'), $bindedParameterReferences);

        foreach ($lobParameters as $key => $lobParameter) {
            rewind($lobParameter);

            while (!feof($lobParameter)) {
                $this->mysqliStatement->send_long_data(
                    $key,
                    fread($lobParameter, $this->connection->getMaxAllowedPacket())
                );
            }
        }
    }
379672
public function appendAdditionalParams(): void
    {
        if (!empty($this->additionalSearchFields)) {
            $this->normalSearchFields = array_merge_recursive($this->normalSearchFields, $this->additionalSearchFields);
        }

        if (!empty($this->additionalCustomSearchFields)) {
            $this->customSearchFields = array_merge_recursive($this->customSearchFields, $this->additionalCustomSearchFields);
        }

        if (!empty($this->additionalRelationSearchFields)) {
            $this->relationSearchFields = array_merge_recursive($this->relationSearchFields, $this->additionalRelationSearchFields);
        }
    }
525268
public function actionUpdate()
    {
        $data = [
            'f1' => $this->getContext()->getInput()->post('p1'),
            'f2' => $this->getContext()->getInput()->post('p2'),
            'id' => $this->getContext()->getInput()->get('id')
        ];

        $this->outputJson($data);
    }
165179
protected function parseInput()
    {
        foreach ($this->input as $key=>$value) {
            $this->applyParameter($key, $value);
        }
    }
936068
protected function initParams () {
		$params = array_merge($this->globalGet);
		if ($this->GetMethod() == self::METHOD_POST) {
			$postValues = [];
			if (count($this->globalPost) > 0) {
				$postValues = $this->globalPost;
			} else {
				$postValues = $this->initParamsCompletePostData();
			}
			$params = array_merge($params, $postValues);
		}
		$this->params = $params;
	}
461746
public function parameterize($attributes = [])
    {
        $parameters = (new Parameters($attributes))->toArray();

        $values = [];
        $replacements = [];

        foreach (array_dot($parameters) as $key => $value) {
            if ($this->isCallbackFunction($value, $key)) {
                $values[] = trim($value);
                array_set($parameters, $key, '%' . $key . '%');
                $replacements[] = '"%' . $key . '%"';
            }
        }

        $new = [];
        foreach ($parameters as $key => $value) {
            array_set($new, $key, $value);
        }

        $json = json_encode($new);

        $json = str_replace($replacements, $values, $json);

        return $json;
    }
60508
protected function populateParameters()
    {
        $this->parameters->clear();
        if ($this->hasParameters() && $this->node) {
            foreach ($this->node->value as $key => $node) {
                $attributes = $node->attributes();
                switch ((string) $attributes['type']) {
                    case 'list':
                        $value = array();
                        foreach ($node->children() as $c) {
                            $value[] = (string) $c;
                        }
                        break;

                    case 'int':
                        if (strlen($value = (string) $node[0])) {
                            $value = (int) $value;
                        } else {
                            $value = null;
                        }
                        break;

                    default:
                        $value = (string) $node[0];
                        break;
                }
                $this->parameters->set((string) $attributes['key'], $value);
            }
        }
    }
206432
private function LoadFunctionsFromJson()
    {
        $functions_def = Json::Decode(
            file_get_contents(
                $this->definitions_path . "functions.json"
            )
        );

        foreach($functions_def as $header => $namespaces)
        {
            $this->symbols->AddHeader($header);
            
            foreach($namespaces as $namespace => $functions)
            {
                foreach($functions as $function_name => $function_overloads)
                {
                    $function = new Element\FunctionElement($function_name);
                    
                    foreach($function_overloads as $index=>$function_overload)
                    {
                        $overload = new Element\Overload(
                            $function_overload["description"]
                        );
                        
                        $overload->SetReturnType(
                            new Element\ReturnType(
                                $function_overload["return_type"]
                            )
                        );
                        
                        if(isset($function_overload["parameters"]))
                        {
                            foreach($function_overload["parameters"] as $parameter)
                            {
                                if(!isset($parameter["value"]))
                                    $parameter["value"] = "";
                                
                                if(!isset($parameter["description"]))
                                    $parameter["description"] = "";

                                $param = new Element\Parameter(
                                    $parameter["name"], 
                                    $parameter["type"], 
                                    $parameter["value"],
                                    $parameter["description"]
                                );
                                
                                if(!isset($parameter["is_array"]))
                                    $param->is_array = false;
                                else
                                    $param->is_array = $parameter["is_array"];
                                
                                $overload->AddParameter($param);
                            }
                        }
                        
                        $function->AddOverload($overload);
                    }
                    
                    $this->symbols->headers[$header]->AddFunction(
                        $function,
                        $namespace
                    );
                }
            }
        }

        unset($functions_def);
    }
464432
protected function addRequestBody()
    {
        if (! empty($this->payload['parameters'])) {
            if (in_array($this->method, ['DELETE', 'PATCH', 'POST', 'PUT'])) {
                $this->addCurlOption(CURLOPT_POSTFIELDS, $this->formattedRequestBody());
            } elseif (is_array($this->payload['parameters'])) {
                // append parameters in the url
                $this->payload['url'] = sprintf('%s?%s', $this->payload['url'], $this->formattedRequestBody());
            }
        }
    }
100255
protected function registerJs()
	{
		//prepare values
		$values = Json::encode($this->values);

		//prepare config
		$config = [
			'type'=>$this->type,
			'height'=>$this->height,
		];
		if ($this->type !== self::SPARKLINE_BAR) {
			$config['width'] = $this->width;
		}
		$config = Json::encode(ArrayHelper::merge($this->sparklineConfig, $config));

		//create and register js
		$js = sprintf("$('#%s').sparkline(%s, %s);", $this->id, $values, $config);
		$this->view->registerJs($js);
	}
1061068
public function registerJs()
    {
        if (!isset($this->clientOptions['create']) && empty($this->items)) {
            $this->clientOptions['create'] = "function(input) { return { value: input, text: input };}";
        }
        $clientOptions = (count($this->clientOptions)) ? Json::encode($this->clientOptions) : '';
        $this->getView()->registerJs("jQuery('#{$this->options['id']}').selectize({$clientOptions});");
    }
1221924
public function addParameters(array $parameters, $overwrite = true)
    {
        $this->parameters = ArrayUtils::merge($this->parameters, $parameters, $overwrite);
        $this->links      = [];
    }