function simpleads_update_7005 in SimpleAds 7
Create a new field for Ad status. Disable comments in SimpleAds content type.
File
- ./
simpleads.updates.inc, line 538 - SimpleAds Updates.
Code
function simpleads_update_7005(&$sandbox) {
$t = get_t();
$fields = array(
array(
'field_name' => 'field_ad_status',
'type' => 'list_boolean',
'cardinality' => 1,
'translatable' => TRUE,
'settings' => array(
'allowed_values' => array(
0 => $t('This ad is inactive'),
1 => $t('This ad is active'),
),
'allowed_values_function' => '',
),
'module' => 'list',
'translatable' => TRUE,
'entity_types' => array(),
),
);
foreach ($fields as $field) {
field_create_field($field);
}
$instance = array(
'field_name' => 'field_ad_status',
'entity_type' => 'node',
'bundle' => 'simpleads',
'label' => $t('Status'),
'description' => $t('Please use this field to show or hide ads even if the ad is active and published.'),
'required' => FALSE,
'widget' => array(
'type' => 'options_onoff',
'settings' => array(
'display_label' => 0,
),
'weight' => 5,
'module' => 'options',
),
'default_value' => array(
0 => array(
'value' => 1,
),
),
'settings' => array(
'user_register_form' => FALSE,
),
'display' => array(
'default' => array(
'label' => 'above',
'type' => 'list_default',
'module' => 'list',
'settings' => array(),
),
'teaser' => array(
'label' => 'above',
'settings' => array(),
'type' => 'hidden',
'weight' => 0,
),
),
);
field_create_instance($instance);
// Set all published ads to be active.
$result = db_select('node', 'n')
->fields('n', array(
'nid',
))
->condition('n.status', 1)
->condition('n.type', 'simpleads')
->execute();
foreach ($result as $row) {
$node = node_load($row->nid);
$node->field_ad_status[$node->language][0]['value'] = 1;
node_save($node);
}
// Reset menu, comments and other default options.
variable_set('menu_options_simpleads', array());
variable_set('node_options_simpleads', array());
variable_set('comment_simpleads', 1);
}