function opening_hours_form_node_type_form_alter in Opening hours 7
Same name and namespace in other branches
- 6 opening_hours.module \opening_hours_form_node_type_form_alter()
Implements hook_form_FORM_ID_alter().
We add our own fieldset to the node settings form, so the user can enable opening hours for a node type there.
File
- ./
opening_hours.module, line 109 - Opening hours module.
Code
function opening_hours_form_node_type_form_alter(&$form, &$form_state, $form_id) {
$form['opening_hours'] = array(
'#type' => 'fieldset',
'#title' => t('Opening hours'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'additional_settings',
'#attributes' => array(
'class' => array(
'opening-hours-node-type-settings-form',
),
),
'#attached' => array(
'js' => array(
drupal_get_path('module', 'opening_hours') . '/js/opening_hours.node-type-form.js',
),
),
);
$form['opening_hours']['opening_hours_enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Enable opening hours for this content type'),
'#default_value' => variable_get('opening_hours_enabled_' . $form['#node_type']->type, FALSE),
);
$form['opening_hours']['opening_hours_hide_on_empty'] = [
'#type' => 'checkbox',
'#title' => t('Hide opening hours widget for nodes with no opening hours data'),
'#default_value' => variable_get('opening_hours_hide_on_empty_' . $form['#node_type']->type, TRUE),
];
// If taxonomy.module is enabled, allow the user to pick a category
// vocabulary for categorization of opening hours periods.
if (function_exists('taxonomy_vocabulary_get_names')) {
// Generate a list of form API options for selecting a vocabulary.
$options = array(
t('- None -'),
);
foreach (taxonomy_vocabulary_get_names() as $vocab) {
$options[$vocab->machine_name] = $vocab->name;
}
$form['opening_hours']['opening_hours_category_vocabulary'] = array(
'#type' => 'select',
'#title' => t('Category vocabulary'),
'#description' => t('You can select a taxonomy vocabulary to act as categories for opening hours here. If enabled, you will be able to select one of the terms in that vocabulary as category when creating or editing an opening hours time interval.'),
'#options' => $options,
'#default_value' => variable_get('opening_hours_category_vocabulary_' . $form['#node_type']->type, 0),
'#states' => array(
'visible' => array(
':input[name="' . 'opening_hours_enabled' . '"]' => array(
'checked' => TRUE,
),
),
),
);
}
}