# ivyforms/0.1.2/backend/src/Entity/Field/Field.php

The Innovative Form Builder – IvyForms, version 0.1.2. 234 lines.

- Page: https://pluginprobe.com/plugins/ivyforms/0.1.2/code/backend/src/Entity/Field/Field.php
- Raw: https://pluginprobe.com/plugins/ivyforms/0.1.2/raw/backend/src/Entity/Field/Field.php
- Modified: 2025-06-12T10:29:14+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/ivyforms/0.1.2/code/backend/src/Entity/Field/Field.php#L10-L20`.

```php
<?php

namespace IvyForms\Entity\Field;

// phpcs:disable PSR1.Files.SideEffects
if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}

use IvyForms\ValueObjects\Field\Field as FieldValueObject;

/**
 * Class Field
 *
 * @package IvyForms\Entity\Field
 */
class Field
{
    /**
     * @var FieldValueObject
     */
    private FieldValueObject $formField;

    /**
     * Field constructor.
     *
     * @param FieldValueObject $formField The form field object.
     */
    public function __construct(FieldValueObject $formField)
    {
        $this->formField = $formField;
    }

    /**
     * Get the ID of the form to which this field belongs
     *
     * @return int The form ID.
     */
    public function getFormId(): int
    {
        return $this->formField->getFormId();
    }

    /**
     * Set the ID of the form to which this field belongs.
     *
     * @param int $formId The form ID to set.
     */
    public function setFormId(int $formId): void
    {
        $this->formField->formId = $formId;
    }

    /**
     * Get ID of the form field.
     *
     * @return int The form field id.
     */
    public function getId(): int
    {
        return $this->formField->getId();
    }

    /**
     * Set the ID of the form field.
     *
     * @param int $id The ID to set.
     */
    public function setId(int $id): void
    {
        $this->formField->id = $id;
    }

    /**
     * Get the index of the form field.
     *
     * @return int The index of the form field.
     */
    public function getIndex(): int
    {
        return $this->formField->getIndex();
    }

    /**
     * Set the index of the form field.
     *
     * @param int $index The index to set.
     */
    public function setIndex(int $index): void
    {
        $this->formField->fieldIndex = $index;
    }

    /**
     * Get the type of the form field.
     *
     * @return string The type of the form field.
     */
    public function getType(): string
    {
        return $this->formField->getType();
    }

    /**
     * Set the type of the form field.
     *
     * @param string $type The type to set.
     */
    public function setType(string $type): void
    {
        $this->formField->type = $type;
    }

    /**
     * Get the label of the form field.
     *
     * @return string The label of the form field.
     */
    public function getLabel(): string
    {
        return $this->formField->getLabel();
    }

    /**
     * Set the label of the form field.
     *
     * @param string $label The label to set.
     */
    public function setLabel(string $label): void
    {
        $this->formField->label = $label;
    }

    /**
     * Get the default value of the form field.
     *
     * @return string The default value of the form field.
     */
    public function getDefaultValue(): string
    {
        return $this->formField->getDefaultValue();
    }

    /**
     * Set the default value of the form field.
     *
     * @param string $defaultValue The default value to set.
     */
    public function setDefaultValue(string $defaultValue): void
    {
        $this->formField->defaultValue = $defaultValue;
    }

    /**
     * Check if the form field is required.
     *
     * @return bool True if the form field is required, false otherwise.
     */
    public function isRequired(): bool
    {
        return $this->formField->isRequired();
    }

    /**
     * Set the required status of the form field.
     *
     * @param bool $required The required status to set.
     */
    public function setRequired(bool $required): void
    {
        $this->formField->required = $required;
    }

    /**
     * Get the placeholder of the form field.
     *
     * @return string The placeholder of the form field.
     */
    public function getPlaceholder(): string
    {
        return $this->formField->getPlaceholder();
    }

    /**
     * Set the placeholder of the form field.
     *
     * @param string $placeholder The placeholder to set.
     */
    public function setPlaceholder(string $placeholder): void
    {
        $this->formField->placeholder = $placeholder;
    }

    /**
     * Get the position of the form field.
     *
     * @return int The position of the form field.
     */
    public function getPosition(): int
    {
        return $this->formField->getPosition();
    }

    /**
     * Set the position of the form field.
     *
     * @param int $position The position to set.
     */
    public function setPosition(int $position): void
    {
        $this->formField->position = $position;
    }

    /**
     * Convert the form field entity to an array.
     *
     * @return array<string, mixed> The form field entity as an array.
     */
    public function toArray(): array
    {
        return [
            'id'           => $this->getId(),
            'formId'       => $this->getFormId(),
            'fieldIndex'   => $this->getIndex(),
            'type'         => $this->getType(),
            'label'        => $this->getLabel(),
            'defaultValue' => $this->getDefaultValue(),
            'required'     => $this->isRequired(),
            'placeholder'  => $this->getPlaceholder(),
            'position'     => $this->getPosition(),
        ];
    }
}

```
