HTMLTree
extends AbstractBase
in package
implements
TranslatorAwareInterface
Uses
TranslatorAwareTrait
Hierarchy Tree HTML Renderer
This is a helper class for producing hierarchy trees.
Tags
Interfaces, Classes, Traits and Enums
- TranslatorAwareInterface
- Lightweight translator aware marker interface (used as an alternative to \Laminas\I18n\Translator\TranslatorAwareInterface, which requires an excessive number of methods to be implemented).
Table of Contents
- $collectionsEnabled : bool
- Whether the collections functionality is enabled
- $dataSource : AbstractBase
- Source of hierarchy data
- $recordDriver : AbstractBase
- Hierarchical record to work on
- $router : Url
- Router plugin
- $translator : TranslatorInterface
- Translator
- $viewRenderer : RendererInterface
- View renderer
- __construct() : mixed
- Constructor
- getHierarchyName() : string
- Get Hierarchy Name
- getTranslator() : TranslatorInterface
- Get translator object.
- getTranslatorLocale() : string
- Get the locale from the translator.
- getTreeList() : mixed
- Get a list of trees containing the item represented by the stored record driver.
- render() : mixed
- Render the Hierarchy Tree
- setRecordDriver() : AbstractBase
- Set the record driver to operate on
- setTranslator() : TranslatorAwareInterface
- Set a translator
- translate() : string
- Translate a string (or string-castable object)
- translateWithPrefix() : string
- Translate a string (or string-castable object) using a prefix, or without the prefix if a prefixed translation is not found.
- augmentNodeData() : bool
- Augment all nodes with 'hasSelectedChild' and 'href' for rendering.
- extractTextDomain() : array<string|int, mixed>
- Given a translation string with or without a text domain, return an array with the raw string and the text domain separated.
- getContextualUrl() : string
- Use the router to build the appropriate URL based on context
- getDataSource() : AbstractBase
- Get the current hierarchy data source
- getDebugTranslation() : string
- Build a debug-mode translation
- getRecordDriver() : DefaultRecord
- Get the current record driver
- getRouteNameFromDataSource() : string
- Get route name from data source.
- getUrlFromRouteCache() : string
- Get the URL for a record and cache it to avoid the relatively slow routing calls.
- sanitizeTranslationKey() : string
- Make sure there are not any illegal characters in the translation key that might prevent successful lookup in language files.
- translateString() : string
- Get translation for a string
Properties
$collectionsEnabled
Whether the collections functionality is enabled
protected
bool
$collectionsEnabled
$dataSource
Source of hierarchy data
protected
AbstractBase
$dataSource
= null
$recordDriver
Hierarchical record to work on
protected
AbstractBase
$recordDriver
= null
$router
Router plugin
protected
Url
$router
= null
$translator
Translator
protected
TranslatorInterface
$translator
= null
$viewRenderer
View renderer
protected
RendererInterface
$viewRenderer
Methods
__construct()
Constructor
public
__construct(Url $router, bool $collectionsEnabled, RendererInterface $renderer) : mixed
Parameters
- $router : Url
-
Router plugin for urls
- $collectionsEnabled : bool
-
Whether the collections functionality is enabled
- $renderer : RendererInterface
-
View renderer
Return values
mixed —getHierarchyName()
Get Hierarchy Name
public
getHierarchyName(string $hierarchyID, array<string|int, mixed> $inHierarchies, array<string|int, mixed> $inHierarchiesTitle) : string
Parameters
- $hierarchyID : string
-
The hierarchy ID to find the title for
- $inHierarchies : array<string|int, mixed>
-
An array of hierarchy IDs
- $inHierarchiesTitle : array<string|int, mixed>
-
An array of hierarchy Titles
Return values
string —A hierarchy title
getTranslator()
Get translator object.
public
getTranslator() : TranslatorInterface
Return values
TranslatorInterface —getTranslatorLocale()
Get the locale from the translator.
public
getTranslatorLocale([string $default = 'en' ]) : string
Parameters
- $default : string = 'en'
-
Default to use if translator absent.
Return values
string —getTreeList()
Get a list of trees containing the item represented by the stored record driver.
public
getTreeList([string $hierarchyID = false ]) : mixed
Parameters
- $hierarchyID : string = false
-
Optional filter: specific hierarchy ID to retrieve
Return values
mixed —An array of hierarchy IDS if a hierarchy tree exists, false if it does not
render()
Render the Hierarchy Tree
public
render(string $context, string $mode, string $hierarchyID[, string|null $selectedID = null ][, array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $context : string
-
The context from which the call has been made
- $mode : string
-
The mode in which the tree should be generated
- $hierarchyID : string
-
The hierarchy ID of the tree to fetch (optional)
- $selectedID : string|null = null
-
The current record ID (optional)
- $options : array<string|int, mixed> = []
-
Additional options
Return values
mixed —The desired hierarchy tree output (or false on error)
setRecordDriver()
Set the record driver to operate on
public
setRecordDriver(AbstractBase $driver) : AbstractBase
Parameters
- $driver : AbstractBase
-
Record driver
Return values
AbstractBase —setTranslator()
Set a translator
public
setTranslator(TranslatorInterface $translator) : TranslatorAwareInterface
Parameters
- $translator : TranslatorInterface
-
Translator
Return values
TranslatorAwareInterface —translate()
Translate a string (or string-castable object)
public
translate(string|object|array<string|int, mixed> $target[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, bool $useIcuFormatter = false ][, array<string|int, string> $fallbackDomains = [] ]) : string
Parameters
- $target : string|object|array<string|int, mixed>
-
String to translate or an array of text domain and string to translate
- $tokens : array<string|int, mixed> = []
-
Tokens to inject into the translated string
- $default : string = null
-
Default value to use if no translation is found (null for no default).
- $useIcuFormatter : bool = false
-
Should we use an ICU message formatter instead of the default behavior?
- $fallbackDomains : array<string|int, string> = []
-
Text domains to check if no match is found in the domain specified in $target
Return values
string —translateWithPrefix()
Translate a string (or string-castable object) using a prefix, or without the prefix if a prefixed translation is not found.
public
translateWithPrefix(string $prefix, string|object|array<string|int, mixed> $target[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, bool $useIcuFormatter = false ][, array<string|int, string> $fallbackDomains = [] ]) : string
Parameters
- $prefix : string
-
Translation key prefix
- $target : string|object|array<string|int, mixed>
-
String to translate or an array of text domain and string to translate
- $tokens : array<string|int, mixed> = []
-
Tokens to inject into the translated string
- $default : string = null
-
Default value to use if no translation is found (null for no default).
- $useIcuFormatter : bool = false
-
Should we use an ICU message formatter instead of the default behavior?
- $fallbackDomains : array<string|int, string> = []
-
Text domains to check if no match is found in the domain specified in $target
Return values
string —augmentNodeData()
Augment all nodes with 'hasSelectedChild' and 'href' for rendering.
protected
augmentNodeData(array<string|int, mixed> $nodes, string $context, string|null $selectedID) : bool
Parameters
- $nodes : array<string|int, mixed>
-
Node list
- $context : string
-
Context
- $selectedID : string|null
-
Selected record ID
Return values
bool —Whether any items are applied (for recursive calls)
extractTextDomain()
Given a translation string with or without a text domain, return an array with the raw string and the text domain separated.
protected
extractTextDomain(string|object|array<string|int, mixed> $target) : array<string|int, mixed>
Parameters
- $target : string|object|array<string|int, mixed>
-
String to translate or an array of text domain and string to translate
Return values
array<string|int, mixed> —getContextualUrl()
Use the router to build the appropriate URL based on context
protected
getContextualUrl(object $node, string $context) : string
Parameters
- $node : object
-
JSON object of a node/top node
- $context : string
-
Record or Collection
Return values
string —getDataSource()
Get the current hierarchy data source
protected
getDataSource() : AbstractBase
Tags
Return values
AbstractBase —getDebugTranslation()
Build a debug-mode translation
protected
getDebugTranslation(string $domain, string $str, array<string|int, mixed> $tokens) : string
Parameters
- $domain : string
-
Text domain
- $str : string
-
String to translate
- $tokens : array<string|int, mixed>
-
Tokens to inject into the translated string
Return values
string —getRecordDriver()
Get the current record driver
protected
getRecordDriver() : DefaultRecord
Tags
Return values
DefaultRecord —getRouteNameFromDataSource()
Get route name from data source.
protected
getRouteNameFromDataSource(string $route) : string
Parameters
- $route : string
-
Route
Return values
string —getUrlFromRouteCache()
Get the URL for a record and cache it to avoid the relatively slow routing calls.
protected
getUrlFromRouteCache(string $route, string $id) : string
Parameters
- $route : string
-
Route
- $id : string
-
Record ID
Return values
string —URL
sanitizeTranslationKey()
Make sure there are not any illegal characters in the translation key that might prevent successful lookup in language files.
protected
sanitizeTranslationKey(string $key) : string
Parameters
- $key : string
-
Key to sanitize
Return values
string —Sanitized key
translateString()
Get translation for a string
protected
translateString(string $rawStr[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, string $domain = 'default' ][, bool $useIcuFormatter = false ]) : string
Parameters
- $rawStr : string
-
String to translate
- $tokens : array<string|int, mixed> = []
-
Tokens to inject into the translated string
- $default : string = null
-
Default value to use if no translation is found (null for no default).
- $domain : string = 'default'
-
Text domain (omit for default)
- $useIcuFormatter : bool = false
-
Should we use an ICU message formatter instead of the default behavior?