You are here

public function PathFieldProcessor::extractTranslatableData in Translation Management Tool 8

Extracts the translatatable data structure from the given field.

Parameters

\Drupal\Core\Field\FieldItemListInterface $field: The field object.

Return value

array $data An array of elements where each element has the following keys:

  • #text
  • #translate

Overrides DefaultFieldProcessor::extractTranslatableData

See also

\Drupal\tmgmt_content\Plugin\tmgmt\Source\ContentEntitySource::extractTranslatableData()

File

sources/content/src/PathFieldProcessor.php, line 18

Class

PathFieldProcessor
Field processor for the metatags field.

Namespace

Drupal\tmgmt_content

Code

public function extractTranslatableData(FieldItemListInterface $field) {
  $data = parent::extractTranslatableData($field);
  foreach (Element::children($data) as $key) {

    // If pathauto is enabled, do not attempt to translate the path, pathauto
    // will deal with it on the translation.
    if ($field instanceof PathautoFieldItemList && $field->pathauto == PathautoState::CREATE) {
      if (!empty($data[$key]['alias']['#translate'])) {
        $data[$key]['alias']['#translate'] = FALSE;
      }
    }
    if (!empty($data[$key]['langcode']['#translate'])) {
      $data[$key]['langcode']['#translate'] = FALSE;
    }
  }
  return $data;
}