class SvgEmbedProcess in SVG Embed 8
Same name and namespace in other branches
- 2.0.x src/SvgEmbedProcess.php \Drupal\svg_embed\SvgEmbedProcess
Class SvgEmbedProcess.
@package Drupal\svg_embed
Hierarchy
- class \Drupal\svg_embed\SvgEmbedProcess implements SvgEmbedProcessInterface
Expanded class hierarchy of SvgEmbedProcess
1 string reference to 'SvgEmbedProcess'
1 service uses SvgEmbedProcess
File
- src/
SvgEmbedProcess.php, line 16
Namespace
Drupal\svg_embedView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SvgEmbedProcess:: |
protected | property | ||
SvgEmbedProcess:: |
public | function |
Overrides SvgEmbedProcessInterface:: |
|
SvgEmbedProcess:: |
private | function | ||
SvgEmbedProcess:: |
public | function |
Overrides SvgEmbedProcessInterface:: |
|
SvgEmbedProcess:: |
public | function | SvgEmbedProcess constructor. |