abstract class StringBase implements StringInterface (View source)

Defines the locale string base class.

This is the base class to be used for locale string objects and contains the common properties and methods for source and translation strings.

Properties

int $lid

The string identifier.

string $locations

The string locations indexed by type.

string $source

The source string.

string $context

The string context.

string $version

The string version.

protected StringStorageInterface $storage

The locale storage this string comes from or is to be saved to.

Methods

__construct(object|array $values = [])

Constructs a new locale string object.

int
getId()

Gets the string unique identifier.

$this
setId($lid)

Sets the string unique identifier.

string
getVersion()

Gets the string version.

$this
setVersion(string $version)

Sets the string version.

array
getPlurals()

Splits string to work with plural values.

$this
setPlurals(array $plurals)

Sets this string using array of plural values.

getStorage()

Gets the string storage.

$this
setStorage(StringStorageInterface $storage)

Sets the string storage.

$this
setValues(array $values, bool $override = TRUE)

Sets an array of values as object properties.

array
getValues(array $fields)

Gets field values that are set for given field names.

array
getLocations(bool $check_only = FALSE)

Gets location information for this string.

$this
addLocation(string $type, string $name)

Adds a location for this string.

bool
hasLocation(string $type, string $name)

Checks whether the string has a given location.

$this
save()

Saves string object to storage.

$this
delete()

Deletes string object from storage.

Details

__construct(object|array $values = [])

Constructs a new locale string object.

Parameters

object|array $values

Object or array with initial values.

int getId()

Gets the string unique identifier.

Return Value

int

The string identifier.

$this setId($lid)

Sets the string unique identifier.

Parameters

$lid

Return Value

$this

string getVersion()

Gets the string version.

Return Value

string

Version identifier.

$this setVersion(string $version)

Sets the string version.

Parameters

string $version

Version identifier.

Return Value

$this

array getPlurals()

Splits string to work with plural values.

Return Value

array

Array of strings that are plural variants.

$this setPlurals(array $plurals)

Sets this string using array of plural values.

Serializes plural variants in one string glued by \Drupal\Component\Gettext\PoItem::DELIMITER.

Parameters

array $plurals

Array of strings with plural variants.

Return Value

$this

StringStorageInterface getStorage()

Gets the string storage.

Return Value

StringStorageInterface

The storage used for this string.

$this setStorage(StringStorageInterface $storage)

Sets the string storage.

Parameters

StringStorageInterface $storage

The storage to use for this string.

Return Value

$this

$this setValues(array $values, bool $override = TRUE)

Sets an array of values as object properties.

Parameters

array $values

Array with values indexed by property name.

bool $override

(optional) Whether to override already set fields, defaults to TRUE.

Return Value

$this

array getValues(array $fields)

Gets field values that are set for given field names.

Parameters

array $fields

Array of field names.

Return Value

array

Array of field values indexed by field name.

array getLocations(bool $check_only = FALSE)

Gets location information for this string.

Locations are arbitrary pairs of type and name strings, used to store information about the origins of the string, like the file name it was found on, the path on which it was discovered, etc.

A string can have any number of locations since the same string may be found on different places of Drupal code and configuration.

Parameters

bool $check_only

(optional) Set to TRUE to get only new locations added during the current page request and not loading all existing locations.

Return Value

array

Location ids indexed by type and name.

$this addLocation(string $type, string $name)

Adds a location for this string.

Parameters

string $type

Location type that may be any arbitrary string. Types used in Drupal core are: 'javascript', 'path', 'code', 'configuration'.

string $name

Location name. Drupal path in case of online discovered translations, file path in case of imported strings, configuration name for strings that come from configuration, etc.

Return Value

$this

bool hasLocation(string $type, string $name)

Checks whether the string has a given location.

Parameters

string $type

Location type.

string $name

Location name.

Return Value

bool

TRUE if the string has a location with this type and name.

$this save()

Saves string object to storage.

Return Value

$this

Exceptions

StringStorageException

$this delete()

Deletes string object from storage.

Return Value

$this

Exceptions

StringStorageException