function views_slideshow_xtra_example_admin_form_submit in Views Slideshow Xtra 7.2
Same name and namespace in other branches
- 7.3 views_slideshow_xtra_example/views_slideshow_xtra_example.module \views_slideshow_xtra_example_admin_form_submit()
Admin form submit.
File
- views_slideshow_xtra_example/
views_slideshow_xtra_example.module, line 168 - This module creates a Views Slideshow Xtra content type and example slide nodes.
Code
function views_slideshow_xtra_example_admin_form_submit($form, &$form_state) {
if ($form_state['clicked_button']['#value'] == $form_state['values']['generate_nodes']) {
views_slideshow_xtra_example_nodes();
drupal_set_message(t('Example nodes generated.'));
}
if ($form_state['clicked_button']['#value'] == $form_state['values']['delete_nodes']) {
$results = db_select('node', 'n')
->fields('n', array(
'nid',
))
->condition('type', array(
'views_slideshow_xtra',
), 'IN')
->execute();
foreach ($results as $result) {
$nids[] = $result->nid;
}
if (!empty($nids)) {
foreach ($nids as $nid) {
$node = node_load($nid);
$vsx_field_values = $node->views_slideshow_xtra['und'];
$is_example_value = FALSE;
foreach ($vsx_field_values as $value) {
$json_str = $value['value'];
$vsx = drupal_json_decode($json_str);
if (!empty($vsx) && array_key_exists('vsx_example', $vsx)) {
if ($vsx['vsx_example'] = 'true') {
$is_example_value = TRUE;
}
}
}
if (!$is_example_value) {
unset($nids[array_search($nid, $nids)]);
}
}
node_delete_multiple($nids);
}
drupal_set_message(t('Deleted %count example nodes.', empty($nids) ? array(
'%count' => 0,
) : array(
'%count' => count($nids),
)));
}
}