Skip to content
Snippets Groups Projects
Commit 27cb29d7 authored by Dave Reid's avatar Dave Reid
Browse files

If $entity->metatags is empty, then do not write a record to the metatag table...

If $entity->metatags is empty, then do not write a record to the metatag table since we do not need it.
parent 427ac16a
No related branches found
No related tags found
No related merge requests found
......@@ -309,15 +309,26 @@ function metatag_metatags_save($type, $id, $metatags) {
$function($metatags, $type, $id);
}
db_merge('metatag')
->key(array(
'entity_type' => $type,
'entity_id' => $id,
))
->fields(array(
'data' => serialize($metatags),
))
->execute();
if (empty($metatags)) {
// If the data array is empty, there is no data to actually save, so
// just delete the record from the database.
db_delete('metatag')
->condition('entity_type', $type)
->condition('entity_id', $id)
->execute();
}
else {
// Otherwise save the data for this entity.
db_merge('metatag')
->key(array(
'entity_type' => $type,
'entity_id' => $id,
))
->fields(array(
'data' => serialize($metatags),
))
->execute();
}
// Clear cached data.
metatag_metatags_cache_clear($type, $id);
......@@ -561,7 +572,7 @@ function metatag_metatags_form(array &$form, $instance, array $metatags = array(
foreach (element_children($form) as $key) {
if (isset($form[$key]['#type']) && $form[$key]['#type'] == 'vertical_tabs') {
$form['metatags']['#group'] = $key;
$form['metatags']['#attached']['js'][] = drupal_get_path('module', 'metatag') . '/metatag.vertical-tabs.js';
$form['metatags']['#attached']['js']['vertical-tabs'] = drupal_get_path('module', 'metatag') . '/metatag.vertical-tabs.js';
break;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment