|
|
|
@ -7,7 +7,6 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
|
|
|
|
|
use Drupal\Core\Field\EntityReferenceFieldItemListInterface; |
|
|
|
|
use Drupal\Core\Field\FieldItemList; |
|
|
|
|
use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem; |
|
|
|
|
use Drupal\Core\File\FileUrlGeneratorInterface; |
|
|
|
|
use Drupal\file\FileInterface; |
|
|
|
|
use Drupal\link\LinkItemInterface; |
|
|
|
|
use Drupal\media\MediaInterface; |
|
|
|
@ -25,19 +24,11 @@ class UrlExtractor {
|
|
|
|
|
*/ |
|
|
|
|
protected $entityTypeManager; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* The fire URL generator. |
|
|
|
|
* |
|
|
|
|
* @var \Drupal\Core\File\FileUrlGeneratorInterface |
|
|
|
|
*/ |
|
|
|
|
protected $fileUrlGenerator; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Constructs a UrlExtractor object. |
|
|
|
|
*/ |
|
|
|
|
public function __construct(EntityTypeManagerInterface $entity_type_manager, FileUrlGeneratorInterface $file_url_generator) { |
|
|
|
|
public function __construct(EntityTypeManagerInterface $entity_type_manager) { |
|
|
|
|
$this->entityTypeManager = $entity_type_manager; |
|
|
|
|
$this->fileUrlGenerator = $file_url_generator; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -53,8 +44,8 @@ class UrlExtractor {
|
|
|
|
|
*/ |
|
|
|
|
public function extractUrl($input, bool $relative = TRUE): ?string { |
|
|
|
|
if (is_string($input)) { |
|
|
|
|
$url = $this->fileUrlGenerator->generateAbsoluteString($input); |
|
|
|
|
return $relative ? $this->fileUrlGenerator->transformRelative($url) : $url; |
|
|
|
|
$url = file_create_url($input); |
|
|
|
|
return $relative ? file_url_transform_relative($url) : $url; |
|
|
|
|
} |
|
|
|
|
elseif ($input instanceof LinkItemInterface) { |
|
|
|
|
return $input->getUrl()->toString(); |
|
|
|
|