Retrieve the property's storage fields.

@param  mixed $val The value to set as field value.
@return PropertyField[]
335619
public function fields($val)
    {
        if (empty($this->fields)) {
            $this->generateFields($val);
        } else {
            $this->updatedFields($val);
        }

        return $this->fields;
    }
695040
protected function propertiesFromAttributes(): array
    {
        // Get all managed properties
        $propertyNames = $this->entityMap->getProperties();

        $propertyAttributes = array_only($this->attributes, $propertyNames);
        $attributesArray = array_except($this->attributes, $propertyNames);

        $attributesArrayName = $this->entityMap->getAttributesArrayName();

        if ($attributesArrayName) {
            $propertyAttributes[$attributesArrayName] = $attributesArray;
        }

        return $propertyAttributes;
    }
448820
public function getValidationRules(Property $property)
    {
        $key = $property->key;
        if (true === $property->canTranslate()) {
            return [
                [$key, ValuesValidator::class, 'skipOnEmpty' => true],
            ];
        } else {
            $rule = Property::dataTypeValidator($property->data_type) ?: 'safe';
            if ($property->allow_multiple_values) {
                return [
                    [$key, 'each', 'rule' => [$rule]],
                ];
            } else {
                return [
                    [$key, $rule],
                ];
            }
        }
    }
1158027
private function fieldVal($fieldIdent, $val)
    {
        if ($val === null) {
            return null;
        }

        if (is_scalar($val)) {
            return $this->storageVal($val);
        }

        if (isset($val[$fieldIdent])) {
            return $this->storageVal($val[$fieldIdent]);
        } else {
            return null;
        }
    }
740041
public function storageVal($val)
    {
        if ($val === null || $val === '') {
            // Do not encode NULL values
            return null;
        }

        if ($val instanceof Translation) {
            $val = (string)$val;
        }

        if (!is_scalar($val)) {
            return json_encode($val, JSON_UNESCAPED_UNICODE);
        }

        return $val;
    }
779231
public function storageVal($val)
    {
        $mode = $this->storageMode();

        if ($mode === self::STORAGE_MODE_INT) {
            return $this->intVal($val);
        } else {
            return $this->stringVal($val);
        }
    }
692185
public function getFormFields(): array
    {
        $properties = $this->getProperties();

        $fields = array_diff($properties, ['id']);

        $fieldsWithTypes = [];
        foreach ($fields as $field) {
            $fieldsWithTypes[$field] = null;
        }

        return $fieldsWithTypes;
    }
523739
public function save($val)
    {
        $val = parent::save($val);

        if ($this->multiple()) {
            $proto = $this->structureProto();
            if ($proto instanceof ModelInterface) {
                $objs = (array)$this->structureVal($val);
                $val  = [];
                if (!empty($objs)) {
                    $val  = [];
                    foreach ($objs as $obj) {
                        $obj->saveProperties();
                        $val[] = $obj->data();
                    }
                }
            }
        } else {
            $obj = $this->structureVal($val);
            if ($obj instanceof ModelInterface) {
                $obj->saveProperties();
                $val = $obj->data();
            }
        }

        return $val;
    }
408515
public static function exportArray($val)
    {
        if (isset($val[0])) {
            $array = json_encode($val, JSON_PRETTY_PRINT);
        } else {
            $array = var_export($val, true);
            $array = trim($array, ' array()');
            $array = '[' . $array . ']';
            $array = str_replace(["array (\n", "),\n"], ["[\n", "],\n"], $array);
        }
        return $array;
    }
1132872
public function structProperties()
    {
        $property = $this->storageProperty();

        if ($property) {
            $struct = $property->structureMetadata();

            if (isset($struct['properties'])) {
                return $struct['properties'];
            }
        }

        return [];
    }
550246
private function mapToRelationshipAndAttribute(string $field): array
    {
        $rootSchema = $this->getRootSchema();
        if ($rootSchema->hasAttributeMapping($field) === true) {
            $relationship = null;
            $schema       = $rootSchema;
            $attribute    = new Attribute($field, $schema);

            return [$relationship, $attribute];
        } elseif ($rootSchema->hasRelationshipMapping($field) === true) {
            $fromSchema   = $rootSchema;
            $toSchema     = $this->getJsonSchemas()->getRelationshipSchema(get_class($fromSchema), $field);
            $relationship = new Relationship($field, $fromSchema, $toSchema);
            $attribute    = new Attribute($toSchema::RESOURCE_ID, $toSchema);

            return [$relationship, $attribute];
        } elseif (count($mightBeRelAndAttr = explode('.', $field, 2)) === 2) {
            // Last chance. It could be a dot ('.') separated relationship with an attribute.

            $mightBeRel  = $mightBeRelAndAttr[0];
            $mightBeAttr = $mightBeRelAndAttr[1];

            $fromSchema = $rootSchema;
            if ($fromSchema->hasRelationshipMapping($mightBeRel)) {
                $toSchema = $this->getJsonSchemas()->getRelationshipSchema(get_class($fromSchema), $mightBeRel);
                if ($toSchema::hasAttributeMapping($mightBeAttr) === true) {
                    $relationship = new Relationship($mightBeRel, $fromSchema, $toSchema);
                    $attribute    = new Attribute($mightBeAttr, $toSchema);

                    return [$relationship, $attribute];
                }
            }
        }

        $error = $this->createQueryError($field, static::MSG_ERR_INVALID_FIELD);
        throw new InvalidQueryParametersException($error);
    }
1340824
public function toArray()
    {
        return [
            'field' => $this->getRawProperty('field'),
            'from-field' => $this->getRawProperty('fromField'),
            'to-field' => $this->getRawProperty('toField'),
            'is-deleted' => $this->isDeleted,
            'is-added' => $this->isAdded,
        ];
    }
464032
public function pluckFields($property = 'name')
    {
        $names = [];

        if ($this->hasFields()) {
            foreach ($this->getFields() as $field) {
                if (property_exists($field, $property)) {
                    $names[] = $field->{$property};
                }
            }
        }

        return $names;
    }
1275757
protected function getCompactVariablesFor(array $fields, $modelName, $view)
    {
        $variables = [];

        if (!empty($modelName)) {
            $variables[] = $modelName;
        }

        if ($view == 'form') {
            $collections = $this->getRelationCollections($fields, $view);

            foreach ($collections as $collection) {
                $variables[] = $collection->getCollectionName();
            }
        }

        return $this->getCompactVariables($variables);
    }
915930
protected function getFieldsValues(): array
    {
        $values = [];
        foreach ($this as $propName => $propValue) {
            if ($this->hasColumn($propName) && ! self::isInPrimaryKey($propName)) {
                $values[$propName] = $propValue;
            }
        }

        return $values;
    }
794222
public function getDefaultValuesForProperties()
    {
        $this->initialize();
        if (!isset($this->fullConfiguration['properties'])) {
            return [];
        }

        $defaultValues = [];
        foreach ($this->fullConfiguration['properties'] as $propertyName => $propertyConfiguration) {
            if (isset($propertyConfiguration['defaultValue'])) {
                $type = isset($propertyConfiguration['type']) ? $propertyConfiguration['type'] : '';
                switch ($type) {
                    case 'DateTime':
                        $defaultValues[$propertyName] = new \DateTime($propertyConfiguration['defaultValue']);
                    break;
                    default:
                        $defaultValues[$propertyName] = $propertyConfiguration['defaultValue'];
                }
            }
        }

        return $defaultValues;
    }
96605
public function Field($properties = [])
    {
        // Requirements::css(SAPPHIRE_DIR . '/css/CheckboxSetField.css');

        $source = $this->source;
        $values = $this->value;
        if ($values instanceof MultiValueField) {
            $values = $values->getValues();

            if ($this->storeKeys && is_array($values)) {
                // use the keys instead, as that's how we've stored things
                $values = array_keys($values);
            }
        }

        // Get values from the join, if available
        if (is_object($this->form)) {
            $record = $this->form->getRecord();
            if (!$values && $record && $record->{$this->name}) {
                $prop = $record->{$this->name};
                if ($prop && $prop instanceof MultiValueField) {
                    $values = $prop->getValues();
                }
            }
        }

        // Source is not an array
        if (!is_array($source) && !is_a($source, 'SQLMap')) {
            if (is_array($values)) {
                $items = $values;
            } else {
                // Source and values are DataObject sets.
                if ($values && is_a($values, 'DataObjectSet')) {
                    foreach ($values as $object) {
                        if (is_a($object, DataObject::class)) {
                            $items[] = $object->ID;
                        }
                    }
                } elseif ($values && is_string($values)) {
                    $items = explode(',', $values);
                    $items = str_replace('{comma}', ',', $items);
                }
            }
        } else {
            // Sometimes we pass a singluar default value thats ! an array && !DataObjectSet
            if (is_a($values, 'DataObjectSet') || is_array($values)) {
                $items = $values;
            } else {
                $items = explode(',', $values);
                $items = str_replace('{comma}', ',', $items);
            }
        }

        if (is_array($source)) {
            unset($source['']);
        }

        $odd     = 0;
        $options = '';

        if ($source == null) {
            $source  = [];
            $options = "<li>"
                ._t('MultiValueCheckboxField.NoOptions', 'No options available')
                ."</li>";
        }

        if ($source)
                foreach ($source as $index => $item) {
                if (is_a($item, DataObject::class)) {
                    $key   = $item->ID;
                    $value = $item->Title;
                } else {
                    $key   = $index;
                    $value = $item;
                }

                $odd        = ($odd + 1) % 2;
                $extraClass = $odd ? 'odd' : 'even';
                $extraClass .= ' val'.str_replace(' ', '', $key);
                $itemID     = $this->id().'_'.preg_replace('/[^a-zA-Z0-9]+/', '', $key);
                $checked    = '';
                if (isset($items)) {
                    $checked = (in_array($key, $items) || in_array($key, $this->defaultItems)) ? ' checked="checked"' : '';
                }

                $disabled = ($this->disabled || in_array($key, $this->disabledItems)) ? $disabled = ' disabled="disabled"'
                        : '';
                $options  .= "<li class=\"$extraClass\"><input id=\"$itemID\" name=\"$this->name[$key]\" type=\"checkbox\" value=\"$key\"$checked $disabled class=\"checkbox\" /> <label for=\"$itemID\">$value</label></li>\n";
            }

        return "<ul id=\"{$this->id()}\" class=\"optionset checkboxsetfield{$this->extraClass()}\">\n$options</ul>\n";
    }