function metatags_quick_update_7006 in Meta tags quick 7.2
Ensure all existing metatags_quick fields have the default display formatter if set.
File
- ./
metatags_quick.install, line 183 - Defines schema for metatags_quick fields
Code
function metatags_quick_update_7006() {
$module_path = drupal_get_path('module', 'metatags_quick');
include_once $module_path . '/known_tags.inc';
$known_tags = _metatags_quick_known_fields();
// Get the known tag names and formatters
$known_tag_names_and_formatters = array();
foreach ($known_tags as $tagkey => $tagvalue) {
if (isset($tagvalue['formatter'])) {
$this_name_and_formatter = array(
'name' => 'meta_' . $tagkey,
'formatter' => $tagvalue['formatter'],
);
array_push($known_tag_names_and_formatters, $this_name_and_formatter);
}
}
// Get info on all instances
$metatags_quick_fields = field_info_field_map();
$metatags_quick_instances = array();
// Loop to get name, entity, bundle and formatter
foreach ($known_tag_names_and_formatters as $nfkey => $nfvalue) {
// Within this loop through the metatags_quick_fields
foreach ($metatags_quick_fields as $key => $value) {
// If the type is metatags_quick and if the name == the known_tags_name_and_formatter key (nfkey)
if ($value['type'] == 'metatags_quick' && $key == $nfvalue['name']) {
foreach ($value['bundles'] as $thiskey => $thisvalue) {
$this_instance = array(
'name' => $key,
'entity' => $thiskey,
'bundle' => $thisvalue,
'formatter' => $nfvalue['formatter'],
);
array_push($metatags_quick_instances, $this_instance);
}
}
}
}
foreach ($metatags_quick_instances as $instance => $value) {
$name = $value['name'];
if (is_array($value['entity'])) {
foreach ($value['entity'] as $entity) {
$this_entity = $entity;
}
}
else {
$this_entity = $value['entity'];
}
foreach ($value['bundle'] as $bundle) {
$this_bundle = $bundle;
$field = field_info_instance($this_entity, $name, $this_bundle);
$field['display']['default']['type'] = $value['formatter'];
field_update_instance($field);
}
}
}