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


PHP ContentEntityInterface::getFieldDefinition方法代码示例

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


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

示例1: getNewCommentPageNumber

 /**
  * {@inheritdoc}
  */
 public function getNewCommentPageNumber($total_comments, $new_comments, ContentEntityInterface $entity, $field_name = 'comment')
 {
     $instance = $entity->getFieldDefinition($field_name);
     $comments_per_page = $instance->getSetting('per_page');
     if ($total_comments <= $comments_per_page) {
         // Only one page of comments.
         $count = 0;
     } elseif ($instance->getSetting('default_mode') == CommentManagerInterface::COMMENT_MODE_FLAT) {
         // Flat comments.
         $count = $total_comments - $new_comments;
     } else {
         // Threaded comments.
         // 1. Find all the threads with a new comment.
         $unread_threads_query = $this->database->select('comment_field_data', 'comment')->fields('comment', array('thread'))->condition('entity_id', $entity->id())->condition('entity_type', $entity->getEntityTypeId())->condition('field_name', $field_name)->condition('status', CommentInterface::PUBLISHED)->condition('default_langcode', 1)->orderBy('created', 'DESC')->orderBy('cid', 'DESC')->range(0, $new_comments);
         // 2. Find the first thread.
         $first_thread_query = $this->database->select($unread_threads_query, 'thread');
         $first_thread_query->addExpression('SUBSTRING(thread, 1, (LENGTH(thread) - 1))', 'torder');
         $first_thread = $first_thread_query->fields('thread', array('thread'))->orderBy('torder')->range(0, 1)->execute()->fetchField();
         // Remove the final '/'.
         $first_thread = substr($first_thread, 0, -1);
         // Find the number of the first comment of the first unread thread.
         $count = $this->database->query('SELECT COUNT(*) FROM {comment_field_data} WHERE entity_id = :entity_id
                     AND entity_type = :entity_type
                     AND field_name = :field_name
                     AND status = :status
                     AND SUBSTRING(thread, 1, (LENGTH(thread) - 1)) < :thread
                     AND default_langcode = 1', array(':status' => CommentInterface::PUBLISHED, ':entity_id' => $entity->id(), ':field_name' => $field_name, ':entity_type' => $entity->getEntityTypeId(), ':thread' => $first_thread))->fetchField();
     }
     return $comments_per_page > 0 ? (int) ($count / $comments_per_page) : 0;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:33,代码来源:CommentStorage.php


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