Drupal 8  8.0.2
CommentStorage Class Reference
Inheritance diagram for CommentStorage:

Public Member Functions

 __construct (EntityTypeInterface $entity_info, Connection $database, EntityManagerInterface $entity_manager, AccountInterface $current_user, CacheBackendInterface $cache, LanguageManagerInterface $language_manager)
 
 getMaxThread (CommentInterface $comment)
 
 getMaxThreadPerThread (CommentInterface $comment)
 
 getDisplayOrdinal (CommentInterface $comment, $comment_mode, $divisor=1)
 
 getNewCommentPageNumber ($total_comments, $new_comments, FieldableEntityInterface $entity, $field_name)
 
 getChildCids (array $comments)
 
 loadThread (EntityInterface $entity, $field_name, $mode, $comments_per_page=0, $pager_id=0)
 
 getUnapprovedCount ()
 
- Public Member Functions inherited from SqlContentEntityStorage
 getFieldStorageDefinitions ()
 
 __construct (EntityTypeInterface $entity_type, Connection $database, EntityManagerInterface $entity_manager, CacheBackendInterface $cache, LanguageManagerInterface $language_manager)
 
 getBaseTable ()
 
 getRevisionTable ()
 
 getDataTable ()
 
 getRevisionDataTable ()
 
 setEntityType (EntityTypeInterface $entity_type)
 
 getTableMapping (array $storage_definitions=NULL)
 
 delete (array $entities)
 
 save (EntityInterface $entity)
 
 requiresEntityStorageSchemaChanges (EntityTypeInterface $entity_type, EntityTypeInterface $original)
 
 requiresFieldStorageSchemaChanges (FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)
 
 requiresEntityDataMigration (EntityTypeInterface $entity_type, EntityTypeInterface $original)
 
 requiresFieldDataMigration (FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)
 
 onEntityTypeCreate (EntityTypeInterface $entity_type)
 
 onEntityTypeUpdate (EntityTypeInterface $entity_type, EntityTypeInterface $original)
 
 onEntityTypeDelete (EntityTypeInterface $entity_type)
 
 onFieldStorageDefinitionCreate (FieldStorageDefinitionInterface $storage_definition)
 
 onFieldStorageDefinitionUpdate (FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)
 
 onFieldStorageDefinitionDelete (FieldStorageDefinitionInterface $storage_definition)
 
 onFieldDefinitionDelete (FieldDefinitionInterface $field_definition)
 
 onBundleCreate ($bundle, $entity_type_id)
 
 onBundleDelete ($bundle, $entity_type_id)
 
 finalizePurge (FieldStorageDefinitionInterface $storage_definition)
 
 countFieldData ($storage_definition, $as_bool=FALSE)
 
- Public Member Functions inherited from ContentEntityStorageBase
 __construct (EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, CacheBackendInterface $cache)
 
 hasData ()
 
 createTranslation (ContentEntityInterface $entity, $langcode, array $values=[])
 
 onFieldStorageDefinitionCreate (FieldStorageDefinitionInterface $storage_definition)
 
 onFieldStorageDefinitionUpdate (FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original)
 
 onFieldStorageDefinitionDelete (FieldStorageDefinitionInterface $storage_definition)
 
 onFieldDefinitionCreate (FieldDefinitionInterface $field_definition)
 
 onFieldDefinitionUpdate (FieldDefinitionInterface $field_definition, FieldDefinitionInterface $original)
 
 onFieldDefinitionDelete (FieldDefinitionInterface $field_definition)
 
 purgeFieldData (FieldDefinitionInterface $field_definition, $batch_size)
 
 finalizePurge (FieldStorageDefinitionInterface $storage_definition)
 
 loadRevision ($revision_id)
 
 resetCache (array $ids=NULL)
 
- Public Member Functions inherited from EntityStorageBase
 __construct (EntityTypeInterface $entity_type)
 
 getEntityTypeId ()
 
 getEntityType ()
 
 loadUnchanged ($id)
 
 resetCache (array $ids=NULL)
 
 create (array $values=array())
 
 load ($id)
 
 loadMultiple (array $ids=NULL)
 
 delete (array $entities)
 
 save (EntityInterface $entity)
 
 loadByProperties (array $values=array())
 
 getQuery ($conjunction= 'AND')
 
 getAggregateQuery ($conjunction= 'AND')
 
- Public Member Functions inherited from EntityHandlerBase
 setModuleHandler (ModuleHandlerInterface $module_handler)
 
- Public Member Functions inherited from EntityStorageInterface
 deleteRevision ($revision_id)
 

Static Public Member Functions

static createInstance (ContainerInterface $container, EntityTypeInterface $entity_info)
 
- Static Public Member Functions inherited from SqlContentEntityStorage
static createInstance (ContainerInterface $container, EntityTypeInterface $entity_type)
 
- Static Public Member Functions inherited from ContentEntityStorageBase
static createInstance (ContainerInterface $container, EntityTypeInterface $entity_type)
 

Protected Attributes

 $currentUser
 
- Protected Attributes inherited from SqlContentEntityStorage
 $tableMapping
 
 $revisionKey = FALSE
 
 $langcodeKey = FALSE
 
 $defaultLangcodeKey = FALSE
 
 $baseTable
 
 $revisionTable
 
 $dataTable
 
 $revisionDataTable
 
 $database
 
 $storageSchema
 
 $languageManager
 
- Protected Attributes inherited from ContentEntityStorageBase
 $bundleKey = FALSE
 
 $entityManager
 
 $cacheBackend
 
- Protected Attributes inherited from EntityStorageBase
 $entities = array()
 
 $entityTypeId
 
 $entityType
 
 $idKey
 
 $uuidKey
 
 $langcodeKey
 
 $uuidService
 
 $entityClass
 
- Protected Attributes inherited from EntityHandlerBase
 $moduleHandler
 

Additional Inherited Members

- Data Fields inherited from EntityStorageInterface
const FIELD_LOAD_CURRENT = 'FIELD_LOAD_CURRENT'
 
const FIELD_LOAD_REVISION = 'FIELD_LOAD_REVISION'
 
- Protected Member Functions inherited from SqlContentEntityStorage
 initTableLayout ()
 
 getStorageSchema ()
 
 doLoadMultiple (array $ids=NULL)
 
 getFromStorage (array $ids=NULL)
 
 mapFromStorageRecords (array $records, $load_from_revision=FALSE)
 
 loadFromSharedTables (array &$values, array &$translations)
 
 doLoadRevisionFieldItems ($revision_id)
 
 doDeleteRevisionFieldItems (ContentEntityInterface $revision)
 
 buildPropertyQuery (QueryInterface $entity_query, array $values)
 
 buildQuery ($ids, $revision_id=FALSE)
 
 doDeleteFieldItems ($entities)
 
 doSaveFieldItems (ContentEntityInterface $entity, array $names=[])
 
 has ($id, EntityInterface $entity)
 
 saveToSharedTables (ContentEntityInterface $entity, $table_name=NULL, $new_revision=NULL)
 
 mapToStorageRecord (ContentEntityInterface $entity, $table_name=NULL)
 
 isColumnSerial ($table_name, $schema_name)
 
 mapToDataStorageRecord (EntityInterface $entity, $table_name=NULL)
 
 saveRevision (ContentEntityInterface $entity)
 
 getQueryServiceName ()
 
 loadFromDedicatedTables (array &$values, $load_from_revision)
 
 saveToDedicatedTables (ContentEntityInterface $entity, $update=TRUE, $names=array())
 
 deleteFromDedicatedTables (ContentEntityInterface $entity)
 
 deleteRevisionFromDedicatedTables (ContentEntityInterface $entity)
 
 wrapSchemaException (callable $callback)
 
 readFieldItemsToPurge (FieldDefinitionInterface $field_definition, $batch_size)
 
 purgeFieldItems (ContentEntityInterface $entity, FieldDefinitionInterface $field_definition)
 
 storageDefinitionIsDeleted (FieldStorageDefinitionInterface $storage_definition)
 
- Protected Member Functions inherited from ContentEntityStorageBase
 doCreate (array $values)
 
 initFieldValues (ContentEntityInterface $entity, array $values=[], array $field_names=[])
 
 readFieldItemsToPurge (FieldDefinitionInterface $field_definition, $batch_size)
 
 purgeFieldItems (ContentEntityInterface $entity, FieldDefinitionInterface $field_definition)
 
 doLoadRevisionFieldItems ($revision_id)
 
 doSaveFieldItems (ContentEntityInterface $entity, array $names=[])
 
 doDeleteFieldItems ($entities)
 
 doDeleteRevisionFieldItems (ContentEntityInterface $revision)
 
 invokeTranslationHooks (ContentEntityInterface $entity)
 
 invokeStorageLoadHook (array &$entities)
 
 invokeFieldMethod ($method, ContentEntityInterface $entity)
 
 invokeFieldPostSave (ContentEntityInterface $entity, $update)
 
 hasFieldValueChanged (FieldDefinitionInterface $field_definition, ContentEntityInterface $entity, ContentEntityInterface $original)
 
 populateAffectedRevisionTranslations (ContentEntityInterface $entity)
 
 cleanIds (array $ids)
 
 getFromPersistentCache (array &$ids=NULL)
 
 setPersistentCache ($entities)
 
 buildCacheId ($id)
 
- Protected Member Functions inherited from EntityStorageBase
 getFromStaticCache (array $ids)
 
 setStaticCache (array $entities)
 
 invokeHook ($hook, EntityInterface $entity)
 
 doCreate (array $values)
 
 doLoadMultiple (array $ids=NULL)
 
 postLoad (array &$entities)
 
 mapFromStorageRecords (array $records)
 
 has ($id, EntityInterface $entity)
 
 doDelete ($entities)
 
 doPreSave (EntityInterface $entity)
 
 doSave ($id, EntityInterface $entity)
 
 doPostSave (EntityInterface $entity, $update)
 
 buildPropertyQuery (QueryInterface $entity_query, array $values)
 
 getQueryServiceName ()
 
- Protected Member Functions inherited from EntityHandlerBase
 moduleHandler ()
 

Detailed Description

Defines the controller class for comments.

This extends the Drupal class, adding required special handling for comment entities.

Constructor & Destructor Documentation

__construct ( EntityTypeInterface  $entity_info,
Connection  $database,
EntityManagerInterface  $entity_manager,
AccountInterface  $current_user,
CacheBackendInterface  $cache,
LanguageManagerInterface  $language_manager 
)

Constructs a CommentStorage object.

Parameters
\Drupal\Core\Entity\EntityTypeInterface$entity_infoAn array of entity info for the entity type.
\Drupal\Core\Database\Connection$databaseThe database connection to be used.
\Drupal\Core\Entity\EntityManagerInterface$entity_managerThe entity manager.
\Drupal\Core\Session\AccountInterface$current_userThe current user.
\Drupal\Core\Cache\CacheBackendInterface$cacheCache backend instance to use.
\Drupal\Core\Language\LanguageManagerInterface$language_managerThe language manager.

References Drupal\currentUser().

Here is the call graph for this function:

Member Function Documentation

static createInstance ( ContainerInterface  $container,
EntityTypeInterface  $entity_info 
)
static

{}

getChildCids ( array  $comments)

{Gets the comment ids of the passed comment entities' children.

Parameters
\Drupal\comment\CommentInterface[]$comments An array of comment entities keyed by their ids.
Returns
array The entity ids of the passed comment entities' children as an array.
}

Implements CommentStorageInterface.

References Drupal\database().

Here is the call graph for this function:

getDisplayOrdinal ( CommentInterface  $comment,
  $comment_mode,
  $divisor = 1 
)

{Gets the display ordinal or page number for a comment.

Parameters
\Drupal\comment\CommentInterface$commentThe comment to use as a reference point.
int$comment_modeThe comment display mode: CommentManagerInterface::COMMENT_MODE_FLAT or CommentManagerInterface::COMMENT_MODE_THREADED.
int$divisorDefaults to 1, which returns the display ordinal for a comment. If the number of comments per page is provided, the returned value will be the page number. (The return value will be divided by $divisor.)
Returns
int The display ordinal or page number for the comment. It is 0-based, so will represent the number of items before the given comment/page.
}

Implements CommentStorageInterface.

References CommentManagerInterface\COMMENT_MODE_FLAT, Drupal\currentUser(), Drupal\database(), EntityInterface\id(), and CommentInterface\PUBLISHED.

Here is the call graph for this function:

getMaxThread ( CommentInterface  $comment)

{Gets the maximum encoded thread value for the top level comments.

Parameters
\Drupal\comment\CommentInterface$commentA comment entity.
Returns
string The maximum encoded thread value among the top level comments of the node $comment belongs to.
}

Implements CommentStorageInterface.

References Drupal\database(), CommentInterface\getCommentedEntityId(), CommentInterface\getCommentedEntityTypeId(), and CommentInterface\getFieldName().

Here is the call graph for this function:

getMaxThreadPerThread ( CommentInterface  $comment)

{Gets the maximum encoded thread value for the children of this comment.

Parameters
\Drupal\comment\CommentInterface$commentA comment entity.
Returns
string The maximum encoded thread value among all replies of $comment.
}

Implements CommentStorageInterface.

References Drupal\database(), CommentInterface\getCommentedEntityId(), CommentInterface\getCommentedEntityTypeId(), CommentInterface\getFieldName(), and CommentInterface\getParentComment().

Here is the call graph for this function:

getNewCommentPageNumber (   $total_comments,
  $new_comments,
FieldableEntityInterface  $entity,
  $field_name 
)

{Calculates the page number for the first new comment.

Parameters
int$total_commentsThe total number of comments that the entity has.
int$new_commentsThe number of new comments that the entity has.
\Drupal\Core\Entity\FieldableEntityInterface$entityThe entity to which the comments belong.
string$field_nameThe field name on the entity to which comments are attached.
Returns
array|null The page number where first new comment appears. (First page returns 0.)
}

Implements CommentStorageInterface.

References CommentManagerInterface\COMMENT_MODE_FLAT, Drupal\database(), and CommentInterface\PUBLISHED.

Here is the call graph for this function:

getUnapprovedCount ( )

{Returns the number of unapproved comments.

Returns
int The number of unapproved comments.
}

Implements CommentStorageInterface.

References Drupal\database(), and CommentInterface\NOT_PUBLISHED.

Here is the call graph for this function:

loadThread ( EntityInterface  $entity,
  $field_name,
  $mode,
  $comments_per_page = 0,
  $pager_id = 0 
)

{Retrieves comments for a thread, sorted in an order suitable for display.

Parameters
\Drupal\Core\Entity\EntityInterface$entityThe entity whose comment(s) needs rendering.
string$field_nameThe field_name whose comment(s) needs rendering.
int$modeThe comment display mode: CommentManagerInterface::COMMENT_MODE_FLAT or CommentManagerInterface::COMMENT_MODE_THREADED.
int$comments_per_page(optional) The amount of comments to display per page. Defaults to 0, which means show all comments.
int$pager_id(optional) Pager id to use in case of multiple pagers on the one page. Defaults to 0; is only used when $comments_per_page is greater than zero.
Returns
array Ordered array of comment objects, keyed by comment id.
}

To display threaded comments in the correct order we keep a 'thread' field and order by that value. This field keeps this data in a way which is easy to update and convenient to use.

A "thread" value starts at "1". If we add a child (A) to this comment, we assign it a "thread" = "1.1". A child of (A) will have "1.1.1". Next brother of (A) will get "1.2". Next brother of the parent of (A) will get "2" and so on.

First of all note that the thread field stores the depth of the comment: depth 0 will be "X", depth 1 "X.X", depth 2 "X.X.X", etc.

Now to get the ordering right, consider this example:

1 1.1 1.1.1 1.2 2

If we "ORDER BY thread ASC" we get the above result, and this is the natural order sorted by time. However, if we "ORDER BY thread DESC" we get:

2 1.2 1.1.1 1.1 1

Clearly, this is not a natural way to see a thread, and users will get confused. The natural order to show a thread by time desc would be:

2 1 1.2 1.1 1.1.1

which is what we already did before the standard pager patch. To achieve this we simply add a "/" at the end of each "thread" value. This way, the thread fields will look like this:

1/ 1.1/ 1.1.1/ 1.2/ 2/

we add "/" since this char is, in ASCII, higher than every number, so if now we "ORDER BY thread DESC" we get the correct order. However this would spoil the reverse ordering, "ORDER BY thread ASC" – here, we do not need to consider the trailing "/" so we use a substring only.

Implements CommentStorageInterface.

References CommentManagerInterface\COMMENT_MODE_FLAT, Drupal\currentUser(), Drupal\database(), EntityStorageBase\loadMultiple(), and CommentInterface\PUBLISHED.

Here is the call graph for this function:


The documentation for this class was generated from the following file: