Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 294676

MachineName migrate process plugin should make allowed characters regular expression configurable

$
0
0

Problem/Motivation

The machine_name migrate process plugins replaces all non alphanumeric characters with underscores. It would be great if that would be a bit more flexible. Concretely, for some machine names it makes sense to allow a period as part of the name which currently gets replaced.

The code that currently handles this is the following:

    $new_value = preg_replace('/[^a-z0-9_]+/', '_', $new_value);

Concretely, when importing files from an external source, you may want to transliterate the filename and remove any "special" characters from the filename. However, periods in the filename need to be retained, so that the file still has a proper file extension. In this case the pattern may be changed to allow a period ("."). And you may also want to allow a dash ("-") as that is a common character in filenames. That means you need to run:

    $new_value = preg_replace('/[^a-z0-9_\-.]+/', '-', $new_value);

Also. some entity types allow periods in their IDs so when importing those from external systems, you may have to change the replace pattern accordingly.

Proposed resolution

Add a replace_pattern configuration value to the plugin to make the pattern configurable.


Viewing all articles
Browse latest Browse all 294676

Trending Articles