Created
August 15, 2018 02:03
-
-
Save daggerhart/de1b98f90d0acdd20a0e4be6ccfb8fea to your computer and use it in GitHub Desktop.
Fast machine names for Drupal 8 - hacky
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fast_machine_names: | |
version: 0.5 | |
js: | |
fast_machine_names.js: {} | |
dependencies: | |
- core/drupal.machine-name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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