Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@daggerhart
Created August 15, 2018 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daggerhart/de1b98f90d0acdd20a0e4be6ccfb8fea to your computer and use it in GitHub Desktop.
Save daggerhart/de1b98f90d0acdd20a0e4be6ccfb8fea to your computer and use it in GitHub Desktop.
Fast machine names for Drupal 8 - hacky
(function ($, Drupal) {
delete Drupal.behaviors.machineName.transliterate;
Drupal.behaviors.machineName.transliterate = function(str) {
var transliterated = str.replace(' ', '_').replace(/[^\w]+/g,'').toLowerCase();
var deferred = $.Deferred();
var promise = deferred.promise();
deferred.resolve(transliterated);
promise.abort = function() {};
return promise;
}
})(jQuery, Drupal);
fast_machine_names:
version: 0.5
js:
fast_machine_names.js: {}
dependencies:
- core/drupal.machine-name
<?php
function fast_machine_names_form_field_ui_field_storage_add_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
$form['new_storage_wrapper']['field_name']['#attached']['library'][] = 'fast_machine_names/fast_machine_names';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment