You are here

public function FieldConfigBase::setRequired in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Field/FieldConfigBase.php \Drupal\Core\Field\FieldConfigBase::setRequired()

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.

Parameters

bool $required: TRUE if the field is required. FALSE otherwise.

Return value

$this The current object, for a fluent interface.

Overrides FieldConfigInterface::setRequired

File

core/lib/Drupal/Core/Field/FieldConfigBase.php, line 387

Class

FieldConfigBase
Base class for configurable field definitions.

Namespace

Drupal\Core\Field

Code

public function setRequired($required) {
  $this->required = $required;
  return $this;
}