You are here

interface FieldConfigInterface in Zircon Profile 8

Same name in this branch
  1. 8 core/modules/field/src/FieldConfigInterface.php \Drupal\field\FieldConfigInterface
  2. 8 core/lib/Drupal/Core/Field/FieldConfigInterface.php \Drupal\Core\Field\FieldConfigInterface
Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Field/FieldConfigInterface.php \Drupal\Core\Field\FieldConfigInterface

Defines an interface for configurable field definitions.

This interface allows both configurable fields and overridden base fields to share a common interface. The interface also extends ConfigEntityInterface to ensure that implementations have the expected save() method.

Hierarchy

Expanded class hierarchy of FieldConfigInterface

All classes that implement FieldConfigInterface

See also

\Drupal\Core\Field\Entity\BaseFieldOverride

\Drupal\field\Entity\FieldConfig

2 files declare their use of FieldConfigInterface
MigrateCommentFieldInstanceTest.php in core/modules/comment/src/Tests/Migrate/d7/MigrateCommentFieldInstanceTest.php
Contains \Drupal\comment\Tests\Migrate\d7\MigrateCommentFieldInstanceTest.
MigrateUserPictureFieldInstanceTest.php in core/modules/user/src/Tests/Migrate/MigrateUserPictureFieldInstanceTest.php
Contains \Drupal\user\Tests\Migrate\MigrateUserPictureFieldInstanceTest.

File

core/lib/Drupal/Core/Field/FieldConfigInterface.php, line 22
Contains \Drupal\Core\Field\FieldConfigInterface.

Namespace

Drupal\Core\Field
View source
interface FieldConfigInterface extends FieldDefinitionInterface, ConfigEntityInterface {

  /**
   * Sets the field definition label.
   *
   * @param string $label
   *   The label to set.
   *
   * @return $this
   */
  public function setLabel($label);

  /**
   * Sets a human readable description.
   *
   * Descriptions are usually used on user interfaces where the data is edited
   * or displayed.
   *
   * @param string $description
   *   The description for this field.
   *
   * @return $this
   */
  public function setDescription($description);

  /**
   * Sets whether the field is translatable.
   *
   * @param bool $translatable
   *   Whether the field is translatable.
   *
   * @return $this
   */
  public function setTranslatable($translatable);

  /**
   * Sets field settings.
   *
   * Note that the method does not unset existing settings not specified in the
   * incoming $settings array.
   *
   * For example:
   * @code
   *   // Given these are the default settings.
   *   $field_definition->getSettings() === [
   *     'fruit' => 'apple',
   *     'season' => 'summer',
   *   ];
   *   // Change only the 'fruit' setting.
   *   $field_definition->setSettings(['fruit' => 'banana']);
   *   // The 'season' setting persists unchanged.
   *   $field_definition->getSettings() === [
   *     'fruit' => 'banana',
   *     'season' => 'summer',
   *   ];
   * @endcode
   *
   * For clarity, it is preferred to use setSetting() if not all available
   * settings are supplied.
   *
   * @param array $settings
   *   The array of field settings.
   *
   * @return $this
   */
  public function setSettings(array $settings);

  /**
   * Sets the value for a field setting by name.
   *
   * @param string $setting_name
   *   The name of the setting.
   * @param mixed $value
   *   The value of the setting.
   *
   * @return $this
   */
  public function setSetting($setting_name, $value);

  /**
   * Sets whether the field can be empty.
   *
   * If a field is required, an entity needs to have at least a valid,
   * non-empty item in that field's FieldItemList in order to pass validation.
   *
   * An item is considered empty if its isEmpty() method returns TRUE.
   * Typically, that is if at least one of its required properties is empty.
   *
   * @param bool $required
   *   TRUE if the field is required. FALSE otherwise.
   *
   * @return $this
   *   The current object, for a fluent interface.
   */
  public function setRequired($required);

  /**
   * Sets a default value.
   *
   * Note that if a default value callback is set, it will take precedence over
   * any value set here.
   *
   * @param mixed $value
   *   The default value for the field. This can be either:
   *   - a literal, in which case it will be assigned to the first property of
   *     the first item.
   *   - a numerically indexed array of items, each item being a property/value
   *     array.
   *   - a non-numerically indexed array, in which case the array is assumed to
   *     be a property/value array and used as the first item
   *   - NULL or array() for no default value.
   *
   * @return $this
   */
  public function setDefaultValue($value);

  /**
   * Sets a custom default value callback.
   *
   * If set, the callback overrides any set default value.
   *
   * @param string|null $callback
   *   The callback to invoke for getting the default value (pass NULL to unset
   *   a previously set callback). The callback will be invoked with the
   *   following arguments:
   *   - \Drupal\Core\Entity\FieldableEntityInterface $entity
   *     The entity being created.
   *   - \Drupal\Core\Field\FieldDefinitionInterface $definition
   *     The field definition.
   *   It should return the default value in the format accepted by the
   *   setDefaultValue() method.
   *
   * @return $this
   */
  public function setDefaultValueCallback($callback);

  /**
   * Sets constraints for a given field item property.
   *
   * Note: this overwrites any existing property constraints. If you need to
   * add to the existing constraints, use
   * \Drupal\Core\Field\FieldConfigInterface::addPropertyConstraints()
   *
   * Note that constraints added via this method are not stored in configuration
   * and as such need to be added at runtime using
   * hook_entity_bundle_field_info_alter().
   *
   * @param string $name
   *   The name of the property to set constraints for.
   * @param array $constraints
   *   The constraints to set.
   *
   * @return static
   *   The object itself for chaining.
   *
   * @see hook_entity_bundle_field_info_alter()
   */
  public function setPropertyConstraints($name, array $constraints);

  /**
   * Adds constraints for a given field item property.
   *
   * Adds a constraint to a property of a field item. e.g.
   * @code
   * // Limit the field item's value property to the range 0 through 10.
   * // e.g. $node->field_how_many->value.
   * $field->addPropertyConstraints('value', [
   *   'Range' => [
   *     'min' => 0,
   *     'max' => 10,
   *   ]
   * ]);
   * @endcode
   *
   * If you want to add a validation constraint that applies to the
   * \Drupal\Core\Field\FieldItemList, use FieldConfigInterface::addConstraint()
   * instead.
   *
   * Note: passing a new set of options for an existing property constraint will
   * overwrite with the new options.
   *
   * Note that constraints added via this method are not stored in configuration
   * and as such need to be added at runtime using
   * hook_entity_bundle_field_info_alter().
   *
   * @param string $name
   *   The name of the property to set constraints for.
   * @param array $constraints
   *   The constraints to set.
   *
   * @return static
   *   The object itself for chaining.
   *
   * @see \Drupal\Core\Field\FieldConfigInterface::addConstraint()
   * @see hook_entity_bundle_field_info_alter()
   */
  public function addPropertyConstraints($name, array $constraints);

  /**
   * Adds a validation constraint to the FieldItemList.
   *
   * Note: If you wish to apply a constraint to just a property of a FieldItem
   * use \Drupal\Core\Field\FieldConfigInterface::addPropertyConstraints()
   * instead.
   * @code
   *   // Add a constraint to the 'field_username' FieldItemList.
   *   // e.g. $node->field_username
   *   $fields['field_username']->addConstraint('UniqueField');
   * @endcode
   *
   * If you wish to apply a constraint to a \Drupal\Core\Field\FieldItem instead
   * of a property or FieldItemList, you can use the
   * \Drupal\Core\Field\FieldConfigBase::getItemDefinition() method.
   * @code
   *   // Add a constraint to the 'field_entity_reference' FieldItem (entity
   *   // reference item).
   *   $fields['field_entity_reference']->getItemDefinition()->addConstraint('MyCustomFieldItemValidationPlugin', []);
   * @endcode
   *
   * See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for
   * details.
   *
   * Note that constraints added via this method are not stored in configuration
   * and as such need to be added at runtime using
   * hook_entity_bundle_field_info_alter().
   *
   * @param string $constraint_name
   *   The name of the constraint to add, i.e. its plugin id.
   * @param array|null $options
   *   The constraint options as required by the constraint plugin, or NULL.
   *
   * @return static
   *   The object itself for chaining.
   *
   * @see \Drupal\Core\Field\FieldItemList
   * @see \Drupal\Core\Field\FieldConfigInterface::addPropertyConstraints()
   * @see hook_entity_bundle_field_info_alter()
   */
  public function addConstraint($constraint_name, $options = NULL);

  /**
   * Sets the array of validation constraints for the FieldItemList.
   *
   * NOTE: This will overwrite any previously set constraints. In most cases
   * FieldConfigInterface::addConstraint() should be used instead.
   *
   * Note that constraints added via this method are not stored in configuration
   * and as such need to be added at runtime using
   * hook_entity_bundle_field_info_alter().
   *
   * @param array $constraints
   *   The array of constraints. See
   *   \Drupal\Core\TypedData\TypedDataManager::getConstraints() for details.
   *
   * @return $this
   *
   * @see \Drupal\Core\TypedData\DataDefinition::addConstraint()
   * @see \Drupal\Core\TypedData\DataDefinition::getConstraints()
   * @see \Drupal\Core\Field\FieldItemList
   * @see hook_entity_bundle_field_info_alter()
   */
  public function setConstraints(array $constraints);

}

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
DataDefinitionInterface::createFromDataType public static function Creates a new data definition object. 2
DataDefinitionInterface::getClass public function Returns the class used for creating the typed data object. 2
DataDefinitionInterface::getConstraint public function Returns a validation constraint. 2
DataDefinitionInterface::getConstraints public function Returns an array of validation constraints. 2
DataDefinitionInterface::getDataType public function Returns the data type of the data. 2
DataDefinitionInterface::getDescription public function Returns a human readable description. 2
DataDefinitionInterface::getLabel public function Returns a human readable label. 2
DataDefinitionInterface::getSetting public function Returns the value of a given setting. 2
DataDefinitionInterface::getSettings public function Returns the array of settings, as required by the used class. 2
DataDefinitionInterface::isComputed public function Determines whether the data value is computed. 3
DataDefinitionInterface::isList public function Returns whether the data is multi-valued, i.e. a list of data items. 2
DataDefinitionInterface::isReadOnly public function Determines whether the data is read-only. 3
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
FieldConfigInterface::addConstraint public function Adds a validation constraint to the FieldItemList. Overrides DataDefinitionInterface::addConstraint 1
FieldConfigInterface::addPropertyConstraints public function Adds constraints for a given field item property. 1
FieldConfigInterface::setConstraints public function Sets the array of validation constraints for the FieldItemList. 1
FieldConfigInterface::setDefaultValue public function Sets a default value. 1
FieldConfigInterface::setDefaultValueCallback public function Sets a custom default value callback. 1
FieldConfigInterface::setDescription public function Sets a human readable description. 1
FieldConfigInterface::setLabel public function Sets the field definition label. 1
FieldConfigInterface::setPropertyConstraints public function Sets constraints for a given field item property. 1
FieldConfigInterface::setRequired public function Sets whether the field can be empty. 1
FieldConfigInterface::setSetting public function Sets the value for a field setting by name. 1
FieldConfigInterface::setSettings public function Sets field settings. 1
FieldConfigInterface::setTranslatable public function Sets whether the field is translatable. 1
FieldDefinitionInterface::getConfig public function Gets an object that can be saved in configuration. 2
FieldDefinitionInterface::getDefaultValue public function Returns the default value for the field in a newly created entity. 2
FieldDefinitionInterface::getDefaultValueCallback public function Returns the default value callback for the field. 2
FieldDefinitionInterface::getDefaultValueLiteral public function Returns the default value literal for the field. 2
FieldDefinitionInterface::getDisplayOptions public function Returns the default display options for the field. 3
FieldDefinitionInterface::getFieldStorageDefinition public function Returns the field storage definition. 3
FieldDefinitionInterface::getName public function Returns the machine name of the field. 2
FieldDefinitionInterface::getTargetBundle public function Gets the bundle the field is attached to. 2
FieldDefinitionInterface::getTargetEntityTypeId public function Returns the ID of the entity type the field is attached to. 2
FieldDefinitionInterface::getType public function Returns the field type. 2
FieldDefinitionInterface::isDisplayConfigurable public function Returns whether the display for the field can be configured. 3
FieldDefinitionInterface::isRequired public function Returns whether the field can be empty. Overrides DataDefinitionInterface::isRequired 1
FieldDefinitionInterface::isTranslatable public function Returns whether the field is translatable. 2
ListDataDefinitionInterface::createFromItemType public static function Creates a new list data definition for items of the given data type. 2
ListDataDefinitionInterface::getItemDefinition public function Gets the data definition of an item of the list. 2
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