You are here

interface EntityFormDisplayInterface in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/Display/EntityFormDisplayInterface.php \Drupal\Core\Entity\Display\EntityFormDisplayInterface

Provides a common interface for entity form displays.

Hierarchy

Expanded class hierarchy of EntityFormDisplayInterface

All classes that implement EntityFormDisplayInterface

4 files declare their use of EntityFormDisplayInterface
ContentEntityForm.php in core/lib/Drupal/Core/Entity/ContentEntityForm.php
Contains \Drupal\Core\Entity\ContentEntityForm.
ContentEntityFormInterface.php in core/lib/Drupal/Core/Entity/ContentEntityFormInterface.php
Contains \Drupal\Core\Entity\ContentEntityFormInterface.
EntityFormDisplay.php in core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php
Contains \Drupal\Core\Entity\Entity\EntityFormDisplay.
MigrateFieldInstanceWidgetSettingsTest.php in core/modules/field/src/Tests/Migrate/d7/MigrateFieldInstanceWidgetSettingsTest.php
Contains \Drupal\field\Tests\Migrate\d7\MigrateFieldInstanceWidgetSettingsTest.

File

core/lib/Drupal/Core/Entity/Display/EntityFormDisplayInterface.php, line 17
Contains \Drupal\Core\Entity\Display\EntityFormDisplayInterface.

Namespace

Drupal\Core\Entity\Display
View source
interface EntityFormDisplayInterface extends EntityDisplayInterface {

  /**
   * Adds field widgets to an entity form.
   *
   * The form elements for the entity's fields are added by reference as direct
   * children in the $form parameter. This parameter can be a full form
   * structure (most common case for entity edit forms), or a sub-element of a
   * larger form.
   *
   * By default, submitted field values appear at the top-level of
   * $form_state->getValues(). A different location within
   * $form_state->getValues() can be specified by setting the '#parents'
   * property on the incoming $form parameter. Because of name clashes, two
   * instances of the same field cannot appear within the same $form element, or
   * within the same '#parents' space.
   *
   * Sample resulting structure in $form:
   * @code
   *   '#parents' => The location of field values in $form_state->getValues(),
   *   '#entity_type' => The name of the entity type,
   *   '#bundle' => The name of the bundle,
   *   // One sub-array per field appearing in the entity, keyed by field name.
   *   // The structure of the array differs slightly depending on whether the
   *   // widget is 'single-value' (provides the input for one field value,
   *   // most common case), and will therefore be repeated as many times as
   *   // needed, or 'multiple-values' (one single widget allows the input of
   *   // several values; e.g., checkboxes, select box, etc.).
   *   'field_foo' => array(
   *     '#access' => TRUE if the current user has 'edit' grants for the field,
   *       FALSE if not.
   *     'widget' => array(
   *       '#field_name' => The name of the field,
   *       '#title' => The label of the field,
   *       '#description' => The description text for the field,
   *       '#required' => Whether or not the field is required,
   *       '#field_parents' => The 'parents' space for the field in the form,
   *          equal to the #parents property of the $form parameter received by
   *          this method,
   *
   *       // For 'multiple-value' widgets, the remaining elements in the
   *       // sub-array depend on the widget.
   *
   *       // For 'single-value' widgets:
   *       '#theme' => 'field_multiple_value_form',
   *       '#cardinality' => The field cardinality,
   *       '#cardinality_multiple => TRUE if the field can contain multiple
   *         items, FALSE otherwise.
   *       // One sub-array per copy of the widget, keyed by delta.
   *       0 => array(
   *         '#title' => The title to be displayed by the widget,
   *         '#description' => The description text for the field,
   *         '#required' => Whether the widget should be marked required,
   *         '#delta' => 0,
   *         '#weight' => 0,
   *         '#field_parents' => Same as above,
   *         // The remaining elements in the sub-array depend on the widget.
   *         ...
   *       ),
   *       1 => array(
   *         ...
   *       ),
   *       ...
   *     ),
   *     ...
   *   ),
   * )
   * @endcode
   *
   * Additionally, some processing data is placed in $form_state, and can be
   * accessed by \Drupal\Core\Field\WidgetBaseInterface::getWidgetState() and
   * \Drupal\Core\Field\WidgetBaseInterface::setWidgetState().
   *
   * @param \Drupal\Core\Entity\FieldableEntityInterface $entity
   *   The entity.
   * @param array $form
   *   The form structure to fill in. This can be a full form structure, or a
   *   sub-element of a larger form. The #parents property can be set to
   *   control the location of submitted field values within
   *   $form_state->getValues(). If not specified, $form['#parents'] is set to
   *   an empty array, which results in field values located at the top-level of
   *   $form_state->getValues().
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The form state.
   */
  public function buildForm(FieldableEntityInterface $entity, array &$form, FormStateInterface $form_state);

  /**
   * Extracts field values from the submitted widget values into the entity.
   *
   * This accounts for drag-and-drop reordering of field values, and filtering
   * of empty values.
   *
   * @param \Drupal\Core\Entity\FieldableEntityInterface $entity
   *   The entity.
   * @param array $form
   *   The form structure where field elements are attached to. This might be a
   *   full form structure, or a sub-element of a larger form.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The form state.
   *
   * @return array
   *   An array whose keys and values are the keys of the top-level entries in
   *   $form_state->getValues() that have been processed. The remaining entries,
   *   if any, do not correspond to widgets and should be extracted manually by
   *   the caller if needed.
   */
  public function extractFormValues(FieldableEntityInterface $entity, array &$form, FormStateInterface $form_state);

  /**
   * Validates submitted widget values and sets the corresponding form errors.
   *
   * This method invokes entity validation and takes care of flagging them on
   * the form. This is particularly useful when all elements on the form are
   * managed by the form display.
   *
   * As an alternative, entity validation can be invoked separately such that
   * some violations can be flagged manually. In that case
   * \Drupal\Core\Entity\Display\EntityFormDisplayInterface::flagViolations()
   * must be used for flagging violations related to the form display.
   *
   * Note that there are two levels of validation for fields in forms: widget
   * validation and field validation:
   * - Widget validation steps are specific to a given widget's own form
   *   structure and UI metaphors. They are executed during normal form
   *   validation, usually through Form API's #element_validate property.
   *   Errors reported at this level are typically those that prevent the
   *   extraction of proper field values from the submitted form input.
   * - If no form / widget errors were reported for the field, field validation
   *   steps are performed according to the "constraints" specified by the
   *   field definition as part of the entity validation. That validation is
   *   independent of the specific widget being used in a given form, and is
   *   also performed on REST entity submissions.
   *
   * @param \Drupal\Core\Entity\FieldableEntityInterface $entity
   *   The entity.
   * @param array $form
   *   The form structure where field elements are attached to. This might be a
   *   full form structure, or a sub-element of a larger form.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The form state.
   */
  public function validateFormValues(FieldableEntityInterface $entity, array &$form, FormStateInterface $form_state);

  /**
   * Flags entity validation violations as form errors.
   *
   * This method processes all violations passed, thus any violations not
   * related to fields of the form display must be processed before this method
   * is invoked.
   *
   * The method flags constraint violations related to fields shown on the
   * form as form errors on the correct form elements. Possibly pre-existing
   * violations of hidden fields (so fields not appearing in the display) are
   * ignored. Other, non-field related violations are passed through and set as
   * form errors according to the property path of the violations.
   *
   * @param \Drupal\Core\Entity\EntityConstraintViolationListInterface $violations
   *   The violations to flag.
   * @param array $form
   *   The form structure where field elements are attached to. This might be a
   *   full form structure, or a sub-element of a larger form.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The form state.
   */
  public function flagWidgetsErrorsFromViolations(EntityConstraintViolationListInterface $violations, array &$form, FormStateInterface $form_state);

}

Members

Namesort descending Modifiers Type Description Overrides
AccessibleInterface::access public function Checks data value access. 5
CacheableDependencyInterface::getCacheContexts public function The cache contexts associated with this object. 26
CacheableDependencyInterface::getCacheMaxAge public function The maximum age for which this object may be cached. 26
CacheableDependencyInterface::getCacheTags public function The cache tags associated with this object. 19
ConfigEntityInterface::calculateDependencies public function Calculates dependencies and stores them in the dependency property. 2
ConfigEntityInterface::disable public function Disables the configuration entity. 2
ConfigEntityInterface::enable public function Enables the configuration entity. 2
ConfigEntityInterface::get public function Returns the value of a property. 2
ConfigEntityInterface::getDependencies public function Gets the configuration dependencies. 2
ConfigEntityInterface::hasTrustedData public function Gets whether on not the data is trusted. 2
ConfigEntityInterface::isInstallable public function Checks whether this entity is installable. 2
ConfigEntityInterface::isSyncing public function Returns whether this entity is being changed as part of an import process. 2
ConfigEntityInterface::isUninstalling public function Returns whether this entity is being changed during the uninstall process. 2
ConfigEntityInterface::onDependencyRemoval public function Informs the entity that entities it depends on will be deleted. 2
ConfigEntityInterface::set public function Sets the value of a property. 2
ConfigEntityInterface::setStatus public function Sets the status of the configuration entity. 3
ConfigEntityInterface::setSyncing public function Sets the status of the isSyncing flag. 2
ConfigEntityInterface::status public function Returns whether the configuration entity is enabled. 2
ConfigEntityInterface::trustData public function Sets that the data should be trusted. 2
EntityDisplayInterface::createCopy public function Creates a duplicate of the entity display object on a different view mode. 1
EntityDisplayInterface::getComponent public function Gets the display options set for a component. 1
EntityDisplayInterface::getComponents public function Gets the display options for all components. 1
EntityDisplayInterface::getHighestWeight public function Gets the highest weight of the components in the display. 1
EntityDisplayInterface::getMode public function Gets the view or form mode to be displayed. 1
EntityDisplayInterface::getOriginalMode public function Gets the original view or form mode that was requested. 1
EntityDisplayInterface::getRenderer public function Gets the renderer plugin for a field (e.g. widget, formatter). 2
EntityDisplayInterface::getTargetBundle public function Gets the bundle to be displayed. 1
EntityDisplayInterface::getTargetEntityTypeId public function Gets the entity type for which this display is used. 1
EntityDisplayInterface::removeComponent public function Sets a component to be hidden. 1
EntityDisplayInterface::setComponent public function Sets the display options for a component. 1
EntityDisplayInterface::setTargetBundle public function Sets the bundle to be displayed. 1
EntityFormDisplayInterface::buildForm public function Adds field widgets to an entity form. 1
EntityFormDisplayInterface::extractFormValues public function Extracts field values from the submitted widget values into the entity. 1
EntityFormDisplayInterface::flagWidgetsErrorsFromViolations public function Flags entity validation violations as form errors. 1
EntityFormDisplayInterface::validateFormValues public function Validates submitted widget values and sets the corresponding form errors. 1
EntityInterface::bundle public function Gets the bundle of the entity. 2
EntityInterface::create public static function Constructs a new entity object, without permanently saving it. 2
EntityInterface::createDuplicate public function Creates a duplicate of the entity. 2
EntityInterface::delete public function Deletes an entity permanently. 2
EntityInterface::enforceIsNew public function Enforces an entity to be new. 2
EntityInterface::getCacheTagsToInvalidate public function Returns the cache tags that should be used to invalidate caches. 2
EntityInterface::getConfigDependencyKey public function Gets the key that is used to store configuration dependencies. 2
EntityInterface::getConfigDependencyName public function Gets the configuration dependency name. 2
EntityInterface::getConfigTarget public function Gets the configuration target identifier for the entity. 2
EntityInterface::getEntityType public function Gets the entity type definition. 2
EntityInterface::getEntityTypeId public function Gets the ID of the type of the entity. 2
EntityInterface::getOriginalId public function Gets the original ID. 2
EntityInterface::getTypedData public function Gets a typed data object for this entity object. 2
EntityInterface::hasLinkTemplate public function Indicates if a link template exists for a given key. 2
EntityInterface::id public function Gets the identifier. 2
EntityInterface::isNew public function Determines whether the entity is new. 2
EntityInterface::label public function Gets the label of the entity. 2
EntityInterface::language public function Gets the language of the entity. 2
EntityInterface::link Deprecated public function Deprecated way of generating a link to the entity. See toLink(). 2
EntityInterface::load public static function Loads an entity. 2
EntityInterface::loadMultiple public static function Loads one or more entities. 2
EntityInterface::postCreate public function Acts on an entity after it is created but before hooks are invoked. 2
EntityInterface::postDelete public static function Acts on deleted entities before the delete hook is invoked. 2
EntityInterface::postLoad public static function Acts on loaded entities. 3
EntityInterface::postSave public function Acts on a saved entity before the insert or update hook is invoked. 2
EntityInterface::preCreate public static function Changes the values of an entity before it is created. 2
EntityInterface::preDelete public static function Acts on entities before they are deleted and before hooks are invoked. 2
EntityInterface::preSave public function Acts on an entity before the presave hook is invoked. 2
EntityInterface::referencedEntities public function Gets a list of entities referenced by this entity. 2
EntityInterface::save public function Saves an entity permanently. 2
EntityInterface::setOriginalId public function Sets the original ID. 2
EntityInterface::toArray public function Gets an array of all property values. 3
EntityInterface::toLink public function Generates the HTML for a link to this entity. 2
EntityInterface::toUrl public function Gets the URL object for the entity. 2
EntityInterface::uriRelationships public function Gets a list of URI relationships supported by this entity. 2
EntityInterface::url Deprecated public function Gets the public URL for this entity. 2
EntityInterface::urlInfo Deprecated public function Gets the URL object for the entity. 2
EntityInterface::uuid public function Gets the entity UUID (Universally Unique Identifier). 2
EntityWithPluginCollectionInterface::getPluginCollections public function Gets the plugin collections used by this entity. 7
RefinableCacheableDependencyInterface::addCacheableDependency public function Adds a dependency on an object: merges its cacheability metadata. 1
RefinableCacheableDependencyInterface::addCacheContexts public function Adds cache contexts. 1
RefinableCacheableDependencyInterface::addCacheTags public function Adds cache tags. 1
RefinableCacheableDependencyInterface::mergeCacheMaxAge public function Merges the maximum age (in seconds) with the existing maximum age. 1
ThirdPartySettingsInterface::getThirdPartyProviders public function Gets the list of third parties that store information. 3
ThirdPartySettingsInterface::getThirdPartySetting public function Gets the value of a third-party setting. 3
ThirdPartySettingsInterface::getThirdPartySettings public function Gets all third-party settings of a given module. 3
ThirdPartySettingsInterface::setThirdPartySetting public function Sets the value of a third-party setting. 3
ThirdPartySettingsInterface::unsetThirdPartySetting public function Unsets a third-party setting. 3