function metatag_importer_metatags_quick_process in Metatag 7
Process a row from Metatags Quick.
Imports data into metatag structure, and deletes Metatags Quick data.
Parameters
array $quick: Row of data from Metatags Quick.
1 call to metatag_importer_metatags_quick_process()
- metatag_importer_metatags_quick_import in metatag_importer/
metatag_importer.metatags_quick.inc - Import all data from Metatags Quick and delete it.
File
- metatag_importer/
metatag_importer.metatags_quick.inc, line 57 - Convert data from Metatags Quick to Metatag.
Code
function metatag_importer_metatags_quick_process(array $quick) {
// Identify which Metatag meta tags will be filled by Metatags Quick values.
$tag_map = array(
'title' => 'title',
'keywords' => 'keywords',
'abstract' => 'abstract',
'description' => 'description',
'canonical' => 'canonical',
);
if (module_exists('metatag_opengraph')) {
$tag_map['og:title'] = 'title';
$tag_map['og:description'] = 'description';
}
if (module_exists('metatag_twitter_cards')) {
$tag_map['twitter:title'] = 'title';
$tag_map['twitter:description'] = 'description';
}
$entity_type = $quick['entity_type'];
$entity_id = $quick['entity_id'];
$revision_id = $quick['revision_id'];
$langcode = $quick['language'];
// Fallback to entity language if no field language is set.
if (LANGUAGE_NONE == $langcode) {
$entities = entity_load($entity_type, array(
$entity_id,
));
if (!empty($entities[$entity_id])) {
$langcode = entity_language($entity_type, $entities[$entity_id]);
}
}
// Check for an existing record.
$data = metatag_metatags_load($entity_type, $entity_id);
// Drop back one level because the results will be keyed by revision_id.
if (!empty($data)) {
$data = reset($data);
}
// Map the Quick meta tags.
foreach ($tag_map as $dest => $source) {
if (!empty($quick['fields'][$source]['value'])) {
$data[$langcode][$dest] = array(
'value' => $quick['fields'][$source]['value'],
);
// Add the default suffix to the page title.
if ($dest == 'title') {
$data[$langcode][$dest]['value'] .= ' | [site:name]';
}
}
}
// Create or update the {metatag} record.
if (!empty($data)) {
metatag_metatags_save($entity_type, $entity_id, $revision_id, $data);
}
if (!empty($quick['fields'])) {
metatag_importer_delete_quick_data($quick['fields']);
}
// Reset the entity cache. If entitycache module is used, this also resets
// its permanent cache.
entity_get_controller($entity_type)
->resetCache(array(
$entity_id,
));
}