function entityform_type_form in Entityform 7
Same name and namespace in other branches
- 7.2 entityform_type.admin.inc \entityform_type_form()
Generates the entityform type editing form.
File
- ./
entityform_type.admin.inc, line 91 - Entityform type editing UI.
Code
function entityform_type_form($form, &$form_state, $entityform_type, $op = 'edit') {
if ($op == 'clone') {
$entityform_type->label .= ' (cloned)';
$entityform_type->type = '';
}
$form = _entityform_type_setttings_elements($entityform_type, $op);
entityform_type_prepare_edit($entityform_type);
$form['#entityform_type'] = $entityform_type;
$form['label'] = array(
'#title' => t('Name'),
'#type' => 'textfield',
'#default_value' => $entityform_type->label,
'#description' => t('The human-readable name of this Entityform Type. This text will be displayed as part of the list in the Entityform Types page. This name must be unqiue.'),
'#required' => TRUE,
'#size' => 30,
'#weight' => -50,
'#maxlength' => 255,
);
// Machine-readable type name.
$form['type'] = array(
'#type' => 'machine_name',
'#default_value' => isset($entityform_type->type) ? $entityform_type->type : '',
'#maxlength' => 32,
// '#disabled' => $entityform_type->isLocked() && $op != 'clone',
'#machine_name' => array(
'exists' => 'entityform_type_load',
'source' => array(
'label',
),
),
'#weight' => -49,
'#description' => t('A unique machine-readable name for this entityform type. It must only contain lowercase letters, numbers, and underscores.'),
);
$form['data']['#tree'] = TRUE;
$form['data']['redirect_path'] = array(
'#type' => 'textfield',
'#title' => t('Redirect path'),
'#default_value' => empty($entityform_type->data['redirect_path']) ? '' : $entityform_type->data['redirect_path'],
'#description' => t('What relative path should the user be redirected to on a correct submission? Leave blank for default action.'),
);
$form['data']['instruction_pre'] = array(
'#type' => 'text_format',
'#title' => t('Intro form instructions'),
'#default_value' => empty($entityform_type->data['instruction_pre']['value']) ? '' : $entityform_type->data['instruction_pre']['value'],
'#format' => empty($entityform_type->data['instruction_pre']['format']) ? NULL : $entityform_type->data['instruction_pre']['format'],
'#description' => t('These user instructions will appear at the top of every page within this form.'),
);
if (module_exists('menu')) {
// Menu Settings
$link = $entityform_type->menu;
$form['menu'] = array(
'#type' => 'fieldset',
'#title' => t('Menu settings'),
'#access' => user_access('administer menu'),
'#collapsible' => TRUE,
'#collapsed' => !$link['link_title'],
'#group' => 'additional_settings',
'#attached' => array(
'js' => array(
drupal_get_path('module', 'menu') . '/menu.js',
),
),
'#tree' => TRUE,
'#weight' => 80,
'#attributes' => array(
'class' => array(
'menu-link-form',
),
),
);
$form['menu']['enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Provide a menu link'),
'#default_value' => (int) (bool) $link['mlid'],
);
$form['menu']['link'] = array(
'#type' => 'container',
'#parents' => array(
'menu',
),
'#states' => array(
'invisible' => array(
'input[name="menu[enabled]"]' => array(
'checked' => FALSE,
),
),
),
);
// Populate the element with the link data.
foreach (array(
'mlid',
'module',
'hidden',
'has_children',
'customized',
'options',
'expanded',
'hidden',
) as $key) {
$form['menu']['link'][$key] = array(
'#type' => 'value',
'#value' => $link[$key],
);
}
$form['menu']['link']['link_title'] = array(
'#type' => 'textfield',
'#title' => t('Menu link title'),
'#default_value' => $link['link_title'],
);
$form['menu']['link']['description'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#default_value' => isset($link['options']['attributes']['title']) ? $link['options']['attributes']['title'] : '',
'#rows' => 1,
'#description' => t('Shown when hovering over the menu link.'),
);
$default = $link['mlid'] ? $link['menu_name'] . ':' . $link['plid'] : '';
// If the current parent menu item is not present in options, use the first
// available option as default value.
// @todo User should not be allowed to access menu link settings in such a
// case.
$options = _menu_get_options(menu_get_menus(), menu_get_menus(), $link);
if (!isset($options[$default])) {
$array = array_keys($options);
$default = reset($array);
}
$form['menu']['link']['parent'] = array(
'#type' => 'select',
'#title' => t('Parent item'),
'#default_value' => $default,
'#options' => $options,
'#attributes' => array(
'class' => array(
'menu-parent-select',
),
),
);
$form['menu']['link']['weight'] = array(
'#type' => 'weight',
'#title' => t('Weight'),
'#delta' => 50,
'#default_value' => $link['weight'],
'#description' => t('Menu links with smaller weights are displayed before links with larger weights.'),
);
}
_entityform_remove_fieldsets_from_tree($form['data'], array(
'data',
));
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save entityform type'),
'#weight' => 40,
);
if (module_exists('path')) {
$form['paths'] = array(
'#type' => 'fieldset',
'#title' => t('URL path settings'),
'#collapsible' => TRUE,
'#collapsed' => empty($path['alias']),
'#group' => 'additional_settings',
'#attributes' => array(
'class' => array(
'path-form',
),
),
'#access' => user_access('create url aliases') || user_access('administer url aliases'),
'#weight' => 100,
'#tree' => TRUE,
'#element_validate' => array(
'_entityform_paths_form_element_validate',
),
);
$path_types = _entityform_type_get_path_types($entityform_type->type);
foreach ($path_types as $key => $path_type) {
$form['paths'][$key]['alias'] = array(
'#type' => 'textfield',
'#title' => check_plain($path_type['title']),
'#default_value' => isset($entityform_type->paths[$key]) ? $entityform_type->paths[$key]['alias'] : '',
'#maxlength' => 255,
'#description' => t($path_type['description']),
);
}
$form['additional_settings'] = array(
'#type' => 'vertical_tabs',
'#weight' => 99,
);
}
if (module_exists('token')) {
$form['tokens'] = array(
'#title' => t('Available Tokens'),
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#weight' => '39',
);
$form['tokens']['token_tree'] = array(
'#theme' => 'token_tree',
'#token_types' => array(
'global_types',
'entityform_type',
'entityform',
),
'#dialog' => TRUE,
);
}
else {
$form['tokens'] = array(
'#markup' => '<p>' . t('Enable the <a href="@drupal-token">Token module</a> to view the available token browser.', array(
'@drupal-token' => 'http://drupal.org/project/token',
)) . '</p>',
);
}
return $form;
}