Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     // Update the user password if it has changed.
     if ($this->isNew() || $this->pass->value && $this->pass->value != $this->original->pass->value) {
         // Allow alternate password hashing schemes.
         $this->pass->value = \Drupal::service('password')->hash(trim($this->pass->value));
         // Abort if the hashing failed and returned FALSE.
         if (!$this->pass->value) {
             throw new EntityMalformedException('The entity does not have a password.');
         }
     }
     if (!$this->isNew()) {
         // If the password is empty, that means it was not changed, so use the
         // original password.
         if (empty($this->pass->value)) {
             $this->pass->value = $this->original->pass->value;
         }
     }
     // Store account cancellation information.
     foreach (array('user_cancel_method', 'user_cancel_notify') as $key) {
         if (isset($this->{$key})) {
             \Drupal::service('user.data')->set('user', $this->id(), substr($key, 5), $this->{$key});
         }
     }
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     // Make sure that the authenticated/anonymous roles are not persisted.
     foreach ($this->get('roles') as $index => $item) {
         if (in_array($item->target_id, array(RoleInterface::ANONYMOUS_ID, RoleInterface::AUTHENTICATED_ID))) {
             $this->get('roles')->offsetUnset($index);
         }
     }
     // Update the user password if it has changed.
     if ($this->isNew() || $this->pass->value && $this->pass->value != $this->original->pass->value) {
         // Allow alternate password hashing schemes.
         $this->pass->value = \Drupal::service('password')->hash(trim($this->pass->value));
         // Abort if the hashing failed and returned FALSE.
         if (!$this->pass->value) {
             throw new EntityMalformedException('The entity does not have a password.');
         }
     }
     if (!$this->isNew()) {
         // If the password is empty, that means it was not changed, so use the
         // original password.
         if (empty($this->pass->value)) {
             $this->pass->value = $this->original->pass->value;
         }
     }
     // Store account cancellation information.
     foreach (array('user_cancel_method', 'user_cancel_notify') as $key) {
         if (isset($this->{$key})) {
             \Drupal::service('user.data')->set('user', $this->id(), substr($key, 5), $this->{$key});
         }
     }
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     // If no owner has been set explicitly, make the current user the owner.
     if (!$this->getOwner()) {
         $this->setOwnerId($this->getCurrentUserId());
     }
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     // If no owner has been set explicitly, make the current user the owner.
     if (!$this->getOwner()) {
         $this->setOwnerId(\Drupal::currentUser()->id());
     }
     // If no revision author has been set explicitly, make the node owner the
     // revision author.
     if (!$this->getRevisionAuthor()) {
         $this->setRevisionAuthorId($this->getOwnerId());
     }
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     // If no owner has been set explicitly, make the current user the owner.
     if (!$this->getOwner()) {
         $this->setOwnerId(\Drupal::currentUser()->id());
     }
     if ($this->isNew()) {
         if (!$this->getIpAddress()) {
             $this->setIpAddress(\Drupal::request()->getClientIp());
         }
         if (!$this->getEmail()) {
             $this->setEmail($this->getOwner()->getEmail());
         }
     }
 }
Пример #6
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     // Make sure that the authenticated/anonymous roles are not persisted.
     foreach ($this->get('roles') as $index => $item) {
         if (in_array($item->target_id, array(RoleInterface::ANONYMOUS_ID, RoleInterface::AUTHENTICATED_ID))) {
             $this->get('roles')->offsetUnset($index);
         }
     }
     // Store account cancellation information.
     foreach (array('user_cancel_method', 'user_cancel_notify') as $key) {
         if (isset($this->{$key})) {
             \Drupal::service('user.data')->set('user', $this->id(), substr($key, 5), $this->{$key});
         }
     }
 }
Пример #7
0
  /**
   * {@inheritdoc}
   */
  public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);

    /** @var \Drupal\entityqueue\EntityQueueInterface $queue */
    $queue = $this->getQueue();
    $max_size = $queue->getMaximumSize();
    $act_as_queue = $queue->getActAsQueue();

    $items = $this->get('items')->getValue();
    $number_of_items = count($items);

    // Remove extra items from the front of the queue if the maximum size is
    // exceeded.
    if ($act_as_queue && $number_of_items > $max_size) {
      $items = array_slice($items, -$max_size);

      $this->set('items', $items);
    }
  }
Пример #8
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     // If no owner has been set explicitly, make the current user the owner.
     if (!$this->getOwner()) {
         $this->setOwnerId(\Drupal::currentUser()->id());
     }
     if ($this->isNew()) {
         if (!$this->getIpAddress()) {
             $this->setIpAddress(\Drupal::request()->getClientIp());
         }
         if (!$this->getEmail()) {
             $this->setEmail($this->getOwner()->getEmail());
         }
     }
     // Recalculate the total.
     // @todo Rework this once pricing is finished.
     $this->total_price->amount = 0;
     foreach ($this->getLineItems() as $line_item) {
         $this->total_price->amount += $line_item->total_price->amount;
         $this->total_price->currency_code = $line_item->total_price->currency_code;
     }
 }
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     // TODO: Change the autogenerated stub
 }
Пример #10
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     if (parse_url($this->link->uri, PHP_URL_SCHEME) === 'internal') {
         $this->setRequiresRediscovery(TRUE);
     } else {
         $this->setRequiresRediscovery(FALSE);
     }
 }
Пример #11
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     foreach (array_keys($this->getTranslationLanguages()) as $langcode) {
         $translation = $this->getTranslation($langcode);
         // If no owner has been set explicitly, make the anonymous user the owner.
         if (!$translation->getOwner()) {
             $translation->setOwnerId(0);
         }
     }
     // If no revision author has been set explicitly, make the node owner the
     // revision author.
     if (!$this->getRevisionAuthor()) {
         $this->setRevisionAuthorId($this->getOwnerId());
     }
 }
Пример #12
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     $url = Url::createFromPath($this->path->value);
     $this->setRouteName($url->getRouteName());
     $this->setRouteParams($url->getRouteParameters());
 }
Пример #13
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     // The file itself might not exist or be available right now.
     $uri = $this->getFileUri();
     if ($size = @filesize($uri)) {
         $this->setSize($size);
     }
 }
Пример #14
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     $this->order_total->value = $this->getTotal();
     $this->product_count->value = $this->getProductCount();
     $this->host->value = \Drupal::request()->getClientIp();
     $this->setChangedTime(REQUEST_TIME);
 }
Пример #15
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     if (is_null($this->get('status')->value)) {
         $published = \Drupal::currentUser()->hasPermission('skip comment approval') ? CommentInterface::PUBLISHED : CommentInterface::NOT_PUBLISHED;
         $this->setPublished($published);
     }
     if ($this->isNew()) {
         // Add the comment to database. This next section builds the thread field.
         // Also see the documentation for comment_view().
         $thread = $this->getThread();
         if (empty($thread)) {
             if ($this->threadLock) {
                 // Thread lock was not released after being set previously.
                 // This suggests there's a bug in code using this class.
                 throw new \LogicException('preSave() is called again without calling postSave() or releaseThreadLock()');
             }
             if (!$this->hasParentComment()) {
                 // This is a comment with no parent comment (depth 0): we start
                 // by retrieving the maximum thread level.
                 $max = $storage->getMaxThread($this);
                 // Strip the "/" from the end of the thread.
                 $max = rtrim($max, '/');
                 // We need to get the value at the correct depth.
                 $parts = explode('.', $max);
                 $n = Number::alphadecimalToInt($parts[0]);
                 $prefix = '';
             } else {
                 // This is a comment with a parent comment, so increase the part of
                 // the thread value at the proper depth.
                 // Get the parent comment:
                 $parent = $this->getParentComment();
                 // Strip the "/" from the end of the parent thread.
                 $parent->setThread((string) rtrim((string) $parent->getThread(), '/'));
                 $prefix = $parent->getThread() . '.';
                 // Get the max value in *this* thread.
                 $max = $storage->getMaxThreadPerThread($this);
                 if ($max == '') {
                     // First child of this parent. As the other two cases do an
                     // increment of the thread number before creating the thread
                     // string set this to -1 so it requires an increment too.
                     $n = -1;
                 } else {
                     // Strip the "/" at the end of the thread.
                     $max = rtrim($max, '/');
                     // Get the value at the correct depth.
                     $parts = explode('.', $max);
                     $parent_depth = count(explode('.', $parent->getThread()));
                     $n = Number::alphadecimalToInt($parts[$parent_depth]);
                 }
             }
             // Finally, build the thread field for this new comment. To avoid
             // race conditions, get a lock on the thread. If another process already
             // has the lock, just move to the next integer.
             do {
                 $thread = $prefix . Number::intToAlphadecimal(++$n) . '/';
                 $lock_name = "comment:{$this->getCommentedEntityId()}:{$thread}";
             } while (!\Drupal::lock()->acquire($lock_name));
             $this->threadLock = $lock_name;
         }
         // We test the value with '===' because we need to modify anonymous
         // users as well.
         if ($this->getOwnerId() === \Drupal::currentUser()->id() && \Drupal::currentUser()->isAuthenticated()) {
             $this->setAuthorName(\Drupal::currentUser()->getUsername());
         }
         // Add the values which aren't passed into the function.
         $this->setThread($thread);
         $this->setHostname(\Drupal::request()->getClientIP());
     }
 }
Пример #16
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage_controller, $update = TRUE)
 {
     parent::preSave($storage_controller, $update);
     $this->ensureSecret();
     $this->ensureToken();
     $this->validateState();
 }
Пример #17
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     if ($this->getJobId()) {
         $this->recalculateStatistics();
     }
     if ($this->unserializedData) {
         $this->data = serialize($this->unserializedData);
     } elseif (empty($this->get('data')->value)) {
         $this->data = serialize(array());
     }
 }
Пример #18
0
  /**
   * {@inheritdoc}
   */
  public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);

    // If no revision author has been set explicitly, make the current user
    // revision author.
    if (!$this->get('revision_uid')->entity) {
      $this->set('revision_uid', \Drupal::currentUser()->id());
    }

    // Try to set URI if not yet defined.
    if (empty($this->uri->value) && !empty($this->entity_type->value) && !empty($this->entity_id->value)) {
      $entity = \Drupal::entityManager()->getStorage($this->entity_type->value)->load($this->entity_id->value);
      if ($uri = $this->provider()->uri($entity)) {
        $this->set('uri', $uri);
      }
    }
  }
Пример #19
0
  /**
   * {@inheritdoc}
   */
  public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);

    // If no owner has been set explicitly, make the current user the owner.
    if (!$this->getOwner()) {
      // @todo Copy from Node.php should dependency inject be used to get current user?
      $this->setOwnerId(\Drupal::currentUser()->id());
    }
    // If no revision author has been set explicitly, make the node owner the
    // revision author.
    if (!$this->getRevisionAuthor()) {
      $this->setRevisionAuthorId($this->getOwnerId());
    }
  }
Пример #20
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     $this->total_price->amount = $this->unit_price->amount * $this->quantity->value;
     $this->total_price->currency_code = $this->unit_price->currency_code;
 }
Пример #21
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     // Make sure any configuration changes will be persisted.
     $configuration = $this->getBlock()->getConfiguration();
     // Make sure the block uuid is the same as the entity uuid. This makes it
     // easier to update block configuration since you can rely on the entity
     // uuid value.
     if (!isset($configuration['uuid']) || $configuration['uuid'] !== $this->uuid()) {
         $configuration['uuid'] = $this->uuid();
     }
     $this->set('config', $configuration);
 }
Пример #22
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     /** @var \Drupal\commerce_product\Entity\ProductVariationTypeInterface $variation_type */
     $variation_type = $this->entityTypeManager()->getStorage('commerce_product_variation_type')->load($this->bundle());
     if ($variation_type->shouldGenerateTitle()) {
         $title = $this->generateTitle();
         $this->setTitle($title);
     }
 }
Пример #23
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     // @todo fix PathValidatorInterface::getUrlIfValid() so we can use it
     //   here. The problem is that we need an exception, not a FALSE
     //   return value. https://www.drupal.org/node/2346695
     if ($this->path->value == '<front>') {
         $url = new Url($this->path->value);
     } else {
         $url = Url::createFromRequest(Request::create("/{$this->path->value}"));
     }
     $this->setRouteName($url->getRouteName());
     $this->setRouteParameters($url->getRouteParameters());
 }
Пример #24
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     // Create the token value as a digestion of the values in the token. This
     // will allow us to check integrity of the token later.
     if ($this->get('value')->isEmpty()) {
         $value = AccessTokenValue::createFromValues($this->normalize())->digest();
         $this->set('value', $value);
     }
 }
Пример #25
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     $this->setSize(filesize($this->getFileUri()));
 }
Пример #26
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     $this->setActivityType($this->getActivity()->bundle());
 }
Пример #27
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     if (!$this->getEvent() instanceof ContentEntityBase) {
         throw new EntityMalformedException('Invalid or missing event on registration.');
     }
     // Add group defaults event settings.
     /* @var $event_manager \Drupal\rng\EventManagerInterface */
     $event_manager = \Drupal::service('rng.event_manager');
     $event_meta = $event_manager->getMeta($this->getEvent());
     if ($this->isNew()) {
         foreach ($event_meta->getDefaultGroups() as $group) {
             $this->addGroup($group);
         }
     }
 }
Пример #28
0
 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     if ($this->isContinuous() && !$this->isContinuousInactive() && !$this->isAborted()) {
         $this->state = Job::STATE_CONTINUOUS;
     }
     // Activate job item if the previous job state was not active.
     if ($this->isActive() && !$this->original->isActive()) {
         foreach ($this->getItems() as $item) {
             // The job was submitted, activate any inactive job item.
             if ($item->isInactive()) {
                 $item->setState(JobItemInterface::STATE_ACTIVE);
             }
         }
     }
 }