123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356 |
- <?php
- class TripalBundleUIController extends EntityDefaultUIController {
- public function __construct($entity_type, $entity_info) {
- parent::__construct($entity_type, $entity_info);
- }
-
- public function hook_menu() {
- $items = parent::hook_menu();
-
- $items[$this->path]['description'] = 'Manage biological content types that are
- added using Tripal.';
-
- unset($items[$this->path . '/import']);
-
- $items[$this->path . '/add'] = array(
- 'title' => 'Add Tripal Content Type',
- 'description' => 'Add new biological content',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_entities_admin_add_type_form'),
- 'access arguments' => array('administer tripal data types'),
- 'file' => 'includes/tripal_entities.admin.inc',
- 'file path' => drupal_get_path('module', 'tripal_entities'),
- 'type' => MENU_LOCAL_ACTION,
- 'weight' => 2
- );
- return $items;
- }
-
- function hook_forms() {
- $forms = parent::hook_forms();
-
-
-
- $forms[$this->entityType . '_form'] = array(
- 'callback' => 'tripal_entities_tripal_bundle_form',
- 'callback arguments' => array($this->entityType)
- );
- return $forms;
- }
- }
- function tripal_entities_tripal_bundle_form($form, &$form_state, $entityDataType) {
- $entity_type = $form_state['build_info']['args'][0];
- if (preg_match('/bio-data_(\d+)/', $entity_type->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);
- }
-
- $form['#validate'] = array('tripal_entities_tripal_bundle_form_validate');
- $form['#submit'] = array('tripal_entities_tripal_bundle_form_submit');
-
- $form['#attached']['css'] = array(
- array(
- 'data' => '
- .form-item select, .form-item input { width:40%; }
- th.side-header { width: 220px; }',
- 'type' => 'inline',
- ),
- );
- if ($term) {
- $form['term'] = array(
- '#type' => 'markup',
- '#markup' => theme('table', array(
- 'header' => array(),
- 'rows' => array(
- array(array('header' => TRUE, 'data' => 'Vocabulary', 'class' => array('side-header')), $vocab->namespace),
- array(array('header' => TRUE, 'data' => 'Term', 'class' => array('side-header')), $term->name),
- )
- ))
- );
- }
- $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' => $entity_type->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>.'),
- '#default_value' => tripal_get_bundle_variable('description', $entity_type->id, $term->definition),
- );
- if (!$form['description']['#default_value']) {
-
- }
- $form['additional_settings'] = array(
- '#type' => 'vertical_tabs',
- '#weight' => 99,
- );
-
-
- $title_format = tripal_get_title_format($entity_type);
- $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 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>'),
- );
- $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_tokens($entity_type);
- $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['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;
- }
- function tripal_entities_tripal_bundle_form_validate($form, $form_state) {
- $tokens_available = unserialize($form_state['values']['set_titles']['tokens']);
- if (preg_match_all('/(\[\w+\])/', $form_state['values']['set_titles']['title_format'], $matches)) {
-
- $tokens_used = $matches[1];
-
- $tokens_missing = array_diff($tokens_used, array_keys($tokens_available));
- if ($tokens_missing) {
- $msg = t('You must only use tokens listed under available tokens. You used the following incorrect tokens: %tokens',
- array('%tokens' => implode(', ', $tokens_missing)));
- form_set_error('set_titles][title_format', $msg);
- }
- }
- else {
- $msg = t('You should use at least one token in your title format or the title for all %type pages will be the same.',
- array('%type' => $form_state['build_info']['args'][0]->label));
- form_set_error('set_titles][title_format', $msg);
- }
- }
- function tripal_entities_tripal_bundle_form_submit($form, &$form_state) {
- if ($form_state['triggering_element']['#value'] == 'Save Content Type') {
- $bundle_entity = $form_state['build_info']['args'][0];
-
- $bundle_entity->label = $form_state['values']['label'];
- $bundle_entity->save();
-
- tripal_bundle_save_variable('description', $bundle_entity->id, $form_state['values']['description']);
-
- tripal_save_title_format(
- $bundle_entity,
- $form_state['values']['set_titles']['title_format']
- );
- $form_state['redirect'] = 'admin/structure/bio-data';
- drupal_set_message(t('Successfully saved %type content type.', array('%type' => $form_state['build_info']['args'][0]->label)));
- }
- else {
- drupal_set_message(t('%button is not supported at this time.', array('%button' => $form_state['triggering_element']['#value'])), 'warning');
- }
- }
- function tripal_bundle_access($op, $type = NULL, $account = NULL) {
- return user_access('administer tripal data types', $account);
- }
- function tripal_entities_admin_add_type_form($form, &$form_state) {
-
-
-
- $stores = module_invoke_all('vocab_storage_info');
- if (is_array($stores) and count($stores) > 0) {
- $keys = array_keys($stores);
- $module = $stores[$keys[0]]['module'];
- $function = $module . '_vocab_select_term_form';
- if (function_exists($function)) {
- $form = $function($form, $form_state);
- }
- }
- else {
- tripal_set_message('A storage backend is not enabled for managing
- the vocabulary terms used to create content. Please enable
- a module that supports storage of vocabualary terms (e.g. tripal_chado)
- and return to create new Tripal content types.', TRIPAL_NOTICE);
- }
- return $form;
- }
- function tripal_entities_admin_add_type_form_validate($form, &$form_state) {
-
-
-
- $stores = module_invoke_all('vocab_storage_info');
- if (is_array($stores) and count($stores) > 0) {
- $keys = array_keys($stores);
- $module = $stores[$keys[0]]['module'];
- $function = $module . '_vocab_select_term_form_validate';
- if (function_exists($function)) {
- $function($form, $form_state);
- }
- }
- }
- function tripal_entities_admin_add_type_form_submit($form, &$form_state) {
- $namespace = '';
- $accession = '';
- if (array_key_exists('storage', $form_state)) {
- $storage = $form_state['storage'];
- $namespace = array_key_exists('namespace', $storage) ? $storage['namespace'] : '';
- $accession = array_key_exists('accession', $storage) ? $storage['accession'] : '';
- $term_name = array_key_exists('term_name', $storage) ? $storage['term_name'] : '';
-
-
- $term = tripal_load_term_entity($namespace, $accession);
- if (!$term) {
- $error = '';
- $success = tripal_create_bundle($namespace, $accession, $term_name, $error);
- if (!$success) {
- drupal_set_message($error, 'error');
- $form_state['redirect'] = "admin/structure/bio-data";
- }
- else {
- drupal_set_message('New biological data type created. Fields are added automatically to this type.');
- $form_state['redirect'] = "admin/structure/bio-data";
- }
- }
- else {
- drupal_set_message('This type already exists.', 'warning');
- }
- }
- }
|