class Language extends DrupalSqlBase (View source)

Drupal 6/7 language source from database.

Available configuration keys:

  • fetch_all: (optional) If not empty, all source languages are retrieved and available as "languages" source property. Each language is an array with the same structure as a source row.
  • domain_negotiation: (optional) If not empty and domain negotiation is enabled in the source database, the "domain_negotiation_used" source property is set to TRUE.

Example:

Traits

Provides a trait for managing an object's dependencies.

Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.

Provides dependency injection friendly methods for serialization.

Provides a trait for the messenger service.

Constants

DERIVATIVE_SEPARATOR

A string which is used to separate base plugin IDs from the derivative ID.

Properties

protected string $pluginId

The plugin_id.

from  PluginBase
protected array $pluginDefinition

The plugin implementation definition.

from  PluginBase
protected array $configuration

Configuration information passed into the plugin.

from  PluginBase
protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected array $_serviceIds

An array of service IDs keyed by property name used for serialization.

from  DependencySerializationTrait
protected array $_entityStorages

An array of entity type IDs keyed by the property name of their storages.

from  DependencySerializationTrait
protected MessengerInterface $messenger

The messenger.

from  MessengerTrait
protected ModuleHandlerInterface $moduleHandler

The module handler service.

from  SourcePluginBase
protected MigrationInterface $migration

The entity migration object.

from  SourcePluginBase
protected Row $currentRow

The current row from the query.

from  SourcePluginBase
protected array $currentSourceIds

The primary key of the current row.

from  SourcePluginBase
protected array $highWaterProperty

Information on the property used as the high-water mark.

from  SourcePluginBase
protected KeyValueStoreInterface $highWaterStorage

The key-value storage for the high-water value.

from  SourcePluginBase
protected int $originalHighWater

The high water mark at the beginning of the import operation.

from  SourcePluginBase
protected bool $cacheCounts

Whether this instance should cache the source count.

from  SourcePluginBase
protected string $cacheKey

Key to use for caching counts.

from  SourcePluginBase
protected bool $skipCount

Whether this instance should not attempt to count the source.

from  SourcePluginBase
protected bool $trackChanges

Flags whether to track changes to incoming data.

from  SourcePluginBase
protected bool $mapRowAdded

Flags whether source plugin will read the map row and add to data row.

from  SourcePluginBase
protected CacheBackendInterface $cache

The backend cache.

from  SourcePluginBase
protected MigrateIdMapInterface $idMap

The migration ID map.

from  SourcePluginBase
protected Iterator $iterator

The iterator to iterate over the source rows.

from  SourcePluginBase
protected SelectInterface $query

The query string.

from  SqlBase
protected Connection $database

The database object.

from  SqlBase
protected StateInterface $state

State service for retrieving database info.

from  SqlBase
protected int $batch

The count of the number of batches run.

from  SqlBase
protected int $batchSize

Number of records to fetch from the database during each batch.

from  SqlBase
protected array $dependencies

The object's dependencies.

from  DependencyTrait
protected array $systemData

The contents of the system table.

from  DrupalSqlBase
protected bool $requirements

If the source provider is missing.

from  DrupalSqlBase
protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

from  DrupalSqlBase

Methods

__construct(array $configuration, string $plugin_id, mixed $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityTypeManagerInterface $entity_type_manager)

Constructs a \Drupal\Component\Plugin\PluginBase object.

string
getPluginId()

Gets the plugin_id of the plugin instance.

string
getBaseId()

Gets the base_plugin_id of the plugin instance.

string|null
getDerivativeId()

Gets the derivative_id of the plugin instance.

array
getPluginDefinition()

Gets the definition of the plugin implementation.

bool
isConfigurable()

Determines if the plugin is configurable.

t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

getStringTranslation()

Gets the string translation service.

$this
setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

setMessenger(MessengerInterface $messenger)

Sets the messenger.

messenger()

Gets the messenger.

initializeIterator()

Initializes the iterator with the source data.

from  SqlBase
getModuleHandler()

Gets the module handler.

bool
prepareRow(Row $row)

Adds additional data to the row.

getIterator()

Returns the iterator that will yield the row arrays to be processed.

current()

{@inheritdoc}

key()

Gets the iterator key.

valid()

Checks whether the iterator is currently valid.

rewind()

Rewinds the iterator.

next()

{@inheritdoc}

fetchNextRow()

Position the iterator to the following row.

from  SqlBase
bool
aboveHighWater(Row $row)

Check if the incoming data is newer than what we've previously imported.

bool
rowChanged(Row $row)

Checks if the incoming row has changed since our last import.

getCurrentIds()

Gets the currentSourceIds data member.

int
count(bool $refresh = FALSE)

Gets the source count.

getCache()

Gets the cache object.

int
doCount()

Gets the source count using countQuery().

from  SqlBase
getHighWaterStorage()

Get the high water storage object.

int|null
getHighWater()

The current value of the high water mark.

saveHighWater(int $high_water)

Save the new high water mark.

array
getHighWaterProperty()

Get information on the property used as the high watermark.

string|null
getHighWaterField()

Get the name of the field used as the high watermark.

preRollback(MigrateRollbackEvent $event)

Performs pre-rollback tasks.

postRollback(MigrateRollbackEvent $event)

Performs post-rollback tasks.

string|null
getSourceModule()

Gets the source module providing the source data.

create(ContainerInterface $container, array $configuration, string $plugin_id, mixed $plugin_definition, MigrationInterface $migration = NULL)

Creates an instance of the plugin.

__toString()

Prints the query string when the object is used as a string.

from  SqlBase
getDatabase()

Gets the database connection object.

from  SqlBase
setUpDatabase(array $database_info)

Gets a connection to the referenced database.

from  SqlBase
checkRequirements()

Checks if requirements for this plugin are OK.

select($table, $alias = NULL, array $options = [])

Wrapper for database select.

from  SqlBase
prepareQuery()

Adds tags and metadata to the query.

from  SqlBase
fetchNextBatch()

Prepares query for the next set of data from the source database.

from  SqlBase
query()

No description

bool
mapJoinable()

Checks if we can join against the map table.

from  SqlBase
$this
addDependency(string $type, string $name)

Adds a dependency.

addDependencies(array $dependencies)

Adds multiple dependencies.

array
getSystemData()

Retrieves all system data information from the source Drupal database.

mixed
getModuleSchemaVersion(string $module)

Retrieves a module schema_version from the source Drupal database.

bool
moduleExists(string $module)

Checks if a given module is enabled in the source Drupal database.

mixed
variableGet($name, $default)

Reads a variable from a source Drupal database.

array
calculateDependencies()

Calculates dependencies for the configured plugin.

array
fields()

Returns available fields on the source.

array[]
getIds()

Defines the source fields uniquely identifying a source row.

Details

__construct(array $configuration, string $plugin_id, mixed $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityTypeManagerInterface $entity_type_manager)

Constructs a \Drupal\Component\Plugin\PluginBase object.

Parameters

array $configuration

A configuration array containing information about the plugin instance.

string $plugin_id

The plugin_id for the plugin instance.

mixed $plugin_definition

The plugin implementation definition.

MigrationInterface $migration
StateInterface $state
EntityTypeManagerInterface $entity_type_manager

string getPluginId()

Gets the plugin_id of the plugin instance.

Return Value

string

The plugin_id of the plugin instance.

string getBaseId()

Gets the base_plugin_id of the plugin instance.

Return Value

string

The base_plugin_id of the plugin instance.

string|null getDerivativeId()

Gets the derivative_id of the plugin instance.

Return Value

string|null

The derivative_id of the plugin instance NULL otherwise.

array getPluginDefinition()

Gets the definition of the plugin implementation.

Return Value

array

The plugin definition, as returned by the discovery object used by the plugin manager.

bool isConfigurable()

Determines if the plugin is configurable.

Return Value

bool

A boolean indicating whether the plugin is configurable.

protected TranslatableMarkup t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.

In order for strings to be localized, make them available in one of the ways supported by the

Parameters

string $string

A string containing the English text to translate.

array $args

(optional) An associative array of replacements to make after translation. Based on the first character of the key, the value is escaped and/or themed. See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for details.

array $options

(optional) An associative array of additional options, with the following elements:

  • 'langcode' (defaults to the current language): A language code, to translate to a language other than what is used to display the page.
  • 'context' (defaults to the empty context): The context the source string belongs to. See the @link i18n Internationalization topic @endlink for more information about string contexts.

Return Value

TranslatableMarkup

An object that, when cast to a string, returns the translated string.

See also

FormattableMarkup::placeholderFormat
TranslatableMarkup::__construct

protected formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

Parameters

$count
$singular
$plural
array $args
array $options

See also

TranslationInterface::formatPlural

protected getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

Parameters

$langcode

See also

PluralFormulaInterface::getNumberOfPlurals

protected TranslationInterface getStringTranslation()

Gets the string translation service.

Return Value

TranslationInterface

The string translation service.

$this setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

Parameters

TranslationInterface $translation

The string translation service.

Return Value

$this

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

setMessenger(MessengerInterface $messenger)

Sets the messenger.

Parameters

MessengerInterface $messenger

The messenger.

MessengerInterface messenger()

Gets the messenger.

Return Value

MessengerInterface

The messenger.

protected Iterator initializeIterator()

Initializes the iterator with the source data.

Return Value

Iterator

Returns an iterable object of data for this source.

protected ModuleHandlerInterface getModuleHandler()

Gets the module handler.

Return Value

ModuleHandlerInterface

The module handler.

bool prepareRow(Row $row)

Adds additional data to the row.

Parameters

Row $row

The row object.

Return Value

bool

FALSE if this row needs to be skipped.

protected Iterator getIterator()

Returns the iterator that will yield the row arrays to be processed.

Return Value

Iterator

The iterator that will yield the row arrays to be processed.

current()

{@inheritdoc}

key()

Gets the iterator key.

Implementation of \Iterator::key() - called when entering a loop iteration, returning the key of the current row. It must be a scalar - we will serialize to fulfill the requirement, but using getCurrentIds() is preferable.

valid()

Checks whether the iterator is currently valid.

Implementation of \Iterator::valid() - called at the top of the loop, returning TRUE to process the loop and FALSE to terminate it.

rewind()

Rewinds the iterator.

Implementation of \Iterator::rewind() - subclasses of SourcePluginBase should implement initializeIterator() to do any class-specific setup for iterating source records.

next()

{@inheritdoc}

protected fetchNextRow()

Position the iterator to the following row.

protected bool aboveHighWater(Row $row)

Check if the incoming data is newer than what we've previously imported.

Parameters

Row $row

The row we're importing.

Return Value

bool

TRUE if the high-water value in the row is greater than our current value.

protected bool rowChanged(Row $row)

Checks if the incoming row has changed since our last import.

Parameters

Row $row

The row we're importing.

Return Value

bool

TRUE if the row has changed otherwise FALSE.

getCurrentIds()

Gets the currentSourceIds data member.

int count(bool $refresh = FALSE)

Gets the source count.

Return a count of available source records, from the cache if appropriate. Returns MigrateSourceInterface::NOT_COUNTABLE if the source is not countable.

Parameters

bool $refresh

(optional) Whether or not to refresh the count. Defaults to FALSE. Not all implementations support the reset flag. In such instances this parameter is ignored and the result of calling the method will always be up to date.

Return Value

int

The count.

protected CacheBackendInterface getCache()

Gets the cache object.

Return Value

CacheBackendInterface

The cache object.

protected int doCount()

Gets the source count using countQuery().

Return Value

int

protected KeyValueStoreInterface getHighWaterStorage()

Get the high water storage object.

Return Value

KeyValueStoreInterface

The storage object.

protected int|null getHighWater()

The current value of the high water mark.

The high water mark defines a timestamp stating the time the import was last run. If the mark is set, only content with a higher timestamp will be imported.

Return Value

int|null

A Unix timestamp representing the high water mark, or NULL if no high water mark has been stored.

protected saveHighWater(int $high_water)

Save the new high water mark.

Parameters

int $high_water

The high water timestamp.

protected array getHighWaterProperty()

Get information on the property used as the high watermark.

Array of 'name' & (optional) db 'alias' properties used for high watermark.

Return Value

array

The property used as the high watermark.

See also

SqlBase::initializeIterator

protected string|null getHighWaterField()

Get the name of the field used as the high watermark.

The name of the field qualified with an alias if available.

Return Value

string|null

The name of the field for the high water mark, or NULL if not set.

See also

SqlBase::initializeIterator

preRollback(MigrateRollbackEvent $event)

Performs pre-rollback tasks.

Parameters

MigrateRollbackEvent $event

The pre-rollback event object.

postRollback(MigrateRollbackEvent $event)

Performs post-rollback tasks.

Parameters

MigrateRollbackEvent $event

The post-rollback event object.

string|null getSourceModule()

Gets the source module providing the source data.

Return Value

string|null

The source module or NULL if not found.

static ContainerFactoryPluginInterface create(ContainerInterface $container, array $configuration, string $plugin_id, mixed $plugin_definition, MigrationInterface $migration = NULL)

Creates an instance of the plugin.

Parameters

ContainerInterface $container

The container to pull out services used in the plugin.

array $configuration

A configuration array containing information about the plugin instance.

string $plugin_id

The plugin ID for the plugin instance.

mixed $plugin_definition

The plugin implementation definition.

MigrationInterface $migration

Return Value

ContainerFactoryPluginInterface

Returns an instance of this plugin.

__toString()

Prints the query string when the object is used as a string.

Connection getDatabase()

Gets the database connection object.

Return Value

Connection

The database connection.

protected Connection setUpDatabase(array $database_info)

Gets a connection to the referenced database.

This method will add the database connection if necessary.

Parameters

array $database_info

Configuration for the source database connection. The keys are: 'key' - The database connection key. 'target' - The database connection target. 'database' - Database configuration array as accepted by Database::addConnectionInfo.

Return Value

Connection

The connection to use for this plugin's queries.

Exceptions

RequirementsException

checkRequirements()

Checks if requirements for this plugin are OK.

protected select($table, $alias = NULL, array $options = [])

Wrapper for database select.

Parameters

$table
$alias
array $options

protected SelectInterface prepareQuery()

Adds tags and metadata to the query.

Return Value

SelectInterface

The query with additional tags and metadata.

protected fetchNextBatch()

Prepares query for the next set of data from the source database.

SelectInterface query()

No description

Return Value

SelectInterface

protected bool mapJoinable()

Checks if we can join against the map table.

This function specifically catches issues when we're migrating with unique sets of credentials for the source and destination database.

Return Value

bool

TRUE if we can join against the map table otherwise FALSE.

protected $this addDependency(string $type, string $name)

Adds a dependency.

Parameters

string $type

Type of dependency being added: 'module', 'theme', 'config', 'content'.

string $name

If $type is 'module' or 'theme', the name of the module or theme. If $type is 'config' or 'content', the result of EntityInterface::getConfigDependencyName().

Return Value

$this

See also

EntityInterface::getConfigDependencyName

protected addDependencies(array $dependencies)

Adds multiple dependencies.

Parameters

array $dependencies

An array of dependencies keyed by the type of dependency. One example: @code array( 'module' => array( 'node', 'field', 'image', ), ); @endcode

See also

DependencyTrait::addDependency

array getSystemData()

Retrieves all system data information from the source Drupal database.

Return Value

array

List of system table information keyed by type and name.

protected mixed getModuleSchemaVersion(string $module)

Retrieves a module schema_version from the source Drupal database.

Parameters

string $module

Name of module.

Return Value

mixed

The current module schema version on the origin system table or FALSE if not found.

protected bool moduleExists(string $module)

Checks if a given module is enabled in the source Drupal database.

Parameters

string $module

Name of module to check.

Return Value

bool

TRUE if module is enabled on the origin system, FALSE if not.

protected mixed variableGet($name, $default)

Reads a variable from a source Drupal database.

Parameters

$name

Name of the variable.

$default

The default value.

Return Value

mixed

array calculateDependencies()

Calculates dependencies for the configured plugin.

Dependencies are saved in the plugin's configuration entity and are used to determine configuration synchronization order. For example, if the plugin integrates with specific user roles, this method should return an array of dependencies listing the specified roles.

Return Value

array

An array of dependencies grouped by type (config, content, module, theme). For example: @code array( 'config' => array('user.role.anonymous', 'user.role.authenticated'), 'content' => array('node:article:f0a189e6-55fb-47fb-8005-5bef81c44d6d'), 'module' => array('node', 'user'), 'theme' => array('seven'), ); @endcode

array fields()

Returns available fields on the source.

Return Value

array

Available fields in the source, keys are the field machine names as used in field mappings, values are descriptions.

array[] getIds()

Defines the source fields uniquely identifying a source row.

None of these fields should contain a NULL value. If necessary, use prepareRow() or hook_migrate_prepare_row() to rewrite NULL values to appropriate empty values (such as '' or 0).

Return Value

array[]

An associative array of field definitions keyed by field ID. Values are associative arrays with a structure that contains the field type ('type' key). The other keys are the field storage settings as they are returned by FieldStorageDefinitionInterface::getSettings().

Examples:

A composite source primary key that is defined by an integer and a string might look like this: @code return [ 'id' => [ 'type' => 'integer', 'unsigned' => FALSE, 'size' => 'big', ], 'version' => [ 'type' => 'string', 'max_length' => 64, 'is_ascii' => TRUE, ], ]; @endcode

If 'type' points to a field plugin with multiple columns and needs to refer to a column different than 'value', the key of that column will be appended as a suffix to the plugin name, separated by dot ('.'). Example: @code return [ 'format' => [ 'type' => 'text.format', ], ]; @endcode

Additional custom keys/values that are not part of field storage definition can be added as shown below. The most common setting passed along to the ID definition is table 'alias', used by the SqlBase source plugin in order to distinguish between ambiguous column names - for example, when a SQL source query joins two tables with the same column names. @code return [ 'nid' => [ 'type' => 'integer', 'alias' => 'n', ], ]; @endcode