uuidGenerator example

/** * {@inheritdoc} */
  public function getPluginCollections() {
    return ['effects' => $this->getEffects()];
  }

  /** * {@inheritdoc} */
  public function addImageEffect(array $configuration) {
    $configuration['uuid'] = $this->uuidGenerator()->generate();
    $this->getEffects()->addInstanceId($configuration['uuid']$configuration);
    return $configuration['uuid'];
  }

  /** * {@inheritdoc} */
  public function getReplacementID() {
    /** @var \Drupal\image\ImageStyleStorageInterface $storage */
    $storage = $this->entityTypeManager()->getStorage($this->getEntityTypeId());
    return $storage->getReplacementId($this->id());
  }

  public function createDuplicate() {
    $duplicate = clone $this;
    $entity_type = $this->getEntityType();
    // Reset the entity ID and indicate that this is a new entity.     $duplicate->{$entity_type->getKey('id')} = NULL;
    $duplicate->enforceIsNew();

    // Check if the entity type supports UUIDs and generate a new one if so.     if ($entity_type->hasKey('uuid')) {
      $duplicate->{$entity_type->getKey('uuid')} = $this->uuidGenerator()->generate();
    }
    return $duplicate;
  }

  /** * {@inheritdoc} */
  public function getEntityType() {
    return $this->entityTypeManager()->getDefinition($this->getEntityTypeId());
  }

  


    $duplicate = clone $this;
    $entity_type = $this->getEntityType();
    if ($entity_type->hasKey('id')) {
      $duplicate->{$entity_type->getKey('id')}->value = NULL;
    }
    $duplicate->enforceIsNew();

    // Check if the entity type supports UUIDs and generate a new one if so.     if ($entity_type->hasKey('uuid')) {
      $duplicate->{$entity_type->getKey('uuid')}->value = $this->uuidGenerator()->generate();
    }

    // Check whether the entity type supports revisions and initialize it if so.     if ($entity_type->isRevisionable()) {
      $duplicate->{$entity_type->getKey('revision')}->value = NULL;
      $duplicate->loadedRevisionId = NULL;
    }

    return $duplicate;
  }

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