Provide rendered value

Supported options:

* valueLabels - array of two strings to use for labels.
Defaults: '0' for false, '1' for true.

@param mixed $data Data to use for provision
@param array $options Options to use for provision
@return mixed
766477
public function provide($data = null, array $options = [])
    {
        $valueLabels = [
            0 => '0',
            1 => '1',
        ];

        if (empty($options['valueLabels'])) {
            $options['valueLabels'] = $valueLabels;
        }

        if (!is_array($options['valueLabels'])) {
            throw new InvalidArgumentException("valueLabels option is not an array");
        }

        if (count($options['valueLabels']) < 2) {
            throw new InvalidArgumentException("valueLabels option has insufficient items");
        }

        $result = $data ? $options['valueLabels'][1] : $options['valueLabels'][0];
        $result = (string)$result;

        return $result;
    }
1306346
public function resolveDataValue($data)
    {
        if ($data instanceof Data) {

            return $this->setData($data);

        } elseif (is_array($data)) {

            return $this->setData(new Data($data));
        }

        throw new \InvalidArgumentException(
            "Data must be View\Data or array value"
        );
    }
76066
public function label($name, $value = null, array $options = [])
    {
        $options = $this->getLabelOptions($options);

        $escapeHtml = false;

        if (is_array($value) and isset($value['html'])) {
            $value = $value['html'];
        } elseif ($value instanceof HtmlString) {
            $value = $value->toHtml();
        } else {
            $escapeHtml = true;
        }

        return $this->form->label($name, $value, $options, $escapeHtml);
    }
45401
public function provide($data = null, array $options = [])
    {
        if (empty($data) && ! empty($options['entity'])) {
            $data = $options['entity'];
        }

        if ($data instanceof EntityInterface) {
            return $this->provideFromEntity($data, $this->config->getField());
        }

        if ($data instanceof RequestInterface) {
            return $this->provideFromRequest($data, $this->config->getField());
        }

        return $data;
    }
496380
protected function encodeValue($data)
	{
	    // xml wrap entity_element label
	    if ($this->options['data_format'] == 'xml') {
	        $data = $this->formatter->wrap($data, $this->options['entity_element']);
	    }
	    return $this->formatter->encode($data);
	}
249733
public function deserialize(array $data, Options $options = null)
    {
        if (empty($options)) {
            $options = $this->optionsRepo->findOneBy(['id' => $data['id']]);
        }
        if (empty($options)) {
            $options = new Options();
        }
        if (isset($data['user'])) {
            $user = isset($data['user']['id']) ? $this->userRepo->findOneBy(['uuid' => $data['user']['id']]) : null;
            $options->setUser($user);
        }
        if (isset($data['data'])) {
            $options->setOptions($data['data']);
        }

        return $options;
    }
899384
public function provide($data = null, array $options = [])
    {
        $selectListItems = $this->config->getProvider('selectOptions');
        $selectListItems = new $selectListItems($this->config);
        $listName = $options['fieldDefinitions']->getLimit();

        $selectOptions = $selectListItems->provide($listName, []);
        foreach ($selectOptions as $k => $v) {
            $selectOptions[$k] = sprintf(CountryValueRenderer::ICON_HTML, strtolower($k), $v);
        }

        $options['selectOptions'] = $selectOptions;
        $options['element'] = 'CsvMigrations.FieldHandlers/CountryFieldHandler/input';

        return parent::provide($data, $options);
    }
468615
protected function _entity(array $data = null, array $options = [])
    {
        if ($this->_entity && empty($data)) {
            return $this->_entity;
        }

        return $this->_table()->newEntity($data, $options);
    }
82624
public function provide($data = null, array $options = [])
    {
        $result = [];

        $combinedFields = $this->config->getProvider('combinedFields');
        $combinedFields = new $combinedFields($this->config);
        $combinedFields = $combinedFields->provide($data, $options);

        $view = $this->config->getView();
        foreach ($combinedFields as $suffix => $fieldOptions) {
            $fieldName = $this->config->getField() . '_' . $suffix;

            $config = new $fieldOptions['config']($fieldName, $this->config->getTable());

            $provider = $config->getProvider('renderName');
            $provider = new $provider($config);
            $options['label'] = $provider->provide();

            $provider = $config->getProvider('searchOptions');
            $provider = new $provider($config);

            $type = Inflector::underscore(str_replace('Config', '', (new \ReflectionClass($config))->getShortName()));
            $options['fieldDefinitions']->setName($fieldName);
            $options['fieldDefinitions']->setType($type);

            $result = array_merge($result, (array)$provider->provide($data, $options));
        }

        return $result;
    }
240899
public function stringToObject($data, $options = array())
	{
		if (is_object($data))
		{
			return $data;
		}

		$data = trim($data);

		// Try to parse, catching exception if it fails
		try
		{
			// Parse config string
			$parsed = SymfonyYaml::parse($data, true);
		}
		catch (Exception $e)
		{
			// Throw an exception Hubzero knows how to catch
			throw new ParseException(
				array(
					'message'   => 'Error parsing YAML',
					'exception' => $e,
				)
			);
		}

		if (!$parsed)
		{
			$parsed = '';
		}

		return (is_string($parsed) ? $parsed : $this->toObject($parsed));
	}
57986
public function computeLabel(DataInterface $data, $value, array $options)
    {
        $choiceLabel = array_key_exists('choice_label', $options) ? $options['choice_label'] : null;
        if (null === $choiceLabel) {
            return (string) $data;
        }
        if (is_string($choiceLabel)) {
            try {
                return (string) $this->accessor->getValue($data, $choiceLabel);
            } catch (\Exception $e) {
                throw new \UnexpectedValueException(
                    "Unable to compute label with given 'choice_label' {$choiceLabel}",
                    0,
                    $e
                );
            }
        }
        if (is_callable($choiceLabel)) {
            return (string) $choiceLabel($data, $value, $options);
        }

        throw new \UnexpectedValueException("Unable to compute label with unknown 'choice_label' option");
    }
662722
public function provide($data = null, array $options = [])
    {
        $result = parent::provide($data, $options);
        $errorResponse = sprintf(parent::VALUE_NOT_FOUND_HTML, $data);

        //In case the result is empty or its the same with the errorResponse then return the result
        if (empty($result) || $errorResponse == $result) {
            return $result;
        } else {
            return sprintf(static::ICON_HTML, strtolower($data), $result);
        }
    }
1234478
public function provide($data = null, array $options = [])
    {
        $result = parent::provide($data, $options);
        $errorResponse = sprintf(parent::VALUE_NOT_FOUND_HTML, $data);

        //In case the result is the same with the errorResponse then return the error
        if (empty($result) || $errorResponse == $result) {
            return $result;
        } else {
            return static::getIcon($data, $result);
        }
    }
49686
public function provide($data = null, array $options = [])
    {
        $field = $this->config->getField();

        $template = $this->getBasicTemplate('string');
        $defaultOptions = $this->getDefaultOptions($data, $options);
        $defaultOptions['input'] = ['content' => $template];

        $result[$field] = $defaultOptions;

        $list = $options['fieldDefinitions']->getListName();

        $table = TableRegistry::get('CsvMigrations.Dblists');
        Assert::isInstanceOf($table, DblistsTable::class);

        $selectOptions = $table->getOptions($list);

        $params = [
            'field' => $field,
            'name' => '{{name}}',
            'type' => 'select',
            'label' => false,
            'required' => $options['fieldDefinitions']->getRequired(),
            'value' => '{{value}}',
            'options' => $selectOptions,
            'extraClasses' => (!empty($options['extraClasses']) ? implode(' ', $options['extraClasses']) : ''),
            'attributes' => empty($options['attributes']) ? [] : $options['attributes'],
        ];

        $defaultElement = 'CsvMigrations.FieldHandlers/DblistFieldHandler/input';
        $element = empty($options['element']) ? $defaultElement : $options['element'];

        foreach ($selectOptions as $key => $value) {
            $result[$field]['options'][] = ['value' => $key, 'label' => $value];
        }
        $result[$field]['input'] = ['content' => $this->renderElement($element, $params)];

        return $result;
    }
1256199
public function setOptionValue($optionName, $optionValue, array $values = [])
    {
        if (!isset($this->options[$optionName])) {
            $this->options[$optionName] = [
                'value' => $optionValue,
                'values' => $values,
            ];
        } elseif (!empty($this->options[$optionName]['values']) && !in_array($optionValue, $this->options[$optionName]['values'], true)) {
            throw new \InvalidArgumentException(sprintf('Invalid value "%s" for option "%s", possible values: %s', $optionValue, $optionName, implode(', ', $this->options[$optionName]['values'])), __LINE__);
        } else {
            $this->options[$optionName]['value'] = $optionValue;
        }
        return $this;
    }
1133208
public function provide($data = null, array $options = [])
    {
        $result = null;

        if (empty($data)) {
            return $result;
        }

        $relatedProperties[] = $this->_getRelatedProperties($options['fieldDefinitions']->getLimit(), $data);

        if (!empty($relatedProperties[0]['config']['parent']['module'])) {
            array_unshift(
                $relatedProperties,
                $this->_getRelatedParentProperties($relatedProperties[0])
            );
        }

        $elementName = 'CsvMigrations.FieldHandlers/RelatedFieldHandler/view';
        $params = [
            'relatedProperties' => $relatedProperties,
            'options' => $options,
        ];

        return $this->renderElement($elementName, $params);
    }
1130643
public static function stringToStruct($data, array $options = [])
    {
        $assoc = StructureHelper::getValue($options, 'assoc', false);
        $depth = StructureHelper::getValue($options, 'depth', 512);
        $option = StructureHelper::getValue($options, 'options', 0);

        return json_decode(trim($data), $assoc, $depth, $option);
    }