Skip to content

Instantly share code, notes, and snippets.

@jmolivas
jmolivas / module_name.install
Last active November 9, 2017 20:25
Update all of the instances of a field in a Drupal 8 database
<?php
function _update_table_field($fieldName, $valueMapping) {
$schema = \Drupal::database()->schema();
$tables = $schema->findTables('%');
foreach ($tables as $table) {
if ($schema->fieldExists($table, $fieldName)) {
foreach ($valueMapping as $originalValue => $newValue) {
echo sprintf(
'Updating table %s and field %s from %s to %s',