Drupal 8  8.0.2
CommentManager Class Reference
Inheritance diagram for CommentManager:

Public Member Functions

 __construct (EntityManagerInterface $entity_manager, QueryFactory $query_factory, ConfigFactoryInterface $config_factory, TranslationInterface $string_translation, UrlGeneratorInterface $url_generator, ModuleHandlerInterface $module_handler, AccountInterface $current_user)
 
 getFields ($entity_type_id)
 
 addBodyField ($comment_type_id)
 
 forbiddenMessage (EntityInterface $entity, $field_name)
 
 getCountNewComments (EntityInterface $entity, $field_name=NULL, $timestamp=0)
 

Protected Attributes

 $entityManager
 
 $queryFactory
 
 $authenticatedCanPostComments
 
 $userConfig
 
 $moduleHandler
 
 $currentUser
 

Additional Inherited Members

- Data Fields inherited from CommentManagerInterface
const COMMENT_MODE_FLAT = 0
 
const COMMENT_MODE_THREADED = 1
 

Detailed Description

Comment manager contains common functions to manage comment fields.

Constructor & Destructor Documentation

__construct ( EntityManagerInterface  $entity_manager,
QueryFactory  $query_factory,
ConfigFactoryInterface  $config_factory,
TranslationInterface  $string_translation,
UrlGeneratorInterface  $url_generator,
ModuleHandlerInterface  $module_handler,
AccountInterface  $current_user 
)

Construct the CommentManager object.

Parameters
\Drupal\Core\Entity\EntityManagerInterface$entity_managerThe entity manager service.
\Drupal\Core\Entity\Query\QueryFactory$query_factoryThe entity query factory.
\Drupal\Core\Config\ConfigFactoryInterface$config_factoryThe config factory.
\Drupal\Core\StringTranslation\TranslationInterface$string_translationThe string translation service.
\Drupal\Core\Routing\UrlGeneratorInterface$url_generatorThe url generator service.
\Drupal\Core\Extension\ModuleHandlerInterface$module_handlerThe module handler service.
\Drupal\Core\Session\AccountInterface$current_userThe current user.

References Drupal\currentUser(), Drupal\entityManager(), Drupal\moduleHandler(), and Drupal\urlGenerator().

Here is the call graph for this function:

Member Function Documentation

addBodyField (   $comment_type_id)

{Creates a comment_body field.

Parameters
string$comment_typeThe comment bundle.
}

Implements CommentManagerInterface.

References Drupal\entityManager(), FieldConfig\loadByName(), and FieldStorageConfig\loadByName().

Here is the call graph for this function:

forbiddenMessage ( EntityInterface  $entity,
  $field_name 
)

{Provides a message if posting comments is forbidden.If authenticated users can post comments, a message is returned that prompts the anonymous user to log in (or register, if applicable) that redirects to entity comment form. Otherwise, no message is returned.

Parameters
\Drupal\Core\Entity\EntityInterface$entityThe entity to which comments are attached to.
string$field_nameThe field name on the entity to which comments are attached to.
Returns
string HTML for a "you can't post comments" notice.
}

Implements CommentManagerInterface.

References RoleInterface\AUTHENTICATED_ID, Drupal\entityManager(), CommentItemInterface\FORM_SEPARATE_PAGE, t(), Drupal\url(), and Drupal\urlGenerator().

Here is the call graph for this function:

getCountNewComments ( EntityInterface  $entity,
  $field_name = NULL,
  $timestamp = 0 
)

{Returns the number of new comments available on a given entity for a user.

Parameters
\Drupal\Core\Entity\EntityInterface$entityThe entity to which the comments are attached to.
string$field_name(optional) The field_name to count comments for. Defaults to any field.
int$timestamp(optional) Time to count from. Defaults to time of last user access the entity.
Returns
int|false The number of new comments or FALSE if the user is not authenticated.
}

Implements CommentManagerInterface.

References Drupal\currentUser(), Drupal\moduleHandler(), and CommentInterface\PUBLISHED.

Here is the call graph for this function:

getFields (   $entity_type_id)

{Utility function to return an array of comment fields.

Parameters
string$entity_type_idThe content entity type to which the comment fields are attached.
Returns
array An array of comment field map definitions, keyed by field name. Each value is an array with two entries:
  • type: The field type.
  • bundles: The bundles in which the field appears, as an array with entity types as keys and the array of bundle names as values.
See Also
::getFieldMap()
}

Implements CommentManagerInterface.

References Drupal\entityManager().

Here is the call graph for this function:


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