function responsive_preview_update_device_definition in Responsive Theme Preview 7
Adds or a updates the record for a device.
Parameters
$device: An associative array that represents the definition of a device.
$exists: (optional) A Boolean that flags whether this device already exists (TRUE), and thus should be updated, or if it is new (FALSE) and should be added.
2 calls to responsive_preview_update_device_definition()
- responsive_preview_device_add_form_submit in ./
responsive_preview.admin.inc - Form submit handler for responsive_preview_device_add_form().
- responsive_preview_device_edit_form_submit in ./
responsive_preview.admin.inc - Form submit handler for responsive_preview_device_edit_form().
File
- ./
responsive_preview.admin.inc, line 391 - Administrative page callbacks for the responsive_preview module.
Code
function responsive_preview_update_device_definition($device, $exists = FALSE) {
$transaction = db_transaction();
if ($exists) {
$query = db_update('responsive_preview');
}
else {
$query = db_insert('responsive_preview');
}
$label = trim($device['label']);
try {
$query
->fields(array(
'label' => $label,
'name' => trim($device['name']),
'width' => trim($device['dimensions']['width']),
'height' => trim($device['dimensions']['height']),
'dppx' => trim($device['dimensions']['dppx']),
'orientation' => $device['orientation'],
'status' => $device['status'],
'weight' => $device['weight'],
));
// If the device definition already exists, add a condition
if ($exists) {
$query
->condition('name', $device['name']);
}
$query
->execute();
} catch (Exception $e) {
$transaction
->rollback();
watchdog_exception('responsive_preview', $e);
throw $e;
}
if ($exists) {
drupal_set_message(t('Device %label has been updated.', array(
'%label' => $device['label'],
)));
}
else {
drupal_set_message(t('Device %label has been added.', array(
'%label' => $device['label'],
)));
}
cache_clear_all('responsive_preview', 'cache', TRUE);
}