function javascript_libraries_custom_form in JavaScript Libraries Manager 7
Form builder function for page callback.
1 string reference to 'javascript_libraries_custom_form'
- javascript_libraries_menu in ./
javascript_libraries.module - Implements hook_menu().
File
- ./
javascript_libraries.admin.inc, line 205 - Administrative management forms for JavaScript libraries.
Code
function javascript_libraries_custom_form($form, &$form_state) {
// Weights range from -delta to +delta, so delta should be at least half
// of the amount of blocks present. This makes sure all blocks in the same
// region get an unique weight.
$custom = variable_get('javascript_libraries_custom_libraries', array());
$weight_delta = max(round(count($custom) / 2), 5);
$path = drupal_get_path('module', 'javascript_libraries');
$form = array(
'#attached' => array(
'css' => array(
$path . '/css/javascript_libraries.admin.css',
),
),
);
$scope_options = array(
'header' => t('Head'),
'footer' => t('Footer'),
'disabled' => t('Disabled'),
);
$form['page_scopes'] = array(
'#type' => 'value',
// Add a last region for disabled blocks.
'#value' => $scope_options,
);
$form['libraries'] = array();
$form['#header'] = array(
'data' => array(
'data' => t('Description'),
'colspan' => 2,
),
t('Region'),
array(
'data' => t('Weight'),
'class' => array(
'library-weight',
),
),
t('Source'),
array(
'data' => t('Operations'),
'colspan' => 2,
),
);
$form['#tree'] = TRUE;
$block_settings = variable_get('javascript_libraries_block_settings', array());
foreach ($custom as $key => $library) {
$blocks = array();
// Only show block settings when relevant:
if ($library['scope'] == 'disabled') {
foreach ($block_settings as $module => $deltas) {
foreach ($deltas as $delta => $ids) {
if (in_array($key, $ids)) {
$module_blocks = module_invoke($module, 'block_info');
if (!empty($module_blocks[$delta])) {
$blocks[] = $module_blocks[$delta]['info'];
}
}
}
}
}
$form['libraries'][$key]['name'] = array(
'#markup' => check_plain($library['name']),
);
$form['libraries'][$key]['extra'] = array(
'#type' => 'item',
'#description' => $blocks ? ' ' . t('Enabled for blocks: %blocks', array(
'%blocks' => implode(', ', $blocks),
)) : '',
);
$form['libraries'][$key]['weight'] = array(
'#type' => 'weight',
'#default_value' => $library['weight'],
'#delta' => $weight_delta,
'#title_display' => 'invisible',
'#title' => t('Weight for @library', array(
'@library' => $library['name'],
)),
'#attributes' => array(
'class' => array(
'library-weight',
'library-weight-' . $library['scope'],
),
),
);
$form['libraries'][$key]['scope'] = array(
'#type' => 'select',
'#default_value' => $library['scope'],
'#title_display' => 'invisible',
'#title' => t('Region for @library', array(
'@library' => $library['name'],
)),
'#options' => $scope_options,
'#attributes' => array(
'class' => array(
'library-region-select',
'library-region-' . $library['scope'],
),
),
);
// Add brackets aroudn the disabled one.
$form['libraries'][$key]['scope']['#options']['disabled'] = '<' . $form['libraries'][$key]['scope']['#options']['disabled'] . '>';
$form['libraries'][$key]['type'] = array(
'#type' => 'markup',
'#markup' => $library['type'] == 'file' ? t('File') : t('External'),
);
$form['libraries'][$key]['edit'] = array(
'#type' => 'link',
'#title' => t('edit'),
'#href' => 'admin/config/system/javascript-libraries/custom/' . $key . '/edit',
);
$form['libraries'][$key]['delete'] = array(
'#type' => 'link',
'#title' => t('delete'),
'#href' => 'admin/config/system/javascript-libraries/custom/' . $key . '/delete',
);
}
$form['actions'] = array(
'#tree' => FALSE,
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}