View source
<?php
function contextual_view_modes_update_7101(&$sandbox) {
db_update('system')
->fields(array(
'weight' => 100,
))
->condition('name', 'contextual_view_modes')
->execute();
}
function contextual_view_modes_update_7102(&$sandbox) {
}
function contextual_view_modes_update_7200(&$sandbox) {
module_enable(array(
"contextual_view_modes_nodes",
"contextual_view_modes_users",
), TRUE);
$storage = array();
$values = db_select('field_data_field_cvm_cvm', 'fdfcc')
->fields("fdfcc", array(
"entity_type",
"entity_id",
"field_cvm_cvm_view_mode",
"field_cvm_cvm_context",
"delta",
))
->execute();
while ($o = $values
->fetchObject()) {
$type = $o->entity_type;
if (isset($storage["contextual_view_modes_" . $type])) {
$vars = $storage["contextual_view_modes_" . $type];
}
else {
$vars = variable_get("contextual_view_modes_" . $type, array());
}
if (isset($vars[$o->entity_id])) {
$vars[$o->entity_id] = array();
}
$vars[$o->entity_id][$o->delta] = array(
'context_name' => $o->field_cvm_cvm_context,
'view_mode' => $o->field_cvm_cvm_view_mode,
);
$storage["contextual_view_modes_" . $type] = $vars;
}
foreach ($storage as $cvm_type => $variables) {
variable_set($cvm_type, $variables);
}
db_drop_table("field_data_field_cvm_cvm");
db_drop_table("field_revision_field_cvm_cvm");
db_delete("field_config")
->condition("module", "cvm_field")
->execute();
db_delete("field_config_instance")
->condition("field_name", "field_cvm_cvm")
->execute();
$old_global = variable_get("cvm_global_content_type_modes", array());
$new_global = variable_get("contextual_view_modes_global", array());
foreach ($old_global as $bundle => $settings) {
foreach ($settings as $context_name => $view_mode) {
$new_global["node"][] = array(
'bundle' => $bundle,
'context' => $context_name,
'view_mode' => $view_mode,
);
}
}
variable_set("contextual_view_modes_global", $new_global);
variable_del("cvm_enabled_content_types");
variable_del("cvm_global_content_type_modes");
}
function contextual_view_modes_update_7300(&$sandbox) {
$settings = variable_get("contextual_view_modes_global", array());
if (empty($settings)) {
return;
}
foreach ($settings as $entity_type => $more) {
foreach ($more as $delta => $variables) {
$context = context_load($variables['context']);
$context->reactions["context_reaction_view_mode"]["entity_types"][$entity_type][$variables["bundle"]] = $variables["view_mode"];
context_save($context);
}
}
variable_del("contextual_view_modes_global");
}