Serializes a Field entity for the JSON api.

@param Field $field   - the field to serialize
@param array $options - a list of serialization options

@return array - the serialized representation of the field
495550
public function serialize(Field $field, array $options = [])
    {
        $serialized = [
            'id' => $field->getUuid(),
            'autoId' => $field->getId(),
            'name' => $field->getName(),
            'label' => $field->getName(),
            'type' => $field->getFieldType(),
            'required' => $field->isRequired(),
            'help' => $field->getHelp(),
            'restrictions' => [
                'isMetadata' => $field->getIsMetadata(),
                'locked' => $field->isLocked(),
                'lockedEditionOnly' => $field->getLockedEditionOnly(),
                'hidden' => $field->isHidden(),
                'order' => $field->getOrder(),
            ],
        ];

        if (count($field->getDetails()) > 0) {
            $serialized['options'] = $field->getDetails();
        }
        if (in_array($field->getType(), [FieldFacet::CHOICE_TYPE, FieldFacet::CASCADE_TYPE])) {
            $serialized['options']['choices'] = array_map(function (FieldFacetChoice $choice) {
                return $this->fieldFacetChoiceSerializer->serialize($choice);
            }, $field->getFieldFacet()->getRootFieldFacetChoices());
        }
        if (!in_array(Options::SERIALIZE_MINIMAL, $options)) {
            $serialized = array_merge($serialized, [
                'fieldFacet' => $this->fieldFacetSerializer->serialize($field->getFieldFacet()),
            ]);
        } else {
            $serialized = array_merge($serialized, [
                'fieldFacet' => [
                    'id' => $field->getUuid(),
                ],
            ]);
        }

        return $serialized;
    }
1368640
public function relationRender($field, $options = [])
    {
        /*
         * Session key
         */
        if (is_string($options)) {
            $options = ['sessionKey' => $options];
        }

        if (isset($options['sessionKey'])) {
            $this->sessionKey = $options['sessionKey'];
        }

        /*
         * Apply options and extra config
         */
        $allowConfig = ['readOnly', 'recordUrl', 'recordOnClick'];
        $extraConfig = array_only($options, $allowConfig);
        $this->extraConfig = $extraConfig;
        $this->applyExtraConfig($extraConfig, $field);

        /*
         * Initialize
         */
        $this->validateField($field);
        $this->prepareVars();

        /*
         * Determine the partial to use based on the supplied section option
         */
        $section = $options['section'] ?? null;
        switch (strtolower($section)) {
            case 'toolbar':
                return $this->toolbarWidget ? $this->toolbarWidget->render() : null;

            case 'view':
                return $this->relationMakePartial('view');

            default:
                return $this->relationMakePartial('container');
        }
    }
866545
protected function _buildValue($field, $options, $params)
    {
        $string = null;

        if ($options['operator'] === 'LIKE') {
            $string .= '%';
        }
        $string .= Hash::get($params, $options['column']);
        if ($options['operator'] === 'LIKE') {
            $string .= '%';
        }
        return $string;
    }
263499
public function serialize(Category $category, array $options = [])
    {
        $serialized = [
            'id' => $category->getUuid(),
            'name' => $category->getName(),
            'details' => $category->getDetails(),
        ];

        if (!in_array(Options::SERIALIZE_MINIMAL, $options)) {
            $serialized = array_merge($serialized, [
                'managers' => array_map(function (User $manager) {
                    return $this->userSerializer->serialize($manager, [Options::SERIALIZE_MINIMAL]);
                }, $category->getManagers()),
            ]);
            $serialized = array_merge($serialized, [
                'fieldsValues' => array_map(function (FieldChoiceCategory $fcc) {
                    return $this->fieldChoiceCategorySerializer->serialize($fcc);
                }, $this->fieldChoiceCategoryRepo->findBy(['category' => $category])),
            ]);
        }

        return $serialized;
    }
1222255
public function toJson($options = 0)
    {
        if ($this->object instanceof Jsonable) {
            return $this->object->toJson();
        }

        return json_encode($this->object);
    }
1347110
function GetOptions($field) {
		$this->LoadSchema();
		if (
			isset($this->schema[$field]) && // A valid field
			isset($this->schema[$field]['options']) // Valid options
		)
			return $this->schema[$field]['options'];
	}
1241491
public function getArrayTypeDeclarationSQL(array $field, array $options)
    {
        $type = array_key_exists('type', $options) ? $options['type'] : Type::STRING;
        return 'ARRAY ( ' . Type::getType($type)->getSQLDeclaration($field, $this) . ' )';
    }
1127660
private function serializeObjects(Item $question, array $options = [])
    {
        return array_values(array_map(function (ItemObject $object) use ($options) {
            return $this->itemObjectSerializer->serialize($object, $options);
        }, $question->getObjects()->toArray()));
    }
1216794
public function serialize(Options $options)
    {
        return [
            'id' => $options->getId(),
            'data' => $options->getOptions(),
            'user' => $this->userSerializer->serialize($options->getUser()),
        ];
    }
1163559
public function serialize(PanelFacet $panel, array $options = [])
    {
        return [
            'id' => $panel->getUuid(),
            'title' => $panel->getName(),
            'position' => $panel->getPosition(),
            'roles' => $this->serializeRoles($panel->getPanelFacetsRole()->toArray()),
            //deprecated
            'display' => [
                'collapsed' => $panel->isDefaultCollapsed(),
            ],
            'defaultOpened' => true,
            'fields' => array_map(function (FieldFacet $fieldFacet) use ($options) { // todo check user rights
                return $this->ffSerializer->serialize($fieldFacet, $options);
            }, $panel->getFieldsFacet()->toArray()),
        ];
    }
439
public function serialize(Ability $ability, array $options = [])
    {
        $serialized = [
            'id' => $ability->getUuid(),
            'name' => $ability->getName(),
            'minResourceCount' => $ability->getMinResourceCount(),
            'minEvaluatedResourceCount' => $ability->getMinEvaluatedResourceCount(),
        ];

        return $serialized;
    }
1212651
public function file($fieldName, $options = [])
    {
        $defaults = [
            'div' => [
                'class' => 'form-group',
            ],
        ];
        $options = array_merge($defaults, $options);
        return parent::input($fieldName, $options);
    }
1217773
public static function json(&$value, $options = ['json_assoc'=>true, 'json_schema'=>[], 'default'=>null])
    {
        $json_assoc = isset($options['json_assoc']) && $options['json_assoc'] ? true : false;
        $value = @json_decode(trim($value), $json_assoc);

        if ($value !== null && $json_assoc && isset($options['json_schema']) && $options['json_schema'] && is_array($options['json_schema'])) {
            foreach ($options['json_schema'] as $field => $opt_arr) {
                self::validate(
                    $value[$field],
                    isset($opt_arr[0]) ? $opt_arr[0] : self::NONE_TYPE,
                    isset($opt_arr[1]) && is_array($opt_arr[1]) ? $opt_arr[1] : []
                );
            }
        } elseif ($value === null) {
            $value = isset($options['default']) ? $options['default'] : null;
        }

        return $value;
    }
850463
public function apiSerialize($object, $options = [])
    {
        if (!empty($object)) {
            return $this->serializerProvider->serialize($object, $options);
        }

        return $object;
    }
1092001
public function serialize(Answer $answer, array $options = [])
    {
        $serialized = [
            'id' => $answer->getUuid(),
            'questionId' => $answer->getQuestionId(),
            'tries' => $answer->getTries(),
            'usedHints' => array_map(function ($hintId) use ($options) {
                return $options['hints'][$hintId];
            }, $answer->getUsedHints()),
        ];

        if (!empty($answer->getData())) {
            $serialized['data'] = json_decode($answer->getData(), true);
        }
        // Adds user score
        if (in_array(Transfer::INCLUDE_USER_SCORE, $options)) {
            $serialized = array_merge($serialized, [
                'score' => $answer->getScore(),
                'feedback' => $answer->getFeedback(),
            ]);
        }

        return $serialized;
    }
990523
public function toJson($options = 0)
    {
        // Models' toJson() calls their toArray() function.  We don't want this to
        // happen twice
        if (!is_a($this, Model::class)) {
            $this->runSerializeTransforms();
        }

        // Continue execution
        return parent::toJson($options);
    }
108578
protected function doDistinct($field, array $query, array $options)
    {
        list($commandOptions, $clientOptions) = isset($options['socketTimeoutMS']) || isset($options['timeout'])
            ? $this->splitCommandAndClientOptions($options)
            : [$options, []];

        $command = [];
        $command['distinct'] = $this->mongoCollection->getName();
        $command['key'] = $field;
        $command['query'] = (object) $query;
        $command = array_merge($command, $commandOptions);

        $database = $this->database;
        $result = $this->retry(function() use ($database, $command, $clientOptions) {
            return $database->command($command, $clientOptions);
        });

        if (empty($result['ok'])) {
            throw new ResultException($result);
        }

        $arrayIterator = new ArrayIterator(isset($result['values']) ? $result['values'] : []);
        $arrayIterator->setCommandResult($result);

        return $arrayIterator;
    }