function config_content_types in Allow a content type only once (Only One) 7
Form constructor for Only One Config Content Types form.
Parameters
array $form: The form element.
array $form_state: The form state.
1 string reference to 'config_content_types'
- onlyone_menu in ./
onlyone.module - Implements hook_menu().
File
- ./
onlyone.admin.inc, line 16 - Calls results to administration's pages for the Only One module.
Code
function config_content_types(array $form, array &$form_state) {
// Loading the helper functions file.
module_load_include('inc', 'onlyone', 'onlyone.helpers');
$available_content_types = _onlyone_available_content_types(TRUE);
$not_available_content_types = _onlyone_not_available_content_types(TRUE);
$cant_available_content_types = count($available_content_types);
if ($cant_available_content_types) {
// The fieldset of available content types.
$form['available_content_type'] = array(
'#type' => 'fieldset',
'#title' => t("Content types available to have Only One content"),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
// All the available content types.
$form['available_content_type']['onlyone_node_types'] = array(
'#type' => 'checkboxes',
'#title' => t('Configure these content types to have Only One content per language:'),
'#options' => $available_content_types,
'#default_value' => variable_get('onlyone_node_types'),
'#description' => t('The selected content types will allow Only One content per language.'),
);
}
// If all the content types are available we don't need to show the fieldset.
$cant_not_available_content_types = count($not_available_content_types);
if ($cant_not_available_content_types) {
$collapsed = $cant_available_content_types ? TRUE : FALSE;
// The fieldset of not available content types.
$form['not_available_content_type'] = array(
'#type' => 'fieldset',
'#title' => t('Content types not available to have Only One content'),
'#description' => t('Content types which have more than one content in at least one language:'),
'#collapsible' => $collapsed,
'#collapsed' => $collapsed,
);
// Showing all the not availables content types.
foreach ($not_available_content_types as $key => $value) {
$form['not_available_content_type'][$key] = array(
'#type' => 'item',
'#markup' => $value,
);
}
$form['#attached']['css'] = array(
drupal_get_path('module', 'onlyone') . '/css/onlyone.css',
);
}
if (!$cant_available_content_types && !$cant_not_available_content_types) {
$form['not_available_content_type'] = array(
'#markup' => t('There are not content types on this site, go to the <a href="@add-content-type">Add content type</a> page to create one.', array(
'@add-content-type' => url('admin/structure/types/add'),
)),
);
}
// Set a submit handler manually because the default submit handler
// gets overridden by the system_settings_form() submit handler.
$form['#submit'][] = 'config_content_types_submit';
// Show the submit button if there is availables content types.
if ($cant_available_content_types) {
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
}
return $form;
}