View source
<?php
function contextual_view_modes_install() {
}
function contextual_view_modes_disable() {
}
function contextual_view_modes_uninstall() {
}
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) {
if (!module_exists('cvm_field')) {
if (!module_enable(array(
'cvm_field',
))) {
drupal_set_message(t('could not enable cvm_module'), 'error');
throw new Exception("Could Not Enable cvm_field Module");
}
}
db_update('field_config')
->fields(array(
'module' => 'cvm_field',
'type' => 'cvm_field_cvm',
))
->condition('field_name', 'field_cvm_cvm')
->execute();
$instances = db_select('field_config_instance', 'fci')
->fields("fci")
->condition('field_name', 'field_cvm_cvm')
->execute();
while ($result = $instances
->fetchAssoc()) {
$data = unserialize($result['data']);
$data['widget']['type'] = "cvm_field_picker";
$data['widget']['module'] = 'cvm_field';
db_update('field_config_instance')
->fields(array(
'data' => serialize($data),
))
->condition('id', $result['id'])
->execute();
}
}
function contextual_view_modes_update_7200($node) {
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");
}