FilenameGenerator.php in Entity Print 8.2
File
src/FilenameGenerator.php
View source
<?php
namespace Drupal\entity_print;
use Drupal\Component\Transliteration\TransliterationInterface;
class FilenameGenerator implements FilenameGeneratorInterface {
protected $transliteration;
public function __construct(TransliterationInterface $transliteration) {
$this->transliteration = $transliteration;
}
public function generateFilename(array $entities, callable $entity_label_callback = NULL) {
$filenames = [];
foreach ($entities as $entity) {
if ($label = trim($this
->sanitizeFilename($entity_label_callback ? $entity_label_callback($entity) : $entity
->label(), $entity
->language()
->getId()))) {
$filenames[] = $label;
}
}
return $filenames ? implode('-', $filenames) : static::DEFAULT_FILENAME;
}
protected function sanitizeFilename($filename, $langcode) {
$transformed = $this->transliteration
->transliterate($filename, $langcode);
return preg_replace("/[^A-Za-z0-9 ]/", '', $transformed);
}
}