function _features_export_form_components in Features 7.2
Adds form elements for component selection on the export form.
Parameters
array $form: Form array to add the form elements to.
array $form_state: The form state array coming from Drupal core.
1 call to _features_export_form_components()
- features_export_form in ./
features.admin.inc - Form builder for features export form.
File
- ./
features.admin.inc, line 307 - Forms for Features admin screens.
Code
function _features_export_form_components(&$form, &$form_state) {
global $features_ignore_conflicts;
drupal_add_css(drupal_get_path('module', 'features') . '/features.css');
drupal_add_js(drupal_get_path('module', 'features') . '/features.js');
$feature = $form['#feature'];
// Keep the allow_conflict variable around in the session.
if (isset($form_state['values']['features_allow_conflicts'])) {
$_SESSION['features_allow_conflicts'] = $form_state['values']['features_allow_conflicts'];
$features_ignore_conflicts = $_SESSION['features_allow_conflicts'];
}
$form['export'] = array(
'#type' => 'fieldset',
'#title' => t('Components'),
'#description' => t('Expand each component section and select which items should be included in this feature export.'),
'#tree' => FALSE,
'#prefix' => "<div id='features-export-wrapper'>",
'#suffix' => '</div>',
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#weight' => 1,
);
// Filter field used in javascript, so javascript will unhide it.
$form['export']['features_filter_wrapper'] = array(
'#type' => 'fieldset',
'#title' => t('Filters'),
'#tree' => FALSE,
'#prefix' => "<div id='features-filter' class='element-invisible'>",
'#suffix' => '</div>',
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#weight' => -10,
);
$form['export']['features_filter_wrapper']['features_filter'] = array(
'#type' => 'textfield',
'#title' => t('Search'),
'#hidden' => TRUE,
'#default_value' => '',
'#suffix' => "<span class='features-filter-clear'>" . t('Clear') . "</span>",
);
$form['export']['features_filter_wrapper']['checkall'] = array(
'#type' => 'checkbox',
'#default_value' => FALSE,
'#hidden' => TRUE,
'#title' => t('Select all'),
'#attributes' => array(
'class' => array(
'features-checkall',
),
),
);
$form['advanced']['features_autodetect_wrapper'] = array(
'#type' => 'fieldset',
'#tree' => FALSE,
'#prefix' => "<div id='features-autodetect'>",
'#suffix' => '</div>',
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form['advanced']['features_autodetect_wrapper']['autodetect'] = array(
'#title' => t('Add auto-detected dependencies'),
'#type' => 'checkbox',
'#default_value' => !empty($feature->info['no autodetect']) ? FALSE : TRUE,
);
// This refresh button will rebuild the form.
// This button is hidden by javascript, since it is only needed when
// javascript is not available.
$form['advanced']['features_autodetect_wrapper']['features_refresh'] = array(
'#type' => 'submit',
'#value' => t('Refresh'),
'#name' => 'features-refresh',
'#attributes' => array(
'title' => t("Refresh the list of auto-detected items."),
'class' => array(
'features-refresh-button',
),
),
/* @see \features_export_form_rebuild() */
'#submit' => array(
'features_export_form_rebuild',
),
'#prefix' => "<div class='features-refresh-wrapper'>",
'#suffix' => "</div>",
'#ajax' => array(
/* @see \features_export_form_ajax() */
'callback' => 'features_export_form_ajax',
'wrapper' => 'features-export-wrapper',
),
);
// Generate the export array for the current feature and user selections.
$export = _features_export_build($feature, $form_state);
$form['advanced']['features_allow_conflicts'] = array(
'#title' => t('Allow conflicts to be added'),
'#type' => 'checkbox',
'#default_value' => $features_ignore_conflicts,
'#ajax' => array(
/* @see \features_export_form_ajax() */
'callback' => 'features_export_form_ajax',
'wrapper' => 'features-export-wrapper',
),
);
if (isset($form_state['values']['op']) && $form_state['values']['op'] == $form_state['values']['info-preview']) {
// Handle clicking the "Preview .info file" button.
module_load_include('inc', 'features', 'features.export');
$feature_export = _features_export_generate($export, $form_state, $feature);
$feature_export = features_export_prepare($feature_export, $feature->name, TRUE);
$info = features_export_info($feature_export);
drupal_add_js(array(
'features' => array(
'info' => $info,
),
), 'setting');
}
// Determine any components that are deprecated.
$deprecated = features_get_deprecated($export['components']);
$sections = array(
'included',
'detected',
'added',
);
foreach ($export['components'] as $component => $component_info) {
if (!variable_get('features_admin_show_component_' . $component, TRUE)) {
continue;
}
$component_items_count = count($component_info['options']['sources']);
$count_label = ' (<span class = "component-count">' . $component_items_count . '</span>)';
$label = isset($component_info['name']) ? $component_info['name'] . $count_label . " <span>(" . check_plain($component) . ")</span>" : check_plain($component) . $count_label;
$count = 0;
foreach ($sections as $section) {
$count += count($component_info['options'][$section]);
}
$extra_class = $count == 0 ? 'features-export-empty' : '';
$component_name = str_replace('_', '-', check_plain($component));
if ($count + $component_items_count > 0) {
if (!empty($deprecated[$component])) {
// Only show deprecated component if it has some exports.
if (!empty($component_info['options']['included'])) {
$form['export'][$component] = array(
'#markup' => '',
'#tree' => TRUE,
);
$form['export'][$component]['deprecated'] = array(
'#type' => 'fieldset',
'#title' => $label . "<span class='features-conflict'> (" . t('DEPRECATED') . ")</span>",
'#tree' => TRUE,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#attributes' => array(
'class' => array(
'features-export-component',
),
),
);
$list = ' ';
foreach ($component_info['options']['included'] as $key) {
$list .= "<span class='form-type-checkbox features-conflict'>{$key}</span>";
}
$form['export'][$component]['deprecated']['selected'] = array(
'#prefix' => "<div class='component-detected'>",
'#markup' => $list,
'#suffix' => "</div>",
);
}
}
else {
$form['export'][$component] = array(
'#markup' => '',
'#tree' => TRUE,
);
$form['export'][$component]['sources'] = array(
'#type' => 'fieldset',
'#title' => $label,
'#tree' => TRUE,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#attributes' => array(
'class' => array(
'features-export-component',
),
),
'#prefix' => "<div class='features-export-parent component-{$component}'>",
);
$form['export'][$component]['sources']['selected'] = array(
'#type' => 'checkboxes',
'#id' => "edit-sources-{$component_name}",
'#options' => features_dom_encode_options($component_info['options']['sources']),
'#default_value' => features_dom_encode_options($component_info['selected']['sources'], FALSE),
'#attributes' => array(
'class' => array(
'component-select',
),
),
);
foreach ($sections as $section) {
$form['export'][$component][$section] = array(
'#type' => 'checkboxes',
'#options' => !empty($component_info['options'][$section]) ? features_dom_encode_options($component_info['options'][$section]) : array(),
'#default_value' => !empty($component_info['selected'][$section]) ? features_dom_encode_options($component_info['selected'][$section], FALSE) : array(),
'#attributes' => array(
'class' => array(
'component-' . $section,
),
),
);
}
$form['export'][$component][$sections[0]]['#prefix'] = "<div class='component-list features-export-list {$extra_class}'>";
$form['export'][$component][$sections[count($sections) - 1]]['#suffix'] = '</div></div>';
}
}
}
$form['export']['features_legend'] = array(
'#type' => 'fieldset',
'#title' => t('Legend'),
'#tree' => FALSE,
'#prefix' => "<div id='features-legend'>",
'#suffix' => '</div>',
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form['export']['features_legend']['legend'] = array(
'#markup' => "<span class='component-included'>Normal</span> " . "<span class='component-added'>Changed</span> " . "<span class='component-detected'>Auto detected</span> " . "<span class='features-conflict'>Conflict</span> ",
);
}