You are here

public function Html::import in Translation Management Tool 8

Implements TMGMTFileExportInterface::import().

Overrides FormatInterface::import

File

translators/tmgmt_file/src/Plugin/tmgmt_file/Format/Html.php, line 62

Class

Html
Export into HTML.

Namespace

Drupal\tmgmt_file\Plugin\tmgmt_file\Format

Code

public function import($imported_file, $is_file = TRUE) {
  $dom = new \DOMDocument();
  $is_file ? $dom
    ->loadHTMLFile($imported_file) : $dom
    ->loadHTML($imported_file);
  $xml = simplexml_import_dom($dom);
  $data = array();
  foreach ($xml
    ->xpath("//div[@class='atom']") as $atom) {

    // Assets are our strings (eq fields in nodes).
    $key = $this
      ->decodeIdSafeBase64((string) $atom['id']);
    $data[$key]['#text'] = (string) $atom;
  }
  return \Drupal::service('tmgmt.data')
    ->unflatten($data);
}