monster_menus-9.0.x-dev/modules/mm_fields/mm_fields.install
modules/mm_fields/mm_fields.install
<?php
/**
* @file
* Install, update and uninstall functions for the mm_fields module.
*/
use Drupal\Core\Database\Database;
/**
* Implements hook_install().
*/
function mm_fields_install() {
}
/**
* Update field display modes and types, so that content_migrate goes more
* smoothly.
*/
function mm_fields_update_7000() {
$db = Database::getConnection();
$result = $db->query("SELECT field_name, type_name, widget_type, display_settings FROM {content_node_field_instance} WHERE widget_type IN('mm_grouplist', 'mm_catlist', 'mm_userlist', 'mm_nodelist')");
foreach ($result as $row) {
$settings = unserialize($row->display_settings);
if (!empty($settings) && is_array($settings)) {
$changed = FALSE;
foreach ($settings as $key => $array) {
if (is_array($array) && isset($array['format']) && $array['format'] == 'link') {
$settings[$key]['format'] = 'mm_fields_link_page';
$changed = TRUE;
}
}
if ($changed) {
$db->update('content_node_field_instance')
->fields(['display_settings' => serialize($settings)])
->condition('field_name', $row->field_name)
->condition('type_name', $row->type_name)
->execute();
}
$db->update('content_node_field')
->fields(['type' => 'mm_fields_' . $row->widget_type])
->condition('field_name', $row->field_name)
->execute();
}
}
$db->update('content_node_field')
->fields(['module' => 'mm_fields'])
->condition('module', 'mm_cck')
->execute();
$db->update('content_node_field_instance')
->fields(['widget_module' => 'mm_fields'])
->condition('widget_module', 'mm_cck')
->execute();
}
