Gutenberg https://notes.masterweb.sk/ sk Drupal Gutenberg keeping filenames https://notes.masterweb.sk/drupal-8/drupal-gutenberg-keeping-filenames <span class="field field--name-title field--type-string field--label-hidden">Drupal Gutenberg keeping filenames</span> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/user/1" typeof="schema:Person" property="schema:name" datatype="">ROOT</span></span> <span class="field field--name-created field--type-created field--label-hidden">Pi, 07/03/2020 - 15:16</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Use case:</p> <p>by default Gutenberg is changing file names if they are uploading via Gutenberg Content Blocks (Images and Media) to some_hash.jpg wich is non good for SEO.</p> <p>Temp solution is comment this function in file /modules/contrib/gutenberg/src/MediaUploader.php and add function getClientOriginalName:</p> <pre> $data = file_get_contents($uploaded_file-&gt;getPathname()); // <s>$file_name = $this-&gt;getRandomFileName($uploaded_file-&gt;getClientOriginalExtension() ?: '');</s> // added line for keeping original filenames: <strong>$file_name = $uploaded_file-&gt;getClientOriginalName();</strong> $file = file_save_data($data, "{$directory}/{$file_name}", FileSystemInterface::EXISTS_RENAME);</pre> <p><strong>This is just TEMPORARY solution, and must be checked after each Gutenberg module update !!</strong></p> <p> </p> </div><div class="field field--name-field-tags field--type-entity-reference field--label-above clearfix"> <h3 class="field__label">Značky</h3> <ul class="links field__items"> <li><a href="/taxonomy/term/16" hreflang="sk">Drupal 8</a></li> <li><a href="/taxonomy/term/65" hreflang="sk">Gutenberg</a></li> </ul> </div> Fri, 03 Jul 2020 13:16:28 +0000ROOT131 at https://notes.masterweb.skhttps://notes.masterweb.sk/drupal-8/drupal-gutenberg-keeping-filenames#comments