You are here

class SvgEmbedProcess in SVG Embed 8

Same name and namespace in other branches
  1. 2.0.x src/SvgEmbedProcess.php \Drupal\svg_embed\SvgEmbedProcess

Class SvgEmbedProcess.

@package Drupal\svg_embed

Hierarchy

Expanded class hierarchy of SvgEmbedProcess

1 string reference to 'SvgEmbedProcess'
svg_embed.services.yml in ./svg_embed.services.yml
svg_embed.services.yml
1 service uses SvgEmbedProcess
svg_embed.process in ./svg_embed.services.yml
Drupal\svg_embed\SvgEmbedProcess

File

src/SvgEmbedProcess.php, line 16

Namespace

Drupal\svg_embed
View source
class SvgEmbedProcess implements SvgEmbedProcessInterface {

  /**
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * SvgEmbedProcess constructor.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  public function translate($uuid, $langcode) : string {
    if ($xml = $this
      ->loadFile($uuid)) {

      //TODO: Go through the DOM and translate all relevant strings, see _svg_embed_translate() in D7
      $xml = str_replace('<?xml version="1.0"?>', '', $xml
        ->asXML());
    }
    return $xml;
  }

  /**
   * {@inheritdoc}
   */
  public function extract($uuid) : array {
    if ($xml = $this
      ->loadFile($uuid)) {

      //TODO: Go through the DOM and extract all relevant strings, see _svg_embed_extract() in D7
    }
    return array();
  }

  /**
   * @param string $uuid
   * @return \SimpleXMLElement|bool
   */
  private function loadFile($uuid) {
    try {

      /** @var File $file */
      if ($file = $this->entityTypeManager
        ->getStorage('file')
        ->loadByProperties([
        'uuid' => $uuid,
      ])) {
        $text = file_get_contents($file
          ->getFileUri());
        return new SimpleXMLElement($text);
      }
    } catch (InvalidPluginDefinitionException $e) {

      // TODO: log this exception.
    } catch (PluginNotFoundException $e) {

      // TODO: log this exception.
    }
    return FALSE;
  }

}

Members