You are here

function serial_clone_node_alter in Serial Field 8

Same name and namespace in other branches
  1. 7 serial.module \serial_clone_node_alter()

Implements hook_clone_node_alter().

@todo to review once node_clone have a stable release

File

./serial.module, line 68
The Serial module main file.

Code

function serial_clone_node_alter(Node &$node, $context) {

  // Reset values of all serial fields when cloning a node.
  foreach (\Drupal::getContainer()
    ->get('entity_field.manager')
    ->getFieldDefinitions('node', $node
    ->bundle()) as $field_name => $field_definition) {
    if (!empty($field_definition
      ->getTargetBundle()) && $field_definition
      ->getType() == SerialStorageInterface::SERIAL_FIELD_TYPE) {
      $node->{$field_name} = [];
    }
  }
}