function remove_duplicates_form_process_tableselect in Remove Duplicates 7
Process function for Remove Duplicates tableselect.
1 string reference to 'remove_duplicates_form_process_tableselect'
- remove_duplicates_element_info in ./
remove_duplicates.module - Implements hook_element_info().
File
- ./
remove_duplicates.module, line 1747 - Remove duplicate nodes according to node fields or Custom fields.
Code
function remove_duplicates_form_process_tableselect($element, $form_state, $complete_form) {
if (!empty($element['#options']) && (isset($element['#options']['#tables']) && is_array($element['#options']['#tables']) && count($element['#options']['#tables']))) {
$element['#value'] = isset($element['#value']) && is_array($element['#value']) ? $element['#value'] : array();
foreach ($element['#options']['#tables'] as &$sub_element) {
$sub_element['#tree'] = TRUE;
$value = isset($sub_element['#value']) && is_array($sub_element['#value']) ? $sub_element['#value'] : array();
$element['#value'] = array_unique(array_merge($element['#value'], $value));
if (isset($sub_element['#options']) && is_array($sub_element['#options']) && count($sub_element['#options'])) {
if (!isset($sub_element['#default_value']) || $sub_element['#default_value'] === 0) {
$sub_element['#default_value'] = array();
}
// Create a checkbox for each item in #options in such a way that the
// value of the tableselect element behaves as if it had been of type
// checkboxes.
foreach ($sub_element['#options'] as $key => $choice) {
// Do not overwrite manually created children.
if (!isset($element[$key])) {
$title = '';
if (!empty($sub_element['#options'][$key]['title']['data']['#title'])) {
$title = t('Update @title', array(
'@title' => $sub_element['#options'][$key]['title']['data']['#title'],
));
}
$checked = array();
if (isset($value[$key]) && isset($sub_element['#default_value'][$key])) {
$checked = array(
'checked' => 'checked',
);
}
$element[$key] = array(
'#type' => 'checkbox',
'#title' => $title,
'#title_display' => 'invisible',
'#return_value' => $key,
'#default_value' => !empty($checked) && isset($value[$key]) ? $key : NULL,
'#attributes' => (isset($sub_element['#attributes']) ? $sub_element['#attributes'] : array()) + $checked,
);
$element['#options'][$key] = TRUE;
if (isset($sub_element['#options'][$key]['#weight'])) {
$element[$key]['#weight'] = $sub_element['#options'][$key]['#weight'];
}
}
}
}
else {
$sub_element['#value'] = array();
}
}
}
return $element;
}