class ForumManager implements ForumManagerInterface (View source)

Provides forum manager service.

Traits

Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.

Provides dependency injection friendly methods for serialization.

Constants

NEWEST_FIRST

Forum sort order, newest first.

OLDEST_FIRST

Forum sort order, oldest first.

MOST_POPULAR_FIRST

Forum sort order, posts with most comments first.

LEAST_POPULAR_FIRST

Forum sort order, posts with the least comments first.

Properties

protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected array $_serviceIds

An array of service IDs keyed by property name used for serialization.

from  DependencySerializationTrait
protected array $_entityStorages

An array of entity type IDs keyed by the property name of their storages.

from  DependencySerializationTrait
protected ConfigFactoryInterface $configFactory

Forum settings config object.

protected EntityFieldManagerInterface $entityFieldManager

Entity field manager.

protected EntityTypeManagerInterface $entityTypeManager

Entity type manager.

protected Connection $connection

Database connection.

protected CommentManagerInterface $commentManager

The comment manager service.

protected array $lastPostData

Array of last post information keyed by forum (term) id.

protected array $forumStatistics

Array of forum statistics keyed by forum (term) id.

protected array $forumChildren

Array of forum children keyed by parent forum (term) id.

protected array $history

Array of history keyed by nid.

protected TermInterface $index

Cached forum index.

Methods

t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

getStringTranslation()

Gets the string translation service.

$this
setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

__construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, Connection $connection, TranslationInterface $string_translation, CommentManagerInterface $comment_manager, EntityFieldManagerInterface $entity_field_manager)

Constructs the forum manager service.

array
getTopics(int $tid, AccountInterface $account)

Gets list of forum topics.

array
getTopicOrder(int $sortby)

Gets topic sorting information based on an integer code.

int
lastVisit(int $nid, AccountInterface $account)

Gets the last time the user viewed a node.

object
getLastPost(int $tid)

Provides the last post information for the given forum tid.

object|null
getForumStatistics(int $tid)

Provides statistics for a forum.

array
getChildren(int $vid, int $tid)

Utility method to fetch the child forums for a given forum.

getIndex()

Generates and returns the forum index.

resetCache()

Resets the ForumManager index and history.

bool
checkNodeType(NodeInterface $node)

Checks whether a node can be used in a forum, based on its content type.

The
unreadTopics(int $term, int $uid)

Calculates the number of new posts in a forum that the user has not yet read.

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

Parameters

string $string

A string containing the English text to translate.

array $args

(optional) An associative array of replacements to make after translation. Based on the first character of the key, the value is escaped and/or themed. See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for details.

array $options

(optional) An associative array of additional options, with the following elements:

  • 'langcode' (defaults to the current language): A language code, to translate to a language other than what is used to display the page.
  • 'context' (defaults to the empty context): The context the source string belongs to. See the @link i18n Internationalization topic @endlink for more information about string contexts.

Return Value

TranslatableMarkup

An object that, when cast to a string, returns the translated string.

See also

FormattableMarkup::placeholderFormat
TranslatableMarkup::__construct

protected formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

Parameters

$count
$singular
$plural
array $args
array $options

See also

TranslationInterface::formatPlural

protected getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

Parameters

$langcode

See also

PluralFormulaInterface::getNumberOfPlurals

protected TranslationInterface getStringTranslation()

Gets the string translation service.

Return Value

TranslationInterface

The string translation service.

$this setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

Parameters

TranslationInterface $translation

The string translation service.

Return Value

$this

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

__construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, Connection $connection, TranslationInterface $string_translation, CommentManagerInterface $comment_manager, EntityFieldManagerInterface $entity_field_manager)

Constructs the forum manager service.

Parameters

ConfigFactoryInterface $config_factory

The config factory service.

EntityTypeManagerInterface $entity_type_manager

The entity type manager.

Connection $connection

The current database connection.

TranslationInterface $string_translation

The translation manager service.

CommentManagerInterface $comment_manager

The comment manager service.

EntityFieldManagerInterface $entity_field_manager

The entity field manager.

array getTopics(int $tid, AccountInterface $account)

Gets list of forum topics.

Parameters

int $tid

Term ID.

AccountInterface $account

Account to fetch topics for.

Return Value

array

Array with keys 'topics' and 'header'.

protected array getTopicOrder(int $sortby)

Gets topic sorting information based on an integer code.

Parameters

int $sortby

One of the following integers indicating the sort criteria:

  • ForumManager::NEWEST_FIRST: Date - newest first.
  • ForumManager::OLDEST_FIRST: Date - oldest first.
  • ForumManager::MOST_POPULAR_FIRST: Posts with the most comments first.
  • ForumManager::LEAST_POPULAR_FIRST: Posts with the least comments first.

Return Value

array

An array with the following values:

  • field: A field for an SQL query.
  • sort: 'asc' or 'desc'.

protected int lastVisit(int $nid, AccountInterface $account)

Gets the last time the user viewed a node.

Parameters

int $nid

The node ID.

AccountInterface $account

Account to fetch last time for.

Return Value

int

The timestamp when the user last viewed this node, if the user has previously viewed the node; otherwise HISTORY_READ_LIMIT.

protected object getLastPost(int $tid)

Provides the last post information for the given forum tid.

Parameters

int $tid

The forum tid.

Return Value

object

The last post for the given forum.

protected object|null getForumStatistics(int $tid)

Provides statistics for a forum.

Parameters

int $tid

The forum tid.

Return Value

object|null

Statistics for the given forum if statistics exist, else NULL.

array getChildren(int $vid, int $tid)

Utility method to fetch the child forums for a given forum.

Parameters

int $vid

The forum vocabulary ID.

int $tid

The forum ID to fetch the children for.

Return Value

array

Array of children.

TermInterface getIndex()

Generates and returns the forum index.

The forum index is a pseudo term that provides an overview of all forums.

Return Value

TermInterface

A pseudo term representing the overview of all forums.

resetCache()

Resets the ForumManager index and history.

bool checkNodeType(NodeInterface $node)

Checks whether a node can be used in a forum, based on its content type.

Parameters

NodeInterface $node

A node entity.

Return Value

bool

Boolean indicating if the node can be assigned to a forum.

The unreadTopics(int $term, int $uid)

Calculates the number of new posts in a forum that the user has not yet read.

Nodes are new if they are newer than HISTORY_READ_LIMIT.

Parameters

int $term

The term ID of the forum.

int $uid

The user ID.

Return Value

The

number of new posts in the forum that have not been read by the user.