Skip to content
Snippets Groups Projects
Commit d5ec6df4 authored by Dimitris Bozelos's avatar Dimitris Bozelos
Browse files

Issue #3463234 Added support for token replacement in file directory

parent ef52ea78
Branches 1.x
No related merge requests found
...@@ -12,10 +12,12 @@ use Drupal\file\FileInterface; ...@@ -12,10 +12,12 @@ use Drupal\file\FileInterface;
use Drupal\file\FileRepositoryInterface; use Drupal\file\FileRepositoryInterface;
// Drupal core. // Drupal core.
use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Component\Render\PlainTextOutput;
use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\File\Exception\DirectoryNotReadyException; use Drupal\Core\File\Exception\DirectoryNotReadyException;
use Drupal\Core\File\FileSystemInterface; use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Utility\Token;
// Third-party libraries. // Third-party libraries.
use Mailgun\Exception\HttpClientException; use Mailgun\Exception\HttpClientException;
use Mailgun\Mailgun; use Mailgun\Mailgun;
...@@ -101,6 +103,8 @@ class FileAttachments extends PluginBase { ...@@ -101,6 +103,8 @@ class FileAttachments extends PluginBase {
* The file system. * The file system.
* @param \Drupal\file\FileRepositoryInterface $fileRepository * @param \Drupal\file\FileRepositoryInterface $fileRepository
* The file repository. * The file repository.
* @param \Drupal\Core\Utility\Token $token
* The token service.
*/ */
public function __construct( public function __construct(
array $configuration, array $configuration,
...@@ -111,6 +115,7 @@ class FileAttachments extends PluginBase { ...@@ -111,6 +115,7 @@ class FileAttachments extends PluginBase {
protected EntityFieldManagerInterface $entityFieldManager, protected EntityFieldManagerInterface $entityFieldManager,
protected FileSystemInterface $fileSystem, protected FileSystemInterface $fileSystem,
protected FileRepositoryInterface $fileRepository, protected FileRepositoryInterface $fileRepository,
protected Token $token,
) { ) {
parent::__construct( parent::__construct(
$configuration, $configuration,
...@@ -140,6 +145,7 @@ class FileAttachments extends PluginBase { ...@@ -140,6 +145,7 @@ class FileAttachments extends PluginBase {
$container->get('entity_field.manager'), $container->get('entity_field.manager'),
$container->get('file_system'), $container->get('file_system'),
$container->get('file.repository'), $container->get('file.repository'),
$container->get('token'),
); );
} }
...@@ -436,7 +442,10 @@ class FileAttachments extends PluginBase { ...@@ -436,7 +442,10 @@ class FileAttachments extends PluginBase {
); );
$definition = $definitions[$field_name]; $definition = $definitions[$field_name];
$uri_scheme = $definition->getSetting('uri_scheme'); $uri_scheme = $definition->getSetting('uri_scheme');
$file_directory = $definition->getSetting('file_directory') ?? ''; $file_directory = PlainTextOutput::renderFromHtml($this->token->replace(
$definition->getSetting('file_directory') ?? '',
[],
));
if (empty($uri_scheme)) { if (empty($uri_scheme)) {
throw new InvalidConfigurationException( throw new InvalidConfigurationException(
'No URI scheme setting found for the field.' 'No URI scheme setting found for the field.'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment