VuFind API Documentation

CookieConsent extends AbstractHelper
in package
implements TranslatorAwareInterface Uses TranslatorAwareTrait

CookieConsent view helper

Tags
category

VuFind

author

Ere Maijala ere.maijala@helsinki.fi

license

http://opensource.org/licenses/gpl-2.0.php GNU General Public License

link

Main Site

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

$config  : array<string|int, mixed>
$consentConfig  : array<string|int, mixed>
$consentCookieExpiration  : int
Consent cookie expiration time (days)
$consentCookieName  : string
Consent cookie name
$cookieManager  : CookieManager
$dateConverter  : Converter
$hostName  : string
Server name
$loginTokenManager  : LoginTokenManager
$translator  : TranslatorInterface
Translator
__construct()  : mixed
Constructor
__invoke()  : CookieConsent
Return this object
getConsentInformation()  : array<string|int, mixed>|null
Get information about user's given consent
getControlledVuFindServices()  : array<string|int, mixed>
Get controlled VuFind services (services integrated into VuFind)
getTranslator()  : TranslatorInterface
Get translator object.
getTranslatorLocale()  : string
Get the locale from the translator.
isCategoryAccepted()  : bool
Check if a cookie category is accepted
isEnabled()  : bool
Check if the cookie consent mechanism is enabled
isServiceAllowed()  : bool
Check if a VuFind service is allowed
render()  : string
Render cookie consent initialization script
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.
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.
getConsentDialogConfig()  : array<string|int, mixed>
Get configuration for the consent dialog
getConsentRevision()  : int
Get current consent revision
getCurrentConsent()  : array<string|int, mixed>
Get current consent data
getDebugTranslation()  : string
Build a debug-mode translation
getDescriptionPlaceholders()  : array<string|int, mixed>
Get placeholders for description translations
getHostName()  : string
Get current host name
getPlaceholders()  : array<string|int, mixed>
Get placeholders for strings
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

$consentConfig

protected array<string|int, mixed> $consentConfig

$consentCookieExpiration

Consent cookie expiration time (days)

protected int $consentCookieExpiration

$consentCookieName

Consent cookie name

protected string $consentCookieName

Methods

__construct()

Constructor

public __construct(array<string|int, mixed> $config, array<string|int, mixed> $consentConfig, CookieManager $cookieManager, Converter $dateConverter, LoginTokenManager $loginTokenManager) : mixed
Parameters
$config : array<string|int, mixed>

Main configuration

$consentConfig : array<string|int, mixed>

Cookie consent configuration

$cookieManager : CookieManager

Cookie manager

$dateConverter : Converter

Date converter

$loginTokenManager : LoginTokenManager

Login token manager

Return values
mixed

getConsentInformation()

Get information about user's given consent

public getConsentInformation() : array<string|int, mixed>|null

The following fields are guaranteed to be returned if consent has been given:

  • consentId Consent ID
  • domain Cookie domain
  • path Cookie path
  • lastConsentTimestamp Timestamp the consent was given or updated
  • lastConsentDateTime Formatted date and time the consent was given or updated
  • categories Categories allowed in the consent
  • categoriesTranslated Translated names of categories allowed in the consent
Return values
array<string|int, mixed>|null

Associative array or null if no consent has been given or it cannot be decoded

getControlledVuFindServices()

Get controlled VuFind services (services integrated into VuFind)

public getControlledVuFindServices() : array<string|int, mixed>
Return values
array<string|int, mixed>

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

isCategoryAccepted()

Check if a cookie category is accepted

public isCategoryAccepted(string $category) : bool

Checks the consent cookie for accepted category information

Parameters
$category : string

Category

Return values
bool

isEnabled()

Check if the cookie consent mechanism is enabled

public isEnabled() : bool
Return values
bool

isServiceAllowed()

Check if a VuFind service is allowed

public isServiceAllowed(string $service) : bool
Parameters
$service : string

Service

Return values
bool

render()

Render cookie consent initialization script

public render() : string
Return values
string

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

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>

getConsentDialogConfig()

Get configuration for the consent dialog

protected getConsentDialogConfig() : array<string|int, mixed>
Return values
array<string|int, mixed>

getConsentRevision()

Get current consent revision

protected getConsentRevision() : int
Return values
int

getCurrentConsent()

Get current consent data

protected getCurrentConsent() : array<string|int, mixed>
Return values
array<string|int, mixed>

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

getDescriptionPlaceholders()

Get placeholders for description translations

protected getDescriptionPlaceholders() : array<string|int, mixed>
Return values
array<string|int, mixed>

getHostName()

Get current host name

protected getHostName() : string
Return values
string

getPlaceholders()

Get placeholders for strings

protected getPlaceholders() : array<string|int, mixed>
Return values
array<string|int, mixed>

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?

Return values
string

Search results