doCreate example



  /** * {@inheritdoc} */
  public function create(array $batch) {
    // Ensure that a session is started before using the CSRF token generator.     $this->session->start();
    $try_again = FALSE;
    try {
      // The batch table might not yet exist.       $this->doCreate($batch);
    }
    catch (\Exception $e) {
      // If there was an exception, try to create the table.       if (!$try_again = $this->ensureTableExists()) {
        // If the exception happened for other reason than the missing table,         // propagate the exception.         throw $e;
      }
    }
    // Now that the table has been created, try again if necessary.     if ($try_again) {
      
$bundle = $this->getBundleFromValues($values);
    $entity_class = $this->getEntityClass($bundle);
    // @todo Decide what to do if preCreate() tries to change the bundle.     // @see https://www.drupal.org/project/drupal/issues/3230792     $entity_class::preCreate($this$values);

    // Assign a new UUID if there is none yet.     if ($this->uuidKey && $this->uuidService && !isset($values[$this->uuidKey])) {
      $values[$this->uuidKey] = $this->uuidService->generate();
    }

    $entity = $this->doCreate($values);
    $entity->enforceIsNew();

    $entity->postCreate($this);

    // Modules might need to add or change the data initially held by the new     // entity object, for instance to fill-in default values.     $this->invokeHook('create', $entity);

    return $entity;
  }

  

  public function create(array $values = []) {
    $entity_class = $this->getEntityClass();
    $entity_class::preCreate($this$values);

    // Assign a new UUID if there is none yet.     if ($this->uuidKey && $this->uuidService && !isset($values[$this->uuidKey])) {
      $values[$this->uuidKey] = $this->uuidService->generate();
    }

    $entity = $this->doCreate($values);
    $entity->enforceIsNew();

    $entity->postCreate($this);

    // Modules might need to add or change the data initially held by the new     // entity object, for instance to fill-in default values.     $this->invokeHook('create', $entity);

    return $entity;
  }

  
Home | Imprint | This part of the site doesn't use cookies.