Enriches field data before passing it on to the view.

@param array $data
@return array
@throws FormFieldDisplayException
498566
protected function decorateFieldData(array $data)
    {
        // Prevent causing errors in the view if the value is not castable to string.
        try {
            $data['value'] = (string) $data['value'];

        } catch (\Exception $e) {

            throw new FormFieldDisplayException(
                "Failed to cast value to string for field '{$this->field->key()}' "
                . "with source '{$this->field->source()}'",
                0,
                $e
            );
        }

        return $data;
    }
1224095
public function setAttributes(array $data)
	{
		$data = $this->stripResponseData($data);

		foreach ($data as $key => $value) {
			$this->setAttribute($key, $value);
		}

		return $this->getAttributes();
	}
659752
protected function decorateFieldData(array $data)
    {
        // Format the date value according to what the datepicker expects
        if ($data['value'] instanceof DateTime) {

            /** @var DateTime $value */
            $value = $data['value'];

            $format = array_get($data, 'options.format', $this->defaultDateFormat());

            if ($format) {
                $data['value'] = $value->format($format);
            }
        }

        // Prepare the momentJS date format, if not explicitly set
        if ( ! array_get($data, 'options.moment_format')) {

            $format       = array_get($data, 'options.format');
            $momentFormat = $format
                ?   $this->convertDateFormatToMoment($format)
                :   $this->defaultMomentDateFormat();

            array_set($data, 'options.moment_format', $momentFormat);
        }

        // Prepare special properties for datepicker
        if ($indicator = array_get($data, 'options.minimum_date')) {
            $data['minimumDate'] = $this->interpretDateIndicator($indicator);
        }
        if ($indicator = array_get($data, 'options.maximum_date')) {
            $data['maximumDate'] = $this->interpretDateIndicator($indicator);
        }

        $data['excludedDates'] = [];
        if (($indicators = array_get($data, 'options.excluded_dates')) && is_array($indicators)) {
            $data['excludedDates'] = array_map([ $this, 'interpretDateIndicator' ], $indicators);
        }

        return $data;
    }
310584
protected function filterFields(array $data): array
    {
        $fields = $this->getFilterFields();

        if ($fields === null) {
            return $data;
        }

        return array_intersect_key(
            $data,
            array_flip(
                iterator_to_array($fields)
            )
        );
    }
403967
final public function render($data = array())
    {
        $context = $this->getContext();
        $context->data       = array_merge($this->getData(), $data);
        $context->action     = 'render';
        $context->parameters = array();

        if ($this->invokeCommand('before.render', $context) !== false)
        {
            //Render the view
            $context->result = $this->_actionRender($context);
            $this->invokeCommand('after.render', $context);
        }

        return $context->result;
    }
629759
public function fill(array $data)
    {
        foreach ($data as $key => &$row) {
            $this->original = $value = array_get($row, $this->name);

            $value = $this->htmlEntityEncode($value);

            array_set($row, $this->name, $value);

            if ($this->isDefinedColumn()) {
                $this->useDefinedColumn();
            }

            if ($this->hasDisplayCallbacks()) {
                $value = $this->callDisplayCallbacks($this->original, $key);
                array_set($row, $this->name, $value);
            }
        }

        return $data;
    }
760850
public function convertFieldValueFromForm($data)
    {
        $country = array();

        // case if multiple is true
        if (is_array($data)) {
            foreach ($data as $countryCode) {
                if (array_key_exists($countryCode, $this->countryData)) {
                    $country[$countryCode] = $this->countryData[$countryCode];
                }
            }
        } else {
            if (array_key_exists($data, $this->countryData)) {
                $country[$data] = $this->countryData[$data];
            }
        }

        return new CountryValue((array) $country);
    }
382846
public function render(array $data = []): string
    {
        $this->addData($data);
        unset($data);
        \extract($this->data, EXTR_OVERWRITE);

        $__level__ = \ob_get_level();

        try {
            \ob_start();
            include $this->template;
            $content = \ob_get_clean();

            if (null !== $this->layoutName) {
                $layout = $this->engine->make($this->layoutName);
                $layout->sections = \array_merge($this->sections, ['content' => $content]);
                $content = $layout->render($this->layoutData);
            }

            return $content;
        } catch (\Throwable $e) {
            while (\ob_get_level() > $__level__) {
                \ob_end_clean();
            }

            throw $e;
        }
    }
366676
protected function parseTemplateData($data = [])
    {
        $error = $this->getThrown();

        $html = $this->renderHtmlError($error);
        while ($error = $error->getPrevious()) {
            $html .= '<h2>'.$this->translator()->translate('Previous error').'</h2>';
            $html .= $this->renderHtmlError($error);
        }

        $data['htmlErrorDetails']    = $html;
        $data['displayErrorDetails'] = $this->displayErrorDetails() && !empty($html);

        return parent::parseTemplateData($data);
    }
1295999
protected function getFields($data)
    {
        if (is_array($data)) {
            $fields = $data;
        } else {
            $this->checkData($data);
            $fields = $data->fields();
        }

        return $fields;
    }
1348117
public function convertFieldValueFromForm($data)
    {
        if (!is_array($data)) {
            $data = array();
            $data['url'] = null;
            $data['text'] = null;
        }

        return new UrlValue\Value($data['url'], $data['text']);
    }
97997
protected function decorateFieldData(array $data)
    {
        $strategy = array_get($this->field->options, 'strategy');

        $data['displayStrategy'] = null;
        $data['displaySource']  = $this->field->source() ?: $this->field->key();

        if ($strategy) {

            $instance = $this->getListDisplayFactory()->make($strategy);

            // todo: resolve attribute information if we can?
            //$instance->setAttributeInformation();
            $instance->setOptions(array_get($this->field->options, 'strategy_options', []));

            $data['displayStrategy'] = $instance;
            $data['displaySource'] = array_get($this->field->options, 'strategy_source', $data['displaySource']);
        }

        return $data;
    }
1073650
protected function _format(array $data) {
		foreach (['id', 'rev'] as $key) {
			if (isset($data["_{$key}"])) {
				$data[$key] = $data["_{$key}"];
				unset($data["_{$key}"]);
			}
		}
		return $data;
	}
1202281
private function formatCapabilities(array $data): array
    {
        $result = [];
        foreach ($data as $controller => $list) {
            $newList = [];
            foreach ($list as $type => $caps) {
                foreach ($caps as $cap) {
                    $field = $cap->getField();
                    $key = !empty($field) ? "${type}_(_${field}_)" : $type;
                    $newList[$key][] = $cap;
                }
            }
            $result[$controller] = $newList;
        }

        return $result;
    }
57152
public function populateValues($data)
    {
        /** @var FieldsetInterface|ElementInterface $element*/
        foreach ($this->elements as $element) {
            if (is_a($element, '\Slick\Form\FieldsetInterface')) {
                $element->populateValues($data);
            } else {
                foreach ($data as $name => $value) {
                    if ($element->getName() == $name) {
                        $element->setValue($value);
                    }
                }

            }
        }
    }
1255266
public function view($data)
    {
        if (array_key_exists('current', $data)) {
            $this->current = $data['current'];
        }
        if (array_key_exists('title_formatter', $data)) {
            $tf = $data['title_formatter'];
        }
        if (array_key_exists('descr_formatter', $data)) {
            $df = $data['descr_formatter'];
        }
        $i = 1;
        foreach ($this->steps as $step) {
            $sdiv = new Element('div');
            $sstyle = $this->getStyle('step');
            if ($i == $this->current) {
                $sdiv->addClass($this->getClass('current'));
                $sstyle .= $this->getStyle('current');
            } elseif ($i < $this->current) {
                $sdiv->addClass($this->getClass('completed'));
                $sstyle .= $this->getStyle('completed');
            }
            $sdiv->addClass($this->getClass('step'))->setAttribute('style', $sstyle);
            $title = array_key_exists('title', $step) ? $step['title'] : '';
            $descr = array_key_exists('descr', $step) ? $step['descr'] : '';
            if (isset($tf) && is_callable($tf)) {
                $title = $tf($title);
            }
            if (isset($df) && is_callable($df)) {
                $descr = $df($descr);
            }
            $contdiv = new Element('div');
            $contdiv->addClass($this->getClass('content'))->setAttribute('style', $this->getStyle('content'));
            $tdiv = new Element('div', new Text($title));
            $tdiv->addClass($this->getClass('title'))->setAttribute('style', $this->getStyle('title'));
            $ddiv = new Element('div', new Text($descr));
            $ddiv->addClass($this->getClass('descr'))->setAttribute('style', $this->getStyle('descr'));
            $contdiv->appendChild($tdiv)->appendChild($ddiv);
            $sdiv->appendChild($contdiv);
            $this->appendChild($sdiv);
            $i++;
        }
        return $this->render();
    }
1199415
public function replace(array $data) {
        $addFields = implode('`,`', array_keys($data));
        return $this->command()
            ->insertOrReplace("`{$addFields}`", Str::repeat('?', $data),
                array_values($data));
    }