function gathercontent_import_form_content_select in GatherContent 7.3
Content select import form.
@inheritdoc
1 string reference to 'gathercontent_import_form_content_select'
- gathercontent_import_form in ./
gathercontent.import.inc - Multistep form function.
File
- ./
gathercontent.import.inc, line 179
Code
function gathercontent_import_form_content_select($form, &$form_state) {
$gathercontent_module_path = drupal_get_path('module', 'gathercontent');
$query = db_select('gathercontent_mapping', 'm')
->distinct()
->fields('m', array(
'gathercontent_project',
'gathercontent_project_id',
))
->isNotNull('data')
->execute();
$projects = $query
->fetchAllKeyed(1, 0);
$form['project_wrapper'] = array(
'#type' => 'container',
);
$form['project_wrapper']['project'] = array(
'#type' => 'select',
'#title' => t('Select project'),
'#options' => $projects,
'#required' => TRUE,
'#ajax' => array(
'callback' => 'gathercontent_import_form_content_select_fetch_content',
'wrapper' => 'edit-import',
'method' => 'replace',
'effect' => 'fade',
),
'#default_value' => isset($form_state['object']->project_id) ? $form_state['object']->project_id : 0,
'#description' => t('You can only see projects with mapped templates in the dropdown.'),
);
$form['project_wrapper']['fetch_content'] = array(
'#type' => 'button',
'#executes_submit_callback' => FALSE,
'#value' => t('Fetch contents of the selected project'),
'#name' => 'fetch_content',
'#attributes' => array(
'class' => array(
'js-hide',
),
),
);
$form['import'] = array(
'#prefix' => '<div id="edit-import">',
'#suffix' => '</div>',
'#attached' => array(
'js' => array(
$gathercontent_module_path . '/js/gathercontent-filter.js',
),
),
);
if (isset($form_state['values']['project']) || isset($form_state['object']->project_id)) {
$project_id = isset($form_state['values']['project']) ? $form_state['values']['project'] : $form_state['object']->project_id;
$content_obj = new Content();
$content = $content_obj
->getContents($project_id);
$query = new EntityFieldQuery();
$result = $query
->entityCondition('entity_type', 'gathercontent_mapping')
->propertyCondition('gathercontent_project_id', $project_id)
->execute();
if (isset($result['gathercontent_mapping'])) {
$mapping_ids = array_keys($result['gathercontent_mapping']);
$mappings = entity_load('gathercontent_mapping', $mapping_ids);
$mapping_array = array();
$content_types = [];
foreach ($mappings as $mapping) {
if (!empty($mapping->data)) {
if (!array_key_exists($mapping->gathercontent_template_id, $content_types)) {
$content_types[$mapping->gathercontent_template_id] = $mapping->content_type;
}
$mapping_array[$mapping->gathercontent_template_id] = array(
'gathercontent_template' => $mapping->gathercontent_template,
'ct' => $mapping->content_type,
);
}
}
$form['import']['content'] = array(
'#tree' => TRUE,
'#theme' => 'gathercontent_tableselect',
'#js_select' => TRUE,
'#header' => array(
'selected' => array(
'class' => array(
'select-all',
),
'data' => '',
),
'status' => t('Status'),
'title' => t('Item Name'),
'updated' => t('Last updated in GatherContent'),
'template' => t('GatherContent Template Name'),
'drupal_status' => t('Import published'),
'menu' => t('Menu'),
),
'#empty' => t('No content available.'),
'#filterwrapper' => array(
'filter_wrapper' => array(
'gathercontent-table--filter-wrapper',
'clearfix',
),
'counter_wrapper' => array(
'gathercontent-table--counter',
'clearfix',
),
),
'#filterdescription' => t('You can only see items with mapped templates in the table.'),
);
foreach ($content as $item) {
// If template is not empty, we have mapped template and item
// isn't synced yet.
if (!is_null($item->template_id) && $item->template_id != 'null' && isset($mapping_array[$item->template_id])) {
$form['import']['content'][$item->id] = array(
'#tree' => TRUE,
'selected' => array(
'#type' => 'checkbox',
'#attributes' => array(
'class' => array(
'gathercontent-select-import-items',
),
),
),
'status' => array(
'#markup' => '<div class="gathercontent-item--status--color" style="background: ' . $item->status->data->color . ';"></div>' . $item->status->data->name,
'#attributes' => array(
'class' => array(
'gathercontent-item',
'status-item',
),
),
),
'title' => array(
'#markup' => $item->name,
'#attributes' => array(
'class' => array(
'gathercontent-item',
'gathercontent-item--name',
),
),
),
'updated' => array(
'#markup' => date('F d, Y - H:i', strtotime($item->updated_at->date)),
'#attributes' => array(
'class' => array(
'gathercontent-item',
'gathercontent-item-date',
),
'data-date' => date('Y-m-d.H:i:s', strtotime($item->updated_at->date)),
),
),
'template' => array(
'#markup' => $mapping_array[$item->template_id]['gathercontent_template'],
'#attributes' => array(
'class' => array(
'template-name-item',
),
),
),
'drupal_status' => array(
'#type' => 'checkbox',
'#title' => t('Publish'),
'#title_display' => 'invisible',
'#checked' => isset($form_state['object']->drupal_status) ? $form_state['object']->drupal_status : variable_get('node_default_status', 1),
),
'menu' => array(
'#type' => 'select',
'#options' => array(
-1 => t("Parent being imported"),
) + menu_parent_options(menu_get_menus(), $mapping_array[$item->template_id]['ct']),
'#empty_option' => t("- Don't create menu item -"),
'#empty_value' => 0,
'#default_value' => variable_get('menu_parent_' . $content_types[$item->template_id], 'main-menu:0'),
'#title' => t('Menu'),
'#title_display' => 'invisible',
),
);
}
}
}
}
return $form;
}