当前位置: 首页>>代码示例>>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;未经允许,请勿转载。