当前位置: 首页>>代码示例>>PHP>>正文


PHP ContentEntityInterface::hasField方法代码示例

本文整理汇总了PHP中Drupal\Core\Entity\ContentEntityInterface::hasField方法的典型用法代码示例。如果您正苦于以下问题:PHP ContentEntityInterface::hasField方法的具体用法?PHP ContentEntityInterface::hasField怎么用?PHP ContentEntityInterface::hasField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Entity\ContentEntityInterface的用法示例。


在下文中一共展示了ContentEntityInterface::hasField方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: updateChildrensAncestry

 /**
  * Update ancestry field of any child that has this as its first parent.
  *
  * @var \Drupal\Core\Entity\EntityInterface $discussion
  *    A discussion node that may have had its ancestry updating.
  */
 public function updateChildrensAncestry(ContentEntityInterface $discussion)
 {
     if ($discussion->hasField('field_parents') && $discussion->hasField('field_ancestry') && $discussion->hasField('field_ancestry_plain')) {
         // If own ancestry has changed, update children's ancestry.
         $newAncestry = $discussion->field_ancestry->getValue();
         $oldAncestry = empty($discussion->original) ? NULL : $discussion->original->field_ancestry->getValue();
         if ($newAncestry !== $oldAncestry) {
             $children = $discussion->field_children->referencedEntities();
             $childAncestry = $newAncestry;
             $childAncestry[] = ["target_id" => $discussion->id()];
             foreach ($children as $child) {
                 // Only update children's ancestry if they are a discussion.
                 if ($child->bundle() == 'discussion') {
                     // Only update children's ancestry if this is their first parent.
                     if ($child->field_parents->entity->id() === $discussion->id()) {
                         // Only update children's ancestry if child is not already included.
                         if (!$this->withinAncestry($child, $childAncestry)) {
                             $child->field_ancestry = $childAncestry;
                             $child->field_ancestry_plain = $this->makePlain($child->field_ancestry);
                             $child->save();
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:shrimala,项目名称:ahsweb,代码行数:33,代码来源:Ancestry.php

示例2: getEntityReferenceTargetIds

  /**
   * {@inheritdoc}
   */
  public function getEntityReferenceTargetIds(ContentEntityInterface $entity, $field_name, $sort = FALSE) {
    $target_ids = [];
    if ($entity->hasField($field_name)) {
      $field_values = $entity->get($field_name)->getValue();

      foreach ($field_values as $field_value) {
        $target_ids[] = $field_value['target_id'];
      }
    }
    if ($sort) {
      asort($target_ids);
    }
    return $target_ids;
  }
开发者ID:joebachana,项目名称:usatne,代码行数:17,代码来源:BaseUpdateRunner.php

示例3: create

 /**
  * {@inheritdoc}
  */
 public function create(ContentEntityInterface $entity, $fields)
 {
     $query = $this->database->insert('comment_entity_statistics')->fields(array('entity_id', 'entity_type', 'field_name', 'cid', 'last_comment_timestamp', 'last_comment_name', 'last_comment_uid', 'comment_count'));
     foreach ($fields as $field_name => $detail) {
         // Skip fields that entity does not have.
         if (!$entity->hasField($field_name)) {
             continue;
         }
         // Get the user ID from the entity if it's set, or default to the
         // currently logged in user.
         $last_comment_uid = 0;
         if ($entity instanceof EntityOwnerInterface) {
             $last_comment_uid = $entity->getOwnerId();
         }
         if (!isset($last_comment_uid)) {
             // Default to current user when entity does not implement
             // EntityOwnerInterface or author is not set.
             $last_comment_uid = $this->currentUser->id();
         }
         // Default to REQUEST_TIME when entity does not have a changed property.
         $last_comment_timestamp = REQUEST_TIME;
         if ($entity instanceof EntityChangedInterface) {
             $last_comment_timestamp = $entity->getChangedTime();
         }
         $query->values(array('entity_id' => $entity->id(), 'entity_type' => $entity->getEntityTypeId(), 'field_name' => $field_name, 'cid' => 0, 'last_comment_timestamp' => $last_comment_timestamp, 'last_comment_name' => NULL, 'last_comment_uid' => $last_comment_uid, 'comment_count' => 0));
     }
     $query->execute();
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:31,代码来源:CommentStatistics.php

示例4: doEvaluate

 /**
  * Evaluate if the user has access to the field of an entity.
  *
  * @param \Drupal\Core\Entity\ContentEntityInterface $entity
  *   The entity to check access on.
  * @param string $field
  *   The name of the field to check access on.
  * @param string $operation
  *   The operation access should be checked for. Usually one of "view" or
  *   "edit".
  * @param \Drupal\Core\Session\AccountInterface $user
  *   The user account to test access against.
  *
  * @return bool
  *   TRUE if the user has access to the field on the entity, FALSE otherwise.
  */
 protected function doEvaluate(ContentEntityInterface $entity, $field, $operation, AccountInterface $user)
 {
     if (!$entity->hasField($field)) {
         return FALSE;
     }
     $access = $this->entityTypeManager->getAccessControlHandler($entity->getEntityTypeId());
     if (!$access->access($entity, $operation, $user)) {
         return FALSE;
     }
     $definition = $entity->getFieldDefinition($field);
     $items = $entity->get($field);
     return $access->fieldAccess($operation, $definition, $user, $items);
 }
开发者ID:Progressable,项目名称:openway8,代码行数:29,代码来源:UserHasEntityFieldAccess.php


注:本文中的Drupal\Core\Entity\ContentEntityInterface::hasField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。