Adds _label field to serialized array if model has a __toString() method.

@inheritdoc
430751
public function toArray(array $fields = [], array $expand = [], $recursive = true)
    {
        $data = parent::toArray($fields, $expand, $recursive);

        if (method_exists($this, '__toString')) {
            $data['_label'] = $this->__toString();
        }
        return $data;
    }
89694
private function updateNonTableMode(ModelToLabelEvent $event, $value)
    {
        if (null === $value) {
            return;
        }

        // HACK: we need to escape all % chars but preserve the %s and the like.
        $value = \str_replace('%', '%%', $value);
        $value = \preg_replace(
            '#%(%([0-9]+\$)?(\'.|0| )?-?([0-9]+)?(.[0-9]+)?(b|c|d|e|E|f|F|g|G|o|s|u|x|X))#',
            '\\1',
            $value
        );

        $event->setLabel($value);
    }
853587
public function addFormField(string $name): void
    {
        $options = $this->formOptions['fields'][$name];
        $wrapper = $this->createWrapper();
        $label = '';

        if (isset($options['label']['text'])) {
            $label = $this->createLabel($options['label']['text'], $name);

            unset($options['label']['text']);
        }

        $input = HtmlTag::createElement('input')
            ->set('type', $options['input']['type'] ?? 'text')
            ->set('id', $name)
            ->set('name', $name);

        $caption = '';

        if (isset($options['caption']['text'])) {
            $input->set('aria-describedby', $name . '_caption');
            $caption = $this->createCaption($options['caption']['text'], $name);

            unset($options['caption']['text']);
        }

        $elements = [
            'wrapper' => $wrapper,
            'label'   => $label,
            'input'   => $input,
            'caption' => $caption
        ];

        foreach ($elements as $name => $element) {
            $$name = $this->assignOptionsToElement($options, $name, $element);
        }

        if (in_array($options['input']['type'] ?? 'text', ['checkbox', 'radio', 'file'])) {
            $wrapper->addElement($input);
            $wrapper->addElement($label);
        } else {
            $wrapper->addElement($label);
            $wrapper->addElement($input);
        }

        $wrapper->addElement($caption);

        echo $wrapper;
    }
514222
protected function setFields($method = 'addColumn')
    {
        $fields = $this->convertFieldsToArray();

        $template = array_map(array($this, $method), $fields);

        return implode("\n\t\t\t", $template);
    }
885801
def _add_column(self, label, field):
        
        # Don't call this directly.
        assert self.headers is not None
        cols = 0
        if len(self._headers) > 0:
            cols = max([int(c.cell.col) for c in self._headers])
        new_col = cols + 1
        if int(self._ws.col_count.text) < new_col:
            self._ws.col_count.text = str(new_col)
            self._update_metadata()

        cell = self._service.UpdateCell(1, new_col, label,
                                        self._ss.id, self.id)
        self._headers.append(cell)
112575
public function modelAsNode($labels = null)
    {
        if (is_null($labels))
        {
            return 'n';
        } elseif (is_array($labels))
        {
            $labels = reset($labels);
        }

        return mb_strtolower($labels);
    }
657551
private function AddLabelField()
    {
        $name = 'Label';
        $field = Fields\Input::Text($name, $this->checkbox->GetLabel());
        $this->AddField($field);
    }
1371270
public function updateFieldLabels(&$labels)
    {
        parent::updateFieldLabels($labels);

        $statics = self::$collectorCache[$this->ownerBaseClass];
        foreach ($statics as $field => $type) {
            $parts = explode(TRANSLATABLE_COLUMN_SEPARATOR, $field);
            $labels[$field] = FormField::name_to_label($parts[0]) . ' (' . $parts[1] . ')';
        }
    }
1056207
public function addSecondaryFields(string $label, string $value): self
    {
        $this->secondaryFields[] = $this->setLabelValue($label, $value);

        $this->isValidArray($this->secondaryFields, 5);

        return $this;
    }
801872
public function unserialize($serialized)
    {
        $data = unserialize($serialized);

        $this->active =  $data['active'];
        $this->defaultValue =  $data['defaultValue'];
        $this->label=  $data['label'];
        $this->validFor=  $data['validFor'];
        $this->value=  $data['value'];
    }
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;
    }
200302
public function add($name, $label = '', array $attributes = array(), array $rules = array())
	{
		if ($name instanceof Fieldset_Field)
		{
			if ($name->name == '' or $this->field($name->name) !== false)
			{
				throw new \RuntimeException('Fieldname empty or already exists in this Fieldset: "'.$name->name.'".');
			}

			$name->set_fieldset($this);
			$this->fields[$name->name] = $name;
			return $name;
		}
		elseif ($name instanceof Fieldset)
		{
			if (empty($name->name) or $this->field($name->name) !== false)
			{
				throw new \RuntimeException('Fieldset name empty or already exists in this Fieldset: "'.$name->name.'".');
			}

			$name->set_parent($this);
			$this->fields[$name->name] = $name;
			return $name;
		}

		if (empty($name) || (is_array($name) and empty($name['name'])))
		{
			throw new \InvalidArgumentException('Cannot create field without name.');
		}

		// Allow passing the whole config in an array, will overwrite other values if that's the case
		if (is_array($name))
		{
			$attributes = $name;
			$label = isset($name['label']) ? $name['label'] : '';
			$rules = isset($name['rules']) ? $name['rules'] : array();
			$name = $name['name'];
		}

		// Check if it exists already, if so: return and give notice
		if ($field = $this->field($name))
		{
			\Error::notice('Field with this name exists already in this fieldset: "'.$name.'".');
			return $field;
		}

		$this->fields[$name] = new \Fieldset_Field($name, $label, $attributes, $rules, $this);

		return $this->fields[$name];
	}
700060
public function addMessage($message, $label = 'info', $isString = true)
    {
        if (!is_string($message)) {
            $message = $this->getDataFormatter()->formatVar($message);
            $isString = false;
        }
        $this->messages[] = array(
            'message' => $message,
            'is_string' => $isString,
            'label' => $label,
            'time' => microtime(true)
        );
    }
875475
public function serialize(ModelInterface $model, $fields)
    {
        $result = array();

        foreach ($fields as $field) {
            $value = $field->getValue($model);
            if (is_string($value)) {
                $value = utf8_encode($value);
            }

            $result[$field->getName()] = $value;
        }

        return $result;
    }
626878
protected function encodeField($label, $value, array $context)
    {
        $convertedLabel = $this->convertEncoding($label, $context);
        $strict         = $context['strict'];

        if ($strict) {
            $this->assertLabel($convertedLabel);
        }

        if ($value === null) {
            $value = '';
        }

        if (is_object($value) && method_exists($value, '__toString')) {
            $value = "$value";
        }

        if (is_scalar($value)) {
            $convertedValue = $this->convertEncoding($value, $context);

            if ($strict) {
                $this->assertValue($convertedValue);
            }

            return sprintf('%s%s%s', $convertedLabel, static::DELIMITER, $convertedValue);
        }

        throw new \RuntimeException(sprintf('Could not serialize LTSV value of label:%s.', $label));
    }
1317613
public function label( string $name ) {
		return $this->$name ? get_field_object( $name, $this->ID )['label'] : FALSE;
	}
590281
protected function filterString($field, $details, $label, $message) {
        if (!(is_string($this->getValue($field)) || is_numeric($this->getValue($field)))) {
            throw new \Exception($message ? $message : $this->translate("$label must be string!"));
        }
        $this->setValue($field, $this->getValue($field) . '');
        if (isset($details['trim']) || in_array('trim', $details)) {
            $this->setValue($field, trim($this->getValue($field)));
        }
        if (isset($details['min']) && strlen($this->getValue($field)) < $details['min']) {
            throw new \Exception($message ? $message : $this->translate("$label must have at least $details[min] characters!"));
        }
        if (isset($details['max']) && strlen($this->getValue($field)) > $details['max']) {
            throw new \Exception($message ? $message : $this->translate("$label must have less than $details[min] characters!"));
        }
        $wordsCount = count(explode(' ', str_replace(array(',', ';', ':', '!', '?', '$', '%', '^', '/', '*', '(', ')', '[', ']', '@', '`', '~', '\'', '\\', '"', '}', '{', "\n"), ' ', $this->getValue($field))));
        if (isset($details['min_words']) && $wordsCount < $details['min_words']) {
            throw new \Exception($message ? $message : $this->translate("$label must have at least $details[min_words] words!"));
        }
        if (isset($details['max_words']) && $wordsCount > $details['max_words']) {
            throw new \Exception($message ? $message : $this->translate("$label must have less than $details[max_words] words!"));
        }
        $lines = count(explode("\n", $this->getValue($field)));
        if (isset($details['min_lines']) && $lines < $details['min_lines']) {
            throw new \Exception($message ? $message : $this->translate("$label must have at least $details[min_lines] lines!"));
        }
        if (isset($details['max_lines']) && $lines > $details['max_lines']) {
            throw new \Exception($message ? $message : $this->translate("$label must have less than $details[max_lines] lines!"));
        }
        return true;
    }