Drupal 8  8.0.2
StringDatabaseStorage Class Reference
Inheritance diagram for StringDatabaseStorage:

Public Member Functions

 __construct (Connection $connection, array $options=array())
 
 getStrings (array $conditions=array(), array $options=array())
 
 getTranslations (array $conditions=array(), array $options=array())
 
 findString (array $conditions)
 
 findTranslation (array $conditions)
 
 getLocations (array $conditions=array())
 
 countStrings ()
 
 countTranslations ()
 
 save ($string)
 
 delete ($string)
 
 deleteStrings ($conditions)
 
 deleteTranslations ($conditions)
 
 createString ($values=array())
 
 createTranslation ($values=array())
 

Protected Member Functions

 updateLocation ($string)
 
 checkVersion ($string, $version)
 
 dbFieldTable ($field)
 
 dbStringTable ($string)
 
 dbStringKeys ($string)
 
 dbStringSelect (array $conditions, array $options=array())
 
 dbStringInsert ($string)
 
 dbStringUpdate ($string)
 
 dbDelete ($table, $keys)
 
 dbExecute ($query, array $args=array())
 

Protected Attributes

 $connection
 
 $options = array()
 

Detailed Description

Defines a class to store localized strings in the database.

Constructor & Destructor Documentation

__construct ( Connection  $connection,
array  $options = array() 
)

Constructs a new StringDatabaseStorage class.

Parameters
\Drupal\Core\Database\Connection$connectionA Database connection to use for reading and writing configuration data.
array$options(optional) Any additional database connection options to use in queries.

Member Function Documentation

checkVersion (   $string,
  $version 
)
protected

Checks whether the string version matches a given version, fix it if not.

Parameters
\Drupal\locale\StringInterface$stringThe string object.
string$versionDrupal version to check against.

Referenced by StringDatabaseStorage\findTranslation(), and StringDatabaseStorage\updateLocation().

Here is the caller graph for this function:

countStrings ( )

{Counts source strings.

Returns
int The number of source strings contained in the storage.
}

Implements StringStorageInterface.

References StringDatabaseStorage\dbExecute().

Here is the call graph for this function:

countTranslations ( )

{Counts translations.

Returns
array The number of translations for each language indexed by language code.
}

Implements StringStorageInterface.

References StringDatabaseStorage\dbExecute().

Here is the call graph for this function:

createString (   $values = array())

{Creates a source string object bound to this storage but not saved.

Parameters
array$values(optional) Array with initial values. Defaults to empty array.
Returns
New source string object.
}

Implements StringStorageInterface.

createTranslation (   $values = array())

{Creates a string translation object bound to this storage but not saved.

Parameters
array$values(optional) Array with initial values. Defaults to empty array.
Returns
New string translation object.
}

Implements StringStorageInterface.

dbDelete (   $table,
  $keys 
)
protected

Creates delete query.

Parameters
string$tableThe table name.
array$keysArray with object keys indexed by field name.
Returns
Returns a new Delete object for the injected database connection.

Referenced by StringDatabaseStorage\delete(), StringDatabaseStorage\deleteStrings(), StringDatabaseStorage\deleteTranslations(), and StringDatabaseStorage\updateLocation().

Here is the caller graph for this function:

dbExecute (   $query,
array  $args = array() 
)
protected

Executes an arbitrary SELECT query string with the injected options.

Referenced by StringDatabaseStorage\countStrings(), and StringDatabaseStorage\countTranslations().

Here is the caller graph for this function:

dbFieldTable (   $field)
protected

Gets table alias for field.

Parameters
string$fieldOne of the field names of the locales_source, locates_location, locales_target tables to find the table alias for.
Returns
string One of the following values:
  • 's' for "source", "context", "version" (locales_source table fields).
  • 'l' for "type", "name" (locales_location table fields)
  • 't' for "language", "translation", "customized" (locales_target table fields)

Referenced by StringDatabaseStorage\dbStringSelect().

Here is the caller graph for this function:

dbStringInsert (   $string)
protected

Creates a database record for a string object.

Parameters
\Drupal\locale\StringInterface$stringThe string object.
Returns
bool|int If the operation failed, returns FALSE. If it succeeded returns the last insert ID of the query, if one exists.
Exceptions
\Drupal\locale\StringStorageExceptionIf the string is not suitable for this storage, an exception is thrown.

References StringDatabaseStorage\dbStringTable().

Referenced by StringDatabaseStorage\save().

Here is the call graph for this function:

Here is the caller graph for this function:

dbStringKeys (   $string)
protected

Gets keys values that are in a database table.

Parameters
\Drupal\locale\StringInterface$stringThe string object.
Returns
array Array with key fields if the string has all keys, or empty array if not.

Referenced by StringDatabaseStorage\dbStringUpdate(), and StringDatabaseStorage\delete().

Here is the caller graph for this function:

dbStringSelect ( array  $conditions,
array  $options = array() 
)
protected

Builds a SELECT query with multiple conditions and fields.

The query uses both 'locales_source' and 'locales_target' tables. Note that by default, as we are selecting both translated and untranslated strings target field's conditions will be modified to match NULL rows too.

Parameters
array$conditionsAn associative array with field => value conditions that may include NULL values. If a language condition is included it will be used for joining the 'locales_target' table.
array$optionsAn associative array of additional options. It may contain any of the options used by Drupal::getStrings() and these additional ones:
  • 'translation', Whether to include translation fields too. Defaults to FALSE.
Returns
Query object with all the tables, fields and conditions.

References db_like(), db_or(), and StringDatabaseStorage\dbFieldTable().

Referenced by StringDatabaseStorage\deleteStrings(), StringDatabaseStorage\findString(), and StringDatabaseStorage\findTranslation().

Here is the call graph for this function:

Here is the caller graph for this function:

dbStringTable (   $string)
protected

Gets table name for storing string object.

Parameters
\Drupal\locale\StringInterface$stringThe string object.
Returns
string The table name.

Referenced by StringDatabaseStorage\dbStringInsert(), and StringDatabaseStorage\dbStringUpdate().

Here is the caller graph for this function:

dbStringUpdate (   $string)
protected

Updates string object in the database.

Parameters
\Drupal\locale\StringInterface$stringThe string object.
Returns
bool|int If the record update failed, returns FALSE. If it succeeded, returns SAVED_NEW or SAVED_UPDATED.
Exceptions
\Drupal\locale\StringStorageExceptionIf the string is not suitable for this storage, an exception is thrown.

References StringDatabaseStorage\dbStringKeys(), and StringDatabaseStorage\dbStringTable().

Referenced by StringDatabaseStorage\save().

Here is the call graph for this function:

Here is the caller graph for this function:

delete (   $string)

{Delete string from storage.

Parameters
\Drupal\locale\StringInterface$stringThe string object.
Returns
The called object.
Exceptions
\Drupal\locale\StringStorageExceptionIn case of failures, an exception is thrown.
}

Implements StringStorageInterface.

References StringDatabaseStorage\dbDelete(), and StringDatabaseStorage\dbStringKeys().

Here is the call graph for this function:

deleteStrings (   $conditions)

{Deletes source strings and translations using conditions.

Parameters
array$conditionsArray with simple field conditions for source strings.
}

Implements StringStorageInterface.

References StringDatabaseStorage\dbDelete(), and StringDatabaseStorage\dbStringSelect().

Here is the call graph for this function:

deleteTranslations (   $conditions)

{Deletes translations using conditions.

Parameters
array$conditionsArray with simple field conditions for string translations.
}

Implements StringStorageInterface.

References StringDatabaseStorage\dbDelete().

Here is the call graph for this function:

findString ( array  $conditions)

{Loads a string source object, fast query.These 'fast query' methods are the ones in the critical path and their implementation must be optimized for speed, as they may run many times in a single page request.

Parameters
array$conditions(optional) Array with conditions that will be used to filter the strings returned and may include all of the conditions defined by getStrings().
Returns
|null Minimal TranslationString object if found, NULL otherwise.
}

Implements StringStorageInterface.

References StringDatabaseStorage\dbStringSelect().

Here is the call graph for this function:

findTranslation ( array  $conditions)

{Loads a string translation object, fast query.This function must only be used when actually translating strings as it will have the effect of updating the string version. For other purposes the getTranslations() method should be used instead.

Parameters
array$conditions(optional) Array with conditions that will be used to filter the strings returned and may include all of the conditions defined by getStrings().
Returns
|null Minimal TranslationString object if found, NULL otherwise.
}

Implements StringStorageInterface.

References StringDatabaseStorage\checkVersion(), StringDatabaseStorage\dbStringSelect(), and Drupal\VERSION.

Here is the call graph for this function:

getLocations ( array  $conditions = array())

{Loads string location information.

Parameters
array$conditions(optional) Array with conditions to filter the locations that may be any of the following elements:
  • 'sid', The string identifier.
  • 'type', The location type.
  • 'name', The location name.
Returns
[] Array of objects matching the conditions.
See Also
::getStrings()
}

Implements StringStorageInterface.

getStrings ( array  $conditions = array(),
array  $options = array() 
)

{Loads multiple source string objects.

Parameters
array$conditions(optional) Array with conditions that will be used to filter the strings returned and may include any of the following elements:
  • Any simple field value indexed by field name.
  • 'translated', TRUE to get only translated strings or FALSE to get only untranslated strings. If not set it returns both translated and untranslated strings that fit the other conditions. Defaults to no conditions which means that it will load all strings.
array$options(optional) An associative array of additional options. It may contain any of the following optional keys:
  • 'filters': Array of string filters indexed by field name.
  • 'pager limit': Use pager and set this limit value.
Returns
array Array of objects matching the conditions.
}

Implements StringStorageInterface.

getTranslations ( array  $conditions = array(),
array  $options = array() 
)

{Loads multiple string translation objects.

Parameters
array$conditions(optional) Array with conditions that will be used to filter the strings returned and may include all of the conditions defined by getStrings().
array$options(optional) An associative array of additional options. It may contain any of the options defined by getStrings().
Returns
[] Array of objects matching the conditions.
See Also
::getStrings()
}

Implements StringStorageInterface.

save (   $string)

{Save string object to storage.

Parameters
\Drupal\locale\StringInterface$stringThe string object.
Returns
The called object.
Exceptions
\Drupal\locale\StringStorageExceptionIn case of failures, an exception is thrown.
}

Implements StringStorageInterface.

References StringDatabaseStorage\dbStringInsert(), StringDatabaseStorage\dbStringUpdate(), and StringDatabaseStorage\updateLocation().

Here is the call graph for this function:

updateLocation (   $string)
protected

Update locations for string.

Parameters
\Drupal\locale\StringInterface$stringThe string object.

References StringDatabaseStorage\checkVersion(), StringDatabaseStorage\dbDelete(), and Drupal\VERSION.

Referenced by StringDatabaseStorage\save().

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following file: