Skip to content

Instantly share code, notes, and snippets.

@marcelovani
Created October 16, 2019 10:20
Show Gist options
  • Save marcelovani/b49d1746ab73e79afbb693166ddb4391 to your computer and use it in GitHub Desktop.
Save marcelovani/b49d1746ab73e79afbb693166ddb4391 to your computer and use it in GitHub Desktop.
Generates a CSV of fields on entities to be used on migration map spreadsheets
// ==UserScript==
// @name FieldCollector
// @namespace drupal
// @version 0.1
// @description Gets list of fields from field ui and creates a CSV, you need to be on the Manage fields tab and Console must be open. Useful to create migration mappings. Copy the list of fields, paste on google docs and go to Data/Split text to columns
// @author Marcelo Vani
// @match http://*/*
// @grant none
// @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// ==/UserScript==
$(document).ready(function() {
var fields = [];
fields.push('Label, Machine name, Field type, Migrate to');
var trs = jQuery('.field-ui-overview').find('tr');
jQuery.each( trs, function( i, tr ) {
var id = $(tr).attr('id');
if (typeof id != 'undefined') {
var label = $(tr).find("td:nth-child(1)").text();
var machine_name = $(tr).find("td:nth-child(4)").text();
var field_type = $(tr).find("td:nth-child(5)").text();
fields.push(label + ',' + machine_name + ',' + field_type + ',');
}
});
var csv = fields.map(function(d){
return d.trim();
}).join('\n');
console.log(csv);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment