postCreate example

/** * {@inheritdoc} */
  public function getWeight() {
    return $this->weight;
  }

  /** * {@inheritdoc} */
  public function postCreate(EntityStorageInterface $storage) {
    parent::postCreate($storage);

    // @todo Use self::applyDefaultValue() once     // https://www.drupal.org/node/2004756 is in.     if (!isset($this->weight)) {
      $this->weight = $this->isDefaultSearch() ? -10 : 0;
    }
  }

  /** * {@inheritdoc} */
  
    if (empty($values['bundle'])) {
      throw new FieldException("Attempt to create a field '{$values['field_name']}' without a bundle.");
    }

    parent::__construct($values$entity_type);
  }

  /** * {@inheritdoc} */
  public function postCreate(EntityStorageInterface $storage) {
    parent::postCreate($storage);

    // Validate that we have a valid storage for this field. This throws an     // exception if the storage is invalid.     $this->getFieldStorageDefinition();

    // 'Label' defaults to the field name (mostly useful for fields created in     // tests).     if (empty($this->label)) {
      $this->label = $this->getName();
    }
  }

  
'position' => 0,
          'display_options' => [],
        ],
      ],
    ];
  }

  /** * {@inheritdoc} */
  public function postCreate(EntityStorageInterface $storage) {
    parent::postCreate($storage);

    $this->mergeDefaultDisplaysOptions();
  }

  /** * {@inheritdoc} */
  public static function preDelete(EntityStorageInterface $storage, array $entities) {
    parent::preDelete($storage$entities);

    // Call the remove() hook on the individual displays.

  public static function preCreate(EntityStorageInterface $storage, array &$values) {
    parent::preCreate($storage$values);
    self::$preCreateCount++;
  }

  /** * {@inheritdoc} */
  public function postCreate(EntityStorageInterface $storage) {
    parent::postCreate($storage);
    $this->postCreateCount++;
  }

  /** * {@inheritdoc} */
  public static function preDelete(EntityStorageInterface $storage, array $entities) {
    parent::preDelete($storage$entities);
    self::$preDeleteCount++;
  }

  
protected function _doCreateFromStorageRecord(array $values$is_syncing = FALSE) {
    // Assign a new UUID if there is none yet.     if ($this->uuidKey && $this->uuidService && !isset($values[$this->uuidKey])) {
      $values[$this->uuidKey] = $this->uuidService->generate();
    }
    $data = $this->mapFromStorageRecords([$values]);
    /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
    $entity = current($data);
    $entity->original = clone $entity;
    $entity->setSyncing($is_syncing);
    $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;

  }

  /** * {@inheritdoc} */
  
/** * {@inheritdoc} */
  public static function preCreate(EntityStorageInterface $storage, array &$values) {
  }

  /** * {@inheritdoc} */
  public function postCreate(EntityStorageInterface $storage) {
    $this->storage->postCreate($storage);
  }

  /** * {@inheritdoc} */
  public static function preDelete(EntityStorageInterface $storage, array $entities) {
  }

  /** * {@inheritdoc} */
  
$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;
  }

  /** * Performs storage-specific creation of entities. * * @param array $values * An array of values to set, keyed by property name. * * @return \Drupal\Core\Entity\EntityInterface */
    // @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;
  }

  /** * {@inheritdoc} */
  
$definition = $field_type_manager->getDefinition($this->getType());
    if ($definition['class']::onDependencyRemoval($this$dependencies)) {
      $changed = TRUE;
    }
    return $changed;
  }

  /** * {@inheritdoc} */
  public function postCreate(EntityStorageInterface $storage) {
    parent::postCreate($storage);
    // If it was not present in the $values passed to create(), (e.g. for     // programmatic creation), populate the denormalized field_type property     // from the field storage, so that it gets saved in the config record.     if (empty($this->field_type)) {
      $this->field_type = $this->getFieldStorageDefinition()->getType();
    }
  }

  /** * {@inheritdoc} */
  
// Our mocked entity->preCreate() returns NULL, so assert that.     $this->assertNull($this->entity->preCreate($storage$values));
  }

  /** * @covers ::postCreate */
  public function testPostCreate() {
    // This method is internal, so check for errors on calling it only.     $storage = $this->createMock('\Drupal\Core\Entity\EntityStorageInterface');
    // Our mocked entity->postCreate() returns NULL, so assert that.     $this->assertNull($this->entity->postCreate($storage));
  }

  /** * @covers ::preDelete */
  public function testPreDelete() {
    // This method is internal, so check for errors on calling it only.     $storage = $this->createMock('\Drupal\Core\Entity\EntityStorageInterface');
    // Our mocked entity->preDelete() returns NULL, so assert that.     $this->assertNull($this->entity->preDelete($storage[$this->entity]));
  }

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