CommentManager
class CommentManager implements CommentManagerInterface (View source)
Comment manager contains common functions to manage comment fields.
Traits
Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.
Properties
| protected TranslationInterface | $stringTranslation | The string translation service. |
from StringTranslationTrait |
| protected EntityFieldManagerInterface | $entityFieldManager | The entity field manager. |
|
| protected EntityDisplayRepositoryInterface | $entityDisplayRepository | The entity display repository. |
|
| protected EntityTypeManagerInterface | $entityTypeManager | The entity type manager. |
|
| protected bool | $authenticatedCanPostComments | Whether the \Drupal\user\RoleInterface::AUTHENTICATED_ID can post comments. |
|
| protected Config | $userConfig | The user settings config object. |
|
| protected ModuleHandlerInterface | $moduleHandler | The module handler service. |
|
| protected AccountInterface | $currentUser | The current user. |
Methods
Translates a string to the current language or to a given language.
Formats a string containing a count of items.
Returns the number of plurals supported by a given language.
Gets the string translation service.
Construct the CommentManager object.
Utility function to return an array of comment fields.
Creates a comment_body field.
Provides a message if posting comments is forbidden.
Returns the number of new comments available on a given entity for a user.
Details
protected TranslatableMarkup
t(string $string, array $args = [], array $options = [])
Translates a string to the current language or to a given language.
See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.
In order for strings to be localized, make them available in one of the ways supported by the
protected
formatPlural($count, $singular, $plural, array $args = [], array $options = [])
Formats a string containing a count of items.
protected
getNumberOfPlurals($langcode = NULL)
Returns the number of plurals supported by a given language.
protected TranslationInterface
getStringTranslation()
Gets the string translation service.
$this
setStringTranslation(TranslationInterface $translation)
Sets the string translation service to use.
__construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, TranslationInterface $string_translation, ModuleHandlerInterface $module_handler, AccountInterface $current_user, EntityFieldManagerInterface $entity_field_manager, EntityDisplayRepositoryInterface $entity_display_repository)
Construct the CommentManager object.
array
getFields(string $entity_type_id)
Utility function to return an array of comment fields.
addBodyField($comment_type_id)
Creates a comment_body field.
string
forbiddenMessage(EntityInterface $entity, string $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.
int|false
getCountNewComments(EntityInterface $entity, string $field_name = NULL, int $timestamp = 0)
Returns the number of new comments available on a given entity for a user.