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;
    }
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;
    }
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 ; }
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
Serializes a Field entity for the JSON api .