TermTagService
in package
Service for term (word) tag operations.
Manages word-tag associations, HTML rendering of tag lists, batch add/remove operations, and select option generation.
Tags
Table of Contents
Properties
- $association : TagAssociationInterface|null
- $repository : TagRepositoryInterface|null
Methods
- addTagToWords() : array{count: int, error: ?string}
- Add a tag to multiple words.
- getAssociation() : TagAssociationInterface
- Get the word tag association handler.
- getOrCreateTermTag() : int|null
- Get or create a term tag, returning its ID.
- getRepository() : TagRepositoryInterface
- Get the term tag repository.
- getTermTagSelectOptions() : string
- Get term tag select options HTML for filtering.
- getWordTagList() : string
- Get comma-separated tag list for a word.
- getWordTagListHtml() : string
- Get formatted tag list as Bulma tag components for a word.
- getWordTagsArray() : array<string|int, string>
- Get word tags as array.
- getWordTagsHtml() : string
- Get HTML list of tags for a word.
- removeTagFromWords() : array{count: int, error: ?string}
- Remove a tag from multiple words.
- saveWordTags() : void
- Save tags for a word.
- saveWordTagsFromArray() : void
- Save tags for a word from an array of tag names.
- saveWordTagsFromForm() : void
- Save tags for a word from form input.
Properties
$association
private
static TagAssociationInterface|null
$association
= null
$repository
private
static TagRepositoryInterface|null
$repository
= null
Methods
addTagToWords()
Add a tag to multiple words.
public
static addTagToWords(string $tagText, array<string|int, int> $ids) : array{count: int, error: ?string}
Parameters
- $tagText : string
-
Tag text to add
- $ids : array<string|int, int>
-
Array of word IDs
Return values
array{count: int, error: ?string} —Result with count and optional error
getAssociation()
Get the word tag association handler.
public
static getAssociation() : TagAssociationInterface
Return values
TagAssociationInterfacegetOrCreateTermTag()
Get or create a term tag, returning its ID.
public
static getOrCreateTermTag(string $tagText) : int|null
Parameters
- $tagText : string
-
Tag text
Return values
int|null —Tag ID or null on failure
getRepository()
Get the term tag repository.
public
static getRepository() : TagRepositoryInterface
Return values
TagRepositoryInterfacegetTermTagSelectOptions()
Get term tag select options HTML for filtering.
public
static getTermTagSelectOptions(int|string|null $selected, int|string $langId) : string
Parameters
- $selected : int|string|null
-
Currently selected value
- $langId : int|string
-
Language ID filter ('' for all)
Return values
string —HTML options
getWordTagList()
Get comma-separated tag list for a word.
public
static getWordTagList(int $wordId[, bool $escapeHtml = true ]) : string
Parameters
- $wordId : int
-
Word ID
- $escapeHtml : bool = true
-
Whether to escape HTML
Return values
stringgetWordTagListHtml()
Get formatted tag list as Bulma tag components for a word.
public
static getWordTagListHtml(int $wordId[, string $size = 'is-small' ][, string $color = 'is-info' ][, bool $isLight = true ]) : string
Parameters
- $wordId : int
-
Word ID
- $size : string = 'is-small'
-
Bulma size class (e.g., 'is-small', 'is-normal')
- $color : string = 'is-info'
-
Bulma color class (e.g., 'is-info', 'is-primary')
- $isLight : bool = true
-
Whether to use light variant
Return values
string —HTML for Bulma tags
getWordTagsArray()
Get word tags as array.
public
static getWordTagsArray(int $wordId) : array<string|int, string>
Parameters
- $wordId : int
-
Word ID
Return values
array<string|int, string>getWordTagsHtml()
Get HTML list of tags for a word.
public
static getWordTagsHtml(int $wordId) : string
Parameters
- $wordId : int
-
Word ID
Return values
string —HTML UL element
removeTagFromWords()
Remove a tag from multiple words.
public
static removeTagFromWords(string $tagText, array<string|int, int> $ids) : array{count: int, error: ?string}
Parameters
- $tagText : string
-
Tag text to remove
- $ids : array<string|int, int>
-
Array of word IDs
Return values
array{count: int, error: ?string} —Result with count and optional error
saveWordTags()
Save tags for a word.
public
static saveWordTags(int $wordId, array<string|int, string> $tagNames) : void
Parameters
- $wordId : int
-
Word ID
- $tagNames : array<string|int, string>
-
Tag names
saveWordTagsFromArray()
Save tags for a word from an array of tag names.
public
static saveWordTagsFromArray(int $wordId, array<string|int, string> $tagNames) : void
Parameters
- $wordId : int
-
Word ID
- $tagNames : array<string|int, string>
-
Array of tag name strings
saveWordTagsFromForm()
Save tags for a word from form input.
public
static saveWordTagsFromForm(int $wordId) : void
Reads 'TermTags' from request and saves to word.
Parameters
- $wordId : int
-
Word ID