doSaveFieldItems example

    // does not support inserting an ID of 0 into serial field unless the SQL     // mode is set to NO_AUTO_VALUE_ON_ZERO.     // @todo https://drupal.org/i/3222123 implement a generic fix for all entity     // types.     if ($entity->id() === 0) {
      $database = \Drupal::database();
      if ($database->databaseType() === 'mysql') {
        $sql_mode = $database->query("SELECT @@sql_mode;")->fetchField();
        $database->query("SET sql_mode = '$sql_mode,NO_AUTO_VALUE_ON_ZERO'");
      }
    }
    parent::doSaveFieldItems($entity$names);

    // Reset the SQL mode if we've changed it.     if (isset($sql_mode$database)) {
      $database->query("SET sql_mode = '$sql_mode'");
    }
  }

  /** * {@inheritdoc} */
  public function updateLastLoginTimestamp(UserInterface $account) {
    
// Populate the "revision_default" flag. Skip this when we are resaving     // the revision, and the flag is set to FALSE, since it is not possible to     // set a previously default revision to non-default. However, setting a     // previously non-default revision to default is allowed for advanced     // use-cases.     if ($this->entityType->isRevisionable() && ($entity->isNewRevision() || $entity->isDefaultRevision())) {
      $revision_default_key = $this->entityType->getRevisionMetadataKey('revision_default');
      $entity->set($revision_default_key$entity->isDefaultRevision());
    }

    $this->doSaveFieldItems($entity);

    return $return;
  }

  /** * Writes entity field values to the storage. * * This method is responsible for allocating entity and revision identifiers * and updating the entity object with their values. * * @param \Drupal\Core\Entity\ContentEntityInterface $entity * The entity object. * @param string[] $names * (optional) The name of the fields to be written to the storage. If an * empty value is passed all field values are saved. */
Home | Imprint | This part of the site doesn't use cookies.