You are here

protected function Xml::parseSmartlingSlVariantKey in TMGMT Translator Smartling 8.4

Parses sl-variant string into array.

Parameters

string $sl_variant: Contains Smartling sl-variant string like 'node-4-title][0][value'

Return value

array Array with fields: 'entity_type', 'entity_id', 'field_name', 'field_index' and 'field_value_name' parsed from sl-variant string

1 call to Xml::parseSmartlingSlVariantKey()
Xml::import in src/Plugin/tmgmt_file/Format/Xml.php
Implements TMGMTFileExportInterface::import().

File

src/Plugin/tmgmt_file/Format/Xml.php, line 168

Class

Xml
Export into XML.

Namespace

Drupal\tmgmt_smartling\Plugin\tmgmt_file\Format

Code

protected function parseSmartlingSlVariantKey($sl_variant) {
  $sl_variant = explode('-', $sl_variant);
  if (!isset($sl_variant[0]) || !isset($sl_variant[1]) || !isset($sl_variant[2])) {
    return [];
  }
  $field_array = explode(Data::TMGMT_ARRAY_DELIMITER, $sl_variant[2]);
  if (!isset($field_array[0]) || !isset($field_array[1]) || !isset($field_array[2])) {
    return [];
  }
  return [
    'entity_type' => $sl_variant[0],
    'entity_id' => $sl_variant[1],
    'field_name' => $field_array[0],
    'field_index' => $field_array[1],
    'field_value_name' => $field_array[2],
  ];
}