This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Form/FieldInterface.php

207 lines
5.0 KiB
PHP
Raw Normal View History

<?php
2010-10-02 11:38:11 +01:00
/*
* This file is part of the Symfony package.
2010-10-02 11:38:11 +01:00
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
2010-10-02 11:38:11 +01:00
*/
namespace Symfony\Component\Form;
use Symfony\Component\Translation\TranslatorInterface;
/**
* A form field that can be embedded in a form.
*
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
*/
interface FieldInterface
{
/**
* Marks a constraint violation in a form field
* @var integer
*/
const FIELD_ERROR = 0;
/**
* Marks a constraint violation in the data of a form field
* @var integer
*/
const DATA_ERROR = 1;
/**
* Clones this field.
*/
function __clone();
/**
* Sets the parent field.
*
* @param FieldInterface $parent The parent field
*/
function setParent(FieldInterface $parent = null);
/**
* Returns the parent field.
*
* @return FieldInterface The parent field
*/
function getParent();
/**
* Sets the key by which the field is identified in field groups.
*
* Once this field is nested in a field group, i.e. after setParent() was
* called for the first time, this method should throw an exception.
*
* @param string $key The key of the field
* @throws BadMethodCallException When the field already has a parent
*/
function setKey($key);
/**
* Returns the key by which the field is identified in field groups.
*
* @return string The key of the field.
*/
function getKey();
/**
* Sets the property path
*
* The property path determines the property or a sequence of properties
* that a field updates in the data of the field group.
*
* @param string $propertyPath
*/
function setPropertyPath($propertyPath);
/**
* Returns the property path of the field
*
* @return PropertyPath
*/
function getPropertyPath();
/**
* Writes a property value of the object into the field
*
* The chosen property is determined by the field's property path.
*
* @param array|object $objectOrArray
*/
function readProperty(&$objectOrArray);
/**
* Writes a the field value into a property of the object
*
* The chosen property is determined by the field's property path.
*
* @param array|object $objectOrArray
*/
function writeProperty(&$objectOrArray);
/**
* Returns the data of the field as it is displayed to the user.
*
* @return string|array When the field is not bound, the transformed
* default data is returned. When the field is bound,
* the bound data is returned.
*/
function getDisplayedData();
/**
* Recursively adds constraint violations to the fields
*
* Violations in the form fields usually have property paths like:
*
* <code>
* iterator[firstName].data
* iterator[firstName].displayedData
* iterator[Address].iterator[street].displayedData
* ...
* </code>
*
* Violations in the form data usually have property paths like:
*
* <code>
* data.firstName
* data.Address.street
* ...
* </code>
*
* @param Error $error
* @param PropertyPathIterator $pathIterator
*/
function addError(Error $error, PropertyPathIterator $pathIterator = null);
/**
* Returns whether the field is valid.
*
* @return Boolean
*/
function isValid();
/**
* Returns whether the field requires a multipart form.
*
* @return Boolean
*/
function isMultipart();
/**
* Returns whether the field is required to be filled out.
*
* If the field has a parent and the parent is not required, this method
* will always return false. Otherwise the value set with setRequired()
* is returned.
*
* @return Boolean
*/
function isRequired();
/**
* Returns whether this field is disabled
*
* The content of a disabled field is displayed, but not allowed to be
* modified. The validation of modified, disabled fields should fail.
*
* Fields whose parents are disabled are considered disabled regardless of
* their own state.
*
* @return Boolean
*/
function isDisabled();
/**
* Returns whether the field is hidden
*
* @return Boolean
*/
function isHidden();
/**
* Returns whether the field is empty
*
* @return boolean
*/
function isEmpty();
/**
* Sets whether this field is required to be filled out when submitted.
*
* @param Boolean $required
*/
function setRequired($required);
/**
* Writes posted data into the field
*
* @param mixed $data The data from the POST request
*/
function submit($data);
2010-10-02 11:38:11 +01:00
}