You are here

public function Replicator::cloneEntityField in Replicate 8

Clone an entity field to another.

We can not create and return the target field here, because it needs to know its parent entity, which can not be changed after creation.

Parameters

\Drupal\Core\Field\FieldItemListInterface $field: The field to clone.

\Drupal\Core\Field\FieldItemListInterface $target_field: The field to clone into.

Throws

\InvalidArgumentException If the value input is inappropriate.

\Drupal\Core\TypedData\Exception\ReadOnlyException If the data is read-only.

File

src/Replicator.php, line 168

Class

Replicator
Class Replicator. Manages the replication of an entity.

Namespace

Drupal\replicate

Code

public function cloneEntityField(FieldItemListInterface $field, FieldItemListInterface $target_field) {
  $target_field
    ->setValue($field
    ->getValue());
  $this
    ->postCloneEntityField($target_field);
}