function tripal_tripal_bundle_form
3.x TripalBundleUIController.inc | tripal_tripal_bundle_form($form, &$form_state, $entityDataType) |
Tripal content type edit form.
Parameters
$form: The default form array. Usually empty.
$form_state: Build information for the form including the entity type and submitted values.
$entityDataType: A string indicating the entity type. This will always be TripalBundle.
1 string reference to 'tripal_tripal_bundle_form'
- TripalBundleUIController::hook_forms in tripal/
includes/ TripalBundleUIController.inc - Allows us to change the forms created by the parent class.
File
- tripal/
includes/ TripalBundleUIController.inc, line 72
Code
function tripal_tripal_bundle_form($form, &$form_state, $entityDataType) {
$bundle = $form_state['build_info']['args'][0];
$term = NULL;
$vocab = NULL;
if (preg_match('/bio_data_(\d+)/', $bundle->name, $matches)) {
$term = entity_load('TripalTerm', array('id' => $matches[1]));
$term = reset($term);
$vocab = entity_load('TripalVocab', array('id' => $term->vocab_id));
$vocab = reset($vocab);
}
// Add a validate and submit handler to save the data in this form.
$form['#validate'] = array('tripal_tripal_bundle_form_validate');
$form['#submit'] = array('tripal_tripal_bundle_form_submit');
$form['#bundle'] = $bundle;
// @TODO: Move this into a css file.
$form['#attached']['css'] = array(
array(
'data' => '
th.side-header { width: 220px; }',
'type' => 'inline',
),
);
if ($term) {
$rows = array(
array(
array(
'header' => TRUE,
'data' => 'Vocabulary',
'class' => array('side-header')
),
$vocab->vocabulary
),
array(
array(
'header' => TRUE,
'data' => 'Term Name',
'class' => array('side-header')
),
$term->name
),
array(
array(
'header' => TRUE,
'data' => 'Accession',
'class' => array('side-header')
),
$term->accession
),
array(
array(
'header' => TRUE,
'data' => 'Definition',
'class' => array('side-header')
),
$term->definition
)
);
$table_vars = array(
'header' => array(),
'rows' => $rows,
'attributes' => array(),
'caption' => '',
'sticky' => FALSE,
'colgroups' => array(),
'empty' => '',
);
$form['term'] = array(
'#type' => 'item',
'#title' => t('Vocabulary Term'),
'#markup' => theme_table($table_vars)
);
}
$form['label'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#required' => TRUE,
'#description' => t('The human-readable name of this content type. This text will be
displayed as part of the list on the <em>Add new content page</em>. It is recommended that
this name begin with a capital letter and contain only letters, numbers, and spaces.
This name must be unique.'),
'#default_value' => $bundle->label,
);
$form['description'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#required' => TRUE,
'#description' => t('Describe this content type. The text will be displayed on the <em>Add new content page</em>.'),
);
if ($term) {
$form['description']['#default_value'] = tripal_get_bundle_variable('description', $bundle->id, $term->definition);
}
else {
$form['description']['#default_value'] = tripal_get_bundle_variable('description', $bundle->id, '');
}
$empty_fields = tripal_get_bundle_variable('hide_empty_field', $bundle->id, '');
$form['hide_empty_field'] = array(
'#type' => 'select',
'#title' => t('Field Display'),
'#options' => array(
'hide' => t('Hide empty fields'),
'show' => t('Show empty fields'),
),
'#description' => t('Choose either to show or hide all empty fields. If "Show empty fields" is selected then fields will be loaded via AJAX to help speed page loads.'),
'#default_value' => !empty($empty_fields) ? array($empty_fields,) : array('hide',),
);
$form['additional_settings'] = array(
'#type' => 'vertical_tabs',
'#weight' => 99,
);
// Set Title Format.
//-------------------------
$title_format = tripal_get_title_format($bundle);
$form['set_titles'] = array(
'#type' => 'fieldset',
'#title' => t('Page Title options'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#tree' => TRUE,
'#group' => 'additional_settings',
);
$form['set_titles']['explanation'] = array(
'#type' => 'item',
'#markup' => t('<p>The format below is used to determine the title displayed on %type content
pages. This ensures all content of this type is consistent while still allowing you
to indicate which data you want represented in the title (ie: which data would most
identify your content).</p>
<p>Keep in mind that it might be confusing to users if more than
one page has the same title. We recommend you <strong>choose a combination of tokens that
will uniquely identify your content</strong>.</p>',
array('%type' => $bundle->label)),
);
$form['set_titles']['title_format'] = array(
'#type' => 'textarea',
'#title' => t('Page Title Format'),
'#description' => t('You may rearrange elements in this text box to customize the page
titles. The available tokens are listed below. You can separate or include any text
between the tokens.'),
'#required' => TRUE,
'#default_value' => $title_format,
'#rows' => 1
);
$form['set_titles']['token_display'] = array(
'#type' => 'fieldset',
'#title' => t('Available Tokens'),
'#description' => t('Copy the token and paste it into the "Custom Page Title" text field above.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE
);
$tokens = tripal_get_entity_tokens($bundle);
$form['set_titles']['tokens'] = array(
'#type' => 'hidden',
'#value' => serialize($tokens)
);
$form['set_titles']['token_display']['content'] = array(
'#type' => 'item',
'#markup' => theme_token_list($tokens),
);
$form['set_titles']['bp_explanation'] = array(
'#type' => 'item',
'#markup' => t('Retroactively apply the new title pattern to
existing content by clicking the button below.',
array('%type' => $bundle->label)),
);
$form['set_titles']['bulk_update'] = array(
'#type' => 'submit',
'#value' => t('Bulk update all titles'),
//'#submit' => array('tripal_bulk_update_submit'),
);
// Set URL Alias Pattern.
//-------------------------
$url_pattern = tripal_get_bundle_variable('url_format', $bundle->id, '');
if (!$url_pattern) {
$url_pattern = str_replace(' ', '', $term->name) . '/[TripalEntity__entity_id]';
}
$form['url'] = array(
'#type' => 'fieldset',
'#title' => t('URL Path options'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#tree' => TRUE,
'#group' => 'additional_settings',
);
$form['url']['explanation'] = array(
'#type' => 'item',
'#markup' => t('<p>The pattern below is used to specify the URL of %type content pages.
This allows you to present more friendly, informative URLs to your user.</p>
<p><strong>You must choose a combination of tokens that results in a unique path for
each page!</strong></p>',
array('%type' => $bundle->label)),
);
$form['url']['url_pattern'] = array(
'#type' => 'textarea',
'#title' => t('URL Alias Pattern'),
'#description' => t('You may rearrange elements in this text box to customize the url
alias. The available tokens are listed below. <strong>Make sure the pattern forms a
valid, unique URL</strong>. Leave this field blank to use the original path.'),
'#default_value' => $url_pattern,
'#required' => TRUE,
'#rows' => 1
);
$tokens = tripal_get_entity_tokens($bundle, array('required only' => TRUE));
$form['url']['tokens'] = array(
'#type' => 'hidden',
'#value' => serialize($tokens)
);
$form['url']['token_display'] = array(
'#type' => 'fieldset',
'#title' => t('Available Tokens'),
'#description' => t('Copy the token and paste it into the "URL Alias Pattern" text field above.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE
);
$form['url']['token_display']['content'] = array(
'#type' => 'item',
'#markup' => theme_token_list($tokens),
);
$form['url']['bp_explanation'] = array(
'#type' => 'item',
'#markup' => t('Retroactively apply the new url alias pattern to
existing content by clicking the button below.',
array('%type' => $bundle->label)),
);
$form['url']['bulk_update'] = array(
'#type' => 'submit',
'#value' => t('Bulk update all aliases'),
//'#submit' => array('tripal_bulk_update_submit'),
);
// Submit Buttons
//-------------------------
$form['save'] = array(
'#type' => 'submit',
'#value' => t('Save Content Type'),
'#weight' => 100
);
$form['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete Content Type'),
'#weight' => 101
);
return $form;
}