當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ContentEntityBase::preSave方法代碼示例

本文整理匯總了PHP中Drupal\Core\Entity\ContentEntityBase::preSave方法的典型用法代碼示例。如果您正苦於以下問題:PHP ContentEntityBase::preSave方法的具體用法?PHP ContentEntityBase::preSave怎麽用?PHP ContentEntityBase::preSave使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\Core\Entity\ContentEntityBase的用法示例。


在下文中一共展示了ContentEntityBase::preSave方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: preSave

 /**
  * {@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});
         }
     }
 }
開發者ID:davidsoloman,項目名稱:drupalconsole.com,代碼行數:29,代碼來源:User.php

示例2: preSave

 /**
  * {@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});
         }
     }
 }
開發者ID:Nikola-xiii,項目名稱:d8intranet,代碼行數:35,代碼來源:User.php

示例3: preSave

 /**
  * {@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());
     }
 }
開發者ID:marmouset,項目名稱:drupal,代碼行數:11,代碼來源:Store.php

示例4: preSave

 /**
  * {@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());
     }
 }
開發者ID:brstde,項目名稱:gap1,代碼行數:16,代碼來源:Node.php

示例5: preSave

 /**
  * {@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());
         }
     }
 }
開發者ID:marmouset,項目名稱:drupal,代碼行數:19,代碼來源:Order.php

示例6: preSave

 /**
  * {@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});
         }
     }
 }
開發者ID:ravindrasingh22,項目名稱:Drupal-8-rc,代碼行數:19,代碼來源:User.php

示例7: preSave

  /**
   * {@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);
    }
  }
開發者ID:jkyto,項目名稱:agolf,代碼行數:22,代碼來源:EntitySubqueue.php

示例8: preSave

 /**
  * {@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;
     }
 }
開發者ID:alexburrows,項目名稱:cream-2.x,代碼行數:26,代碼來源:Order.php

示例9: preSave

 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     // TODO: Change the autogenerated stub
 }
開發者ID:tedbow,項目名稱:scheduled-updates-demo,代碼行數:5,代碼來源:ScheduledUpdate.php

示例10: preSave

 /**
  * {@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);
     }
 }
開發者ID:nstielau,項目名稱:drops-8,代碼行數:12,代碼來源:MenuLinkContent.php

示例11: preSave

 /**
  * {@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());
     }
 }
開發者ID:HakS,項目名稱:drupal8_training,代碼行數:19,代碼來源:Node.php

示例12: preSave

 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     $url = Url::createFromPath($this->path->value);
     $this->setRouteName($url->getRouteName());
     $this->setRouteParams($url->getRouteParameters());
 }
開發者ID:anatalsceo,項目名稱:en-classe,代碼行數:10,代碼來源:Shortcut.php

示例13: preSave

 /**
  * {@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);
     }
 }
開發者ID:sgtsaughter,項目名稱:d8portfolio,代碼行數:12,代碼來源:File.php

示例14: preSave

 /**
  * {@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);
 }
開發者ID:justincletus,項目名稱:webdrupalpro,代碼行數:11,代碼來源:Order.php

示例15: preSave

 /**
  * {@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());
     }
 }
開發者ID:brstde,項目名稱:gap1,代碼行數:73,代碼來源:Comment.php


注:本文中的Drupal\Core\Entity\ContentEntityBase::preSave方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。