77
88namespace Drupal \dropzonejs ;
99
10+ use Drupal \Component \Render \PlainTextOutput ;
1011use Drupal \Core \Config \ConfigFactoryInterface ;
1112use Drupal \Core \Entity \EntityManagerInterface ;
1213use Drupal \Core \Logger \LoggerChannelFactoryInterface ;
1314use Drupal \Core \Render \RendererInterface ;
1415use Drupal \Core \Session \AccountProxyInterface ;
16+ use Drupal \Core \Utility \Token ;
1517use Drupal \file \FileInterface ;
1618use Symfony \Component \HttpFoundation \File \MimeType \MimeTypeGuesserInterface ;
1719use Symfony \Component \Validator \Constraints \File ;
@@ -68,6 +70,13 @@ class DropzoneJsUploadSave implements DropzoneJsUploadSaveInterface {
6870 */
6971 protected $ configFactory ;
7072
73+ /**
74+ * The token service.
75+ *
76+ * @var \Drupal\Core\Utility\Token
77+ */
78+ protected $ token ;
79+
7180 /**
7281 * Construct the DropzoneUploadSave object.
7382 *
@@ -83,14 +92,17 @@ class DropzoneJsUploadSave implements DropzoneJsUploadSaveInterface {
8392 * The renderer service.
8493 * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
8594 * Config factory service.
95+ * @param \Drupal\Core\Utility\Token $token
96+ * The token service.
8697 */
87- public function __construct (EntityManagerInterface $ entity_manager , MimeTypeGuesserInterface $ mimetype_guesser , FileSystemInterface $ file_system , LoggerChannelFactoryInterface $ logger_factory , RendererInterface $ renderer , ConfigFactoryInterface $ config_factory ) {
98+ public function __construct (EntityManagerInterface $ entity_manager , MimeTypeGuesserInterface $ mimetype_guesser , FileSystemInterface $ file_system , LoggerChannelFactoryInterface $ logger_factory , RendererInterface $ renderer , ConfigFactoryInterface $ config_factory, Token $ token ) {
8899 $ this ->entityManager = $ entity_manager ;
89100 $ this ->mimeTypeGuesser = $ mimetype_guesser ;
90101 $ this ->fileSystem = $ file_system ;
91102 $ this ->logger = $ logger_factory ->get ('dropzonejs ' );
92103 $ this ->renderer = $ renderer ;
93104 $ this ->configFactory = $ config_factory ;
105+ $ this ->token = $ token ;
94106 }
95107
96108 /**
@@ -100,6 +112,10 @@ public function saveFile($uri, $destination, $extensions, AccountProxyInterface
100112 // Create the file entity.
101113 $ file = $ this ->fileEntityFromUri ($ uri , $ user );
102114
115+ // Replace tokens. As the tokens might contain HTML we convert it to plain
116+ // text.
117+ $ destination = PlainTextOutput::renderFromHtml ($ this ->token ->replace ($ destination ));
118+
103119 // Handle potentialy dangerous extensions.
104120 $ renamed = $ this ->renameExecutableExtensions ($ file );
105121 // The .txt extension may not be in the allowed list of extensions. We have
0 commit comments