Skip to content
This repository has been archived by the owner on Jun 22, 2020. It is now read-only.

Use core's filename transliteration #546

Open
wants to merge 1 commit into
base: 8.x-3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
},
"drupal/redirect": {
"Provided config does not match the config after an export": "https://www.drupal.org/files/issues/2932248-3.patch"
},
"drupal/core": {
"Use new Transliteration functionality in core for file names": "https://www.drupal.org/files/issues/2018-05-14/2492171-93.patch"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's wait till this has been merge into core

}
}
},
Expand Down
1 change: 1 addition & 0 deletions drupal-org-core.make
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ core = 8.x
projects[drupal][type] = core
projects[drupal][download][url] = https://git.drupal.org/project/drupal.git
projects[drupal][download][branch] = 8.6.x
projects[drupal][patch][] = https://www.drupal.org/files/issues/2018-05-14/2492171-93.patch
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
enable_filename_transliteration: false
enable_filefield_remove_button: false
3 changes: 0 additions & 3 deletions modules/thunder_media/config/schema/thunder_media.schema.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
thunder_media.settings:
type: config_object
mapping:
enable_filename_transliteration:
type: boolean
label: 'Default transliteration'
enable_filefield_remove_button:
type: boolean
label: 'Enable remove button'
8 changes: 0 additions & 8 deletions modules/thunder_media/src/Form/ConfigurationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ public function getFormId() {
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('thunder_media.settings');

$form['enable_filename_transliteration'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable filename transliteration'),
'#description' => $this->t('Enable this checkbox to clean filenames before saving the files.'),
'#default_value' => $config->get('enable_filename_transliteration'),
];

$form['enable_filefield_remove_button'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable file field remove button'),
Expand All @@ -58,7 +51,6 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);

$this->config('thunder_media.settings')
->set('enable_filename_transliteration', $form_state->getValue('enable_filename_transliteration'))
->set('enable_filefield_remove_button', $form_state->getValue('enable_filefield_remove_button'))
->save();
}
Expand Down

This file was deleted.

23 changes: 0 additions & 23 deletions modules/thunder_media/thunder_media.module
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,8 @@
* Contains media related functions.
*/

use Drupal\file\Entity\File;
use Drupal\Core\Form\FormStateInterface;

/**
* Implements hook_ENTITY_TYPE_create().
*/
function thunder_media_file_create(File $entity) {

$config = \Drupal::config('thunder_media.settings');

if ($config->get('enable_filename_transliteration')) {

$pathinfo = pathinfo($entity->getFilename());

/** @var \Drupal\pathauto\AliasCleaner $aliasCleaner */
$aliasCleaner = \Drupal::service('pathauto.alias_cleaner');

// Check for needed pathinfo array keys.
if (!empty($pathinfo['filename']) && !empty($pathinfo['extension'])) {
$cleanFilename = $aliasCleaner->cleanString($pathinfo['filename']) . '.' . $pathinfo['extension'];
$entity->setFilename($cleanFilename);
}
}
}

/**
* Implements hook_preprocess_views_view().
*/
Expand Down
21 changes: 21 additions & 0 deletions modules/thunder_media/thunder_media.post_update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/**
* @file
* Post update functions for Thunder.
*/

/**
* Move to core's filename transliteration functionality.
*/
function thunder_media_post_update_move_to_core_filename_transliteration() {

/** @var \Drupal\thunder_updater\Updater $thunderUpdater */
$thunderUpdater = \Drupal::service('thunder_updater');

\Drupal::config('system.file')->set('filename_transliteration', \Drupal::config('thunder_media.settings')->get('enable_filename_transliteration'));
\Drupal::config('thunder_media.settings')->clear('enable_filename_transliteration');

// Output logged messages to related channel of update execution.
return $thunderUpdater->logger()->output();
}