123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <?php
- class chado_linker__prop_adder extends TripalField {
-
- public static $default_label = 'Add a Property Type';
-
- public static $default_description = 'This record may have any number of properties. Use
- this field to first add the type.';
-
-
-
-
- public static $default_settings = array(
- 'chado_table' => '',
- 'chado_column' => '',
- 'base_table' => '',
- 'semantic_web' => '',
- );
-
-
- public static $default_storage = 'field_chado_storage';
-
- public function widgetForm(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
- $widget['#type'] = 'fieldset';
- $widget['#title'] = $element['#title'];
- $widget['#description'] = $element['#description'];
- $widget['#group'] = 'entity_form_vtabs';
- $widget['kvproperty_instructions'] = array(
- '#type' => 'item',
- '#markup' => t('You may add additional properties to this form by
- providing a property name (from a vocabulary) in the field below
- and clicking the "Add Property" button. This will add a
- new field to the form above for the property you entered.
- In the future, this field will be present for all records
- of this type.'),
- );
- $widget['value'] = array(
- '#title' => t('Property Type'),
- '#type' => 'textfield',
- '#description' => t("Please enter the type of property that you want to
- add. As you type, suggestions will be provided."),
- '#autocomplete_path' => "admin/tripal/storage/chado/auto_name/cvterm/",
- );
- $widget['kvproperty_adder_link'] = array(
- '#type' => 'item',
- '#markup' => '<span class="kvproperty-adder-link">' . l('Add a term', 'admin/tripal/vocab/cvterm/add', array('attributes' => array('target' => '_blank'))) . '</span>',
- );
-
-
-
-
-
-
-
- $widget['kvproperty_adder_button'] = array(
- '#value' => t('Add Property'),
- '#type' => 'submit',
- '#name' => 'kvproperty_adder_button',
- '#limit_validation_errors' => array(array($this->field['field_name'])),
- );
- }
-
- public function widgetFormValidate($entity_type, $entity, $field, $items, &$errors) {
- }
-
- public function widgetFormSubmit($entity_type, $entity, $langcode, &$items, $form, &$form_state) {
-
- if (array_key_exists('triggering_element', $form_state) and
- $form_state['triggering_element']['#name'] == 'kvproperty_adder_button') {
- $form_state['rebuild'] = TRUE;
- $field_name = $element['#field_name'];
- $entity_type = $element['#entity']->type;
- $bundle = $element['#entity']->bundle;
-
- $field = field_info_field($field_name);
- $base_table = $field['settings']['base_table'];
-
-
- $term = chado_generate_var('cvterm', array('name' => $kvproperty), $options = array('return_array' => TRUE));
- if (count($term) == 1) {
- $prop_field_name = $field_name . '__' . $term[0]->cvterm_id;
-
-
- $schema = chado_get_schema($field_name);
- $pkey = $schema['primary key'][0];
-
- $field = field_info_field('cvterm');
- if (!$field) {
- $create_info = array(
- 'field_name' => 'property-' . $term[0]->cvterm_id,
- 'type' => 'tripal_chado_kvproperty_widget',
- 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => FALSE,
- 'storage' => array(
- 'type' => 'field_chado_storage',
- ),
- 'settings' => array(
- 'chado_table' => $field_name,
- 'chado_column' => $pkey,
- 'base_table' => $base_table,
- 'semantic_web' => '',
- ),
- );
- $field = field_create_field($create_info);
- }
-
- if (!$field and array_key_exists('bundles', $field) or
- !array_key_exists('TripalEntity', $field['bundles']) or
- !in_array($bundle_name, $field['bundles']['TripalEntity'])) {
- $createInstanceInfo = array(
- 'field_name' => 'property-' . $term[0]->cvterm_id,
- 'entity_type' => 'TripalEntity',
- 'bundle' => $this->bundle->name,
- 'label' => ucfirst(preg_replace('/_/', ' ', $term[0]->name)),
- 'description' => $term[0]->definition ? $term[0]->definition : '',
- 'required' => FALSE,
- 'settings' => array(),
- 'widget' => array(
- 'type' => 'tripal_chado_kvproperty_widget',
- 'settings' => array(
- 'display_label' => 1,
- ),
- ),
- 'display' => array(
- 'default' => array(
- 'label' => 'inline',
- 'type' => 'tripal_chado_kvproperty_formatter',
- 'settings' => array(),
- ),
- ),
- );
- $instance = field_create_instance($createInstanceInfo);
- }
- }
- else if (count($term) > 1) {
- form_set_error(implode('][', $element ['#parents']) . '][value', t("This term is present in multiple vocabularies. Please select the appropriate one."));
- }
- else {
- form_set_error(implode('][', $element ['#parents']) . '][value', t("Please provide a property type to add."));
- }
- }
- }
-
- }
|