function gathercontent_import_form_content_select_validate in GatherContent 7.3
Validation function for import select screen.
We are validating, if every item with "parent being imported" menu has parent in current import selection.
@inheritdoc
File
- ./
gathercontent.import.inc, line 361
Code
function gathercontent_import_form_content_select_validate($form, &$form_state) {
if ($form_state['triggering_element']['#type'] === 'submit') {
$stack = array();
$content = array_filter($form_state['values']['content']);
$import_content = [];
$menu = [];
foreach ($content as $item_id => $item) {
if ($item['selected'] === 1) {
$import_content[$item_id] = $item_id;
$menu[$item_id] = $item['menu'];
}
}
if (!empty($import_content) && !empty($menu)) {
foreach ($import_content as $k => $value) {
if (isset($menu[$value]) && $menu[$value] != -1 || !isset($menu[$value])) {
$stack[] = $value;
unset($import_content[$k]);
}
}
if (!empty($import_content)) {
// Load all by project_id.
$first = reset($import_content);
$content_obj = new Content();
$content = $content_obj
->getContent($first);
$contents_source = $content_obj
->getContents($content->project_id);
$content = array();
foreach ($contents_source as $value) {
$content[$value->id] = $value;
}
$num_of_repeats = 0;
$size = count($import_content);
while (!empty($import_content)) {
$current = reset($import_content);
if (in_array($content[$current]->parent_id, $stack)) {
$stack[] = $current;
array_shift($import_content);
}
else {
array_shift($import_content);
array_push($import_content, $current);
$num_of_repeats++;
if ($num_of_repeats >= $size * $size) {
form_set_error('form', t("Please check your menu selection, some of items don't have parent in import."));
$import_content = array();
}
}
}
}
}
}
}