preSaveNew example

// Clear the derived data about the field.     unset($this->schema);

    // Filter out unknown settings and make sure all settings are present, so     // that a complete field definition is passed to the various hooks and     // written to config.     $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
    $default_settings = $field_type_manager->getDefaultStorageSettings($this->type);
    $this->settings = array_intersect_key($this->settings, $default_settings) + $default_settings;

    if ($this->isNew()) {
      $this->preSaveNew($storage);
    }
    else {
      $this->preSaveUpdated($storage);
    }

    parent::preSave($storage);
  }

  /** * Prepares saving a new field definition. * * @param \Drupal\Core\Entity\EntityStorageInterface $storage * The entity storage. * * @throws \Drupal\Core\Field\FieldException * If the field definition is invalid. */
Home | Imprint | This part of the site doesn't use cookies.