Mercurial > hg > drupalISMI
diff openmindattribute/openmindattribute.module~ @ 0:124ef8f3b22d
initial
author | Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de> |
---|---|
date | Fri, 27 Mar 2015 19:21:42 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openmindattribute/openmindattribute.module~ Fri Mar 27 19:21:42 2015 +0100 @@ -0,0 +1,1535 @@ +<?php + + + +/** + * Implements hook_field_info(). + */ +function openmindattribute_field_info() { + return array( + 'openmindattribute_field' => array( + 'label' => t('Attribute'), + 'description' => t('The attribute'), + 'default_widget' => 'openmindattribute_field', + 'default_formatter' => 'openmindattribute_default', + // Support hook_entity_property_info() from contrib "Entity API". + 'property_type' => 'field_item_openmindattribute', + 'property_callbacks' => array('openmindattribute_field_property_info_callback') + ), + 'openmindattribute_fields' => array( + 'label' => t('All Attributes'), + 'description' => t('The attributes'), + 'default_widget' => 'openmindattribute_fields', + 'default_formatter' => 'openmindattribute_default', + // Support hook_entity_property_info() from contrib "Entity API". + #'property_type' => 'field_item_openmindattribute', + #'property_callbacks' => array('openmindattribute_field_property_info_callback') + ), + 'openmindattribute_field' => array( + 'label' => t('Attribute'), + 'description' => t('The attribute'), + 'default_widget' => 'openmindattribute_field', + 'default_formatter' => 'openmindattribute_default', + // Support hook_entity_property_info() from contrib "Entity API". + 'property_type' => 'field_item_openmindattribute', + 'property_callbacks' => array('openmindattribute_field_property_info_callback') + ), + + ); +} + +/** + * Implements hook_field_instance_settings_form(). + */ +function openmindattribute_field_instance_settings_form($field, $instance) { + + if ($field['type'] == 'openmindattribute_fields'){ // nur ausgabe feld! + $form['name'] = array( + '#type' => 'textfield', + '#title' => t('Name'), + '#default_value' => isset($instance['settings']['name']) ? $instance['settings']['name'] : '', + '#description' => t('This title will always be used if “Static Title” is selected above.'), + ); + return $form; + } + $form = array( + '#element_validate' => array('openmindattribute_field_settings_form_validate'), + ); + + + + $form['name'] = array( + '#type' => 'textfield', + '#title' => t('Name'), + '#default_value' => isset($instance['settings']['name']) ? $instance['settings']['name'] : '', + '#description' => t('This title will always be used if “Static Title” is selected above.'), + ); + + + + + + $form['ov'] = array( + '#type' => 'textfield', + '#title' => t('Ov'), + '#description' => t('Value'), + #'#default_value' => empty($instance['settings']['attributes']['rel']) ? '' : $instance['settings']['attributes']['rel'], + #'#field_prefix' => 'rel = "', + #'#field_suffix' => '"', + '#size' => 100, + ); + + $form['nov'] = array( + '#type' => 'textfield', + '#title' => t('Nov'), + '#description' => t('Normalised Value'), + #'#default_value' => empty($instance['settings']['attributes']['rel']) ? '' : $instance['settings']['attributes']['rel'], + #'#field_prefix' => 'rel = "', + #'#field_suffix' => '"', + '#size' => 100, + ); + + $form['romanization'] = array( + '#type' => 'textfield', + '#title' => t('Romanization'), + '#description' => t('Normalised Value (LOC)'), + #'#default_value' => empty($instance['settings']['attributes']['rel']) ? '' : $instance['settings']['attributes']['rel'], + #'#field_prefix' => 'rel = "', + #'#field_suffix' => '"', + '#size' => 100, + ); + + + return $form; +} + +/** + * #element_validate handler for openmindattribute_field_instance_settings_form(). + */ +function openmindattribute_field_settings_form_validate($element, &$form_state, $complete_form) { + return true; +} + +/** + * Implements hook_field_is_empty(). + */ +function openmindattribute_field_is_empty($item, $field) { + return false; +} + +#/** +# * Implements hook_field_load(). +# */ +#function link_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) { +# foreach ($entities as $id => $entity) { +# foreach ($items[$id] as $delta => $item) { +# $items[$id][$delta]['attributes'] = _link_load($field, $item, $instances[$id]); +# } +# } +#} + +/** + * Implements hook_field_validate(). + */ +function openmindattribute_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) { + return true; +} + + + +/** + * Implements hook_field_insert(). + */ +function openmindattribute_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) { + foreach ($items as $delta => $value) { + _openmindattribute_process($items[$delta], $delta, $field, $entity); + } +} + +/** + * Implements hook_field_update(). + */ +function openmindattribute_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) { + foreach ($items as $delta => $value) { + _openmindattribute_process($items[$delta], $delta, $field, $entity); + } +} + +#/** +# * Implements hook_field_prepare_view(). +#*/ +#function openmindattribute_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) { +# foreach ($items as $entity_id => $entity_items) { +# foreach ($entity_items as $delta => $value) { +# _link_sanitize($items[$entity_id][$delta], $delta, $field, $instances[$entity_id], $entities[$entity_id]); +# } +# } +#} + +/** + * Implements hook_field_widget_info(). + */ +function openmindattribute_field_widget_info() { + return array( + 'openmindattribute_field' => array( + 'label' => 'Attribute', + 'field types' => array('openmindattribute_field'), + 'multiple values' => FIELD_BEHAVIOR_DEFAULT, + ), + 'openmindattribute_fields' => array( + 'label' => 'NOTHING', + 'field types' => array('openmindattribute_fields'), + 'multiple values' => FIELD_BEHAVIOR_NONE + ), + ); +} + +/** + * Implements hook_field_widget_form(). + */ +function openmindattribute_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) { + + + if ($field['type'] == 'openmindattribute_fields'){ // nur ausgabe feld! + return $element; + } + $element += array( + '#type' => $instance['widget']['type'], + '#default_value' => isset($items[$delta]) ? $items[$delta] : '', + ); + return $element; +} + +#/** +# * Implements hook_field_widget_error(). +# */ +#function link_field_widget_error($element, $error, $form, &$form_state) { +# if ($error['error_element']['title']) { +# form_error($element['title'], $error['message']); +# } +# elseif ($error['error_element']['url']) { +# form_error($element['url'], $error['message']); +# } +#} + + +/** + * Prepares the item attributes and url for storage. + */ +function _openmindattribute_process(&$item, $delta = 0, $field, $entity) { + // Trim whitespace from URL. + $item['name'] = trim($item['name']); +} + + + + +/** + * Implements hook_theme(). + */ +function openmindattribute_theme() { + return array( + 'openmindattribute_formatter_default' => array( + 'variables' => array('element' => NULL, 'field' => NULL, 'entity' => NULL), + ), + 'openmindattribute_formatter_fields_default' => array( + 'variables' => array('type' => NULL, 'attributes' => NULL), + ), + 'openmindattribute_formatter_fields_specialized' => array( + 'variables' => array('type' => NULL, 'attributes' => NULL), + ), + 'openmindattribute_formatter_field_identifier' => array( + 'variables' => array('type' => NULL, 'attributes' => NULL), + ), + + 'openmindattribute_formatter_field_full_title' => array( + 'variables' => array('type' => NULL, 'attributes' => NULL), + ), + + + 'openmindattribute_formatter_field_full_title_translit_romanization' => array( + 'variables' => array('type' => NULL, 'attributes' => NULL), + ), + + + 'openmindattribute_formatter_field_name_translit_romanization' => array( + 'variables' => array('type' => NULL, 'attributes' => NULL), + ), + + 'openmindattribute_formatter_field_name' => array( + 'variables' => array('type' => NULL, 'attributes' => NULL, 'nid' => NULL), + ), + + 'openmindattribute_formatter_field_ahlwardt' => array( + 'variables' => array('type' => NULL, 'attributes' => NULL), + ), + + 'openmindattribute_formatter_fields_diva_link' => array( + 'variables' => array('type' => NULL,'entid' => NULL) + ), + + 'openmindattribute_formatter_field_MPIWG_viewer' => array( + 'variables' => array('type' => NULL, 'attributes' => NULL), + ), + 'openmindattribute_item_thumbnail' => array( + 'variables' => array('objid' => NULL,'entid' => NULL,'objdata'=>NULL,'type'=>NULL), + + ), + + + 'openmindattribute_reference_format' => array ( + 'variables' => array('type' => NULL,'entid' => NULL, 'attributes' => NULL, 'ov' => NULL, 'nid' => NULL ), + + ), + + + + + + ); +} + +function theme_openmindattribute_item_thumbnail($vars) { + + $vars['objdata'] = digitalobjects_readMetadata($vars['objid']); + + return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute-item-thumbnail.tpl.php", $vars); + +} + + +function theme_openmindattribute_reference_format($vars){ + + return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute_reference_format.tpl.php", $vars); + +} + +/** + * Formats a link field widget. + */ +function theme_openmindattribute_field($vars) { + drupal_add_css(drupal_get_path('module', 'openmindattribute') . '/openmindattribute.css'); + $element = $vars['element']; + // Prefix single value link fields with the name of the field. + + + $output = ''; + $output .= '<div class="openmindattribute-field-subrow clearfix">'; + $output = $output . $element['name']; + $output = $output . $element['ov']; + $output = $output . $element['nov']; + $output = $output . $element['romanization']; + + return $output; +} + +/** + * Implements hook_element_info(). + */ +function openmindattribute_element_info() { + $elements = array(); + $elements['openmindattribute_field'] = array( + '#input' => TRUE, + '#process' => array('openmindattribute_field_process'), + '#theme' => 'openmindattribute_field', + '#theme_wrappers' => array('form_element'), + ); + return $elements; +} + + + +/** + * Processes the link type element before displaying the field. + * + * Build the form element. When creating a form using FAPI #process, + * note that $element['#value'] is already set. + * + * The $fields array is in $complete_form['#field_info'][$element['#field_name']]. + */ +function openmindattribute_field_process($element, $form_state, $complete_form) { + + $instance = field_widget_instance($element, $form_state); + + $settings = $instance['settings']; + $element['name'] = array( + '#type' => 'textfield', + '#maxlength' => 1000, + '#title' => t('name'), + '#required' => FALSE, + '#default_value' => isset($element['#value']['name']) ? $element['#value']['name'] : NULL, + ); + + $element['ov'] = array( + '#type' => 'textfield', + '#maxlength' => 1000, + '#title' => t('ov'), + '#required' => FALSE, + '#default_value' => isset($element['#value']['ov']) ? $element['#value']['ov'] : NULL, + ); + + $element['nov'] = array( + '#type' => 'textfield', + '#maxlength' => 1000, + '#title' => t('nov'), + '#required' => FALSE, + '#default_value' => isset($element['#value']['nov']) ? $element['#value']['nov'] : NULL, + ); + + $element['romanization'] = array( + '#type' => 'textfield', + '#maxlength' => 1000, + '#title' => t('romanization'), + '#required' => FALSE, + '#default_value' => isset($element['#value']['romanization']) ? $element['#value']['romanization'] : NULL, + ); + + + + return $element; +} + +/** + * Implements hook_field_formatter_info(). + */ +function openmindattribute_field_formatter_info() { + return array( + + + 'openmindattribute_reference_format' => array( + 'label' => t('Formats a title field with the field selected, depending on the value of oc'), + 'field types' => array('text'), + 'multiple values' => FIELD_BEHAVIOR_DEFAULT, + ), + + 'openmindattribute_default' => array( + 'label' => t('Attribute as default'), + 'field types' => array('openmindattribute_field'), + 'multiple values' => FIELD_BEHAVIOR_DEFAULT, + ), + 'openmindattribute_fields_default' => array( + 'label' => t('All Attribute as default'), + 'field types' => array('openmindattribute_fields'), + 'multiple values' => FIELD_BEHAVIOR_DEFAULT, + ), + 'openmindattribute_fields_specialized' => array( + 'label' => t('All Attribute as specialized'), + 'field types' => array('openmindattribute_fields'), + 'multiple values' => FIELD_BEHAVIOR_DEFAULT, + ), + 'openmindattribute_fields_diva_link' => array( + 'label' => t('DIVA-openmind-view'), + 'field types' => array('text'), + 'multiple values' => FIELD_BEHAVIOR_DEFAULT, + ), + 'openmindattribute_field_identifier' => array( + 'label' => t('Only the attribute identifer'), + 'field types' => array('openmindattribute_fields'), + 'multiple values' => FIELD_BEHAVIOR_DEFAULT, + ), + + 'openmindattribute_field_full_title' => array( + 'label' => t('Only the attribute full_title'), + 'field types' => array('openmindattribute_fields'), + 'multiple values' => FIELD_BEHAVIOR_DEFAULT, + ), + + 'openmindattribute_field_full_title_translit_romanization' => array( + 'label' => t('Only the attribute full_title_translit_romanization'), + 'field types' => array('openmindattribute_fields'), + 'multiple values' => FIELD_BEHAVIOR_DEFAULT, + ), + + 'openmindattribute_field_name_translit_romanization' => array( + 'label' => t('Only the attribute name_translit_romanization'), + 'field types' => array('openmindattribute_fields'), + 'multiple values' => FIELD_BEHAVIOR_DEFAULT, + ), + + 'openmindattribute_field_ahlwardt' => array( + 'label' => t('Only the attribute ahlwardt'), + 'field types' => array('openmindattribute_fields'), + 'multiple values' => FIELD_BEHAVIOR_DEFAULT, + ), + + 'openmindattribute_field_name' => array( + 'label' => t('Only the attribute name'), + 'field types' => array('openmindattribute_fields'), + 'multiple values' => FIELD_BEHAVIOR_DEFAULT, + ), + + + + 'openmindattribute_field_MPIWG_viewer' => array( + 'label' => t('MPIWG Image viewer'), + 'field types' => array('openmindattribute_fields'), + 'multiple values' => FIELD_BEHAVIOR_DEFAULT, + ), + 'openmindattribute_field_MPIWG_viewer_for_view' => array( + 'label' => t('MPIWG Image viewer (for use in views)'), + 'field types' => array('openmindattribute_fields'), + 'multiple values' => FIELD_BEHAVIOR_DEFAULT, + ), + + + ); +} + +#/** +# * Implements hook_field_formatter_settings_form(). +# */ +#function openmindattribute_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) { +# $display = $instance['display'][$view_mode]; +# $settings = $display['settings']; +# $element = array(); +# if ($display['type'] == 'link_domain') { +# $element['strip_www'] = array( +# '#title' => t('Strip www. from domain'), +# '#type' => 'checkbox', +# '#default_value' => $settings['strip_www'], +# ); +## } +# return $element; +#} + +#/** +# * Implements hook_field_formatter_settings_summary(). +# */ +#function link_field_formatter_settings_summary($field, $instance, $view_mode) { +# $display = $instance['display'][$view_mode]; +# $settings = $display['settings']; +# if ($display['type'] == 'link_domain') { +# if ($display['settings']['strip_www']) { +# return t('Strip www. from domain'); +# } +## else { +# return t('Leave www. in domain'); +# } +# } +# return ''; +#} + + +function _openmindattribute_field_remap($atts){ + //erzeuge eine array mit name -> (ov, nov,name) + $retmap = array(); + foreach ($atts as $a){ + $retmap[$a['name']]=$a; + } + return $retmap; +} + + + + + +/** + * Implements hook_field_formatter_view(). + */ +function openmindattribute_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { + + + #openmindattribute_fields ist nur experimentell, TODO: insbesondere field_oc, field_attribute sollte nicht hardcoded vorliegen. + + $elements= array(); + + if ($field['type'] == 'text'){ // nur ausgabe feld! + + + + switch($display['type']){ + + + case ("openmindattribute_fields_diva_link"): + + foreach ($items as $delta => $item) { + $entid = $entity->field_id['und'][0]['value']; + + $ocid = $entity->field_oc['und'][0]['tid']; + + $term = taxonomy_term_load($ocid); + + + $elements[$delta] = array( + '#theme' => 'openmindattribute_formatter_fields_diva_link', + '#entid' => $entid, + '#type' => $term->name + + ); + } + + return $elements; + + + break; + + case ("openmindattribute_reference_format"): + + foreach ($items as $delta => $item) { + $entid = $entity->field_id['und'][0]['value']; + + $ocid = $entity->field_oc['und'][0]['tid']; + + $term = taxonomy_term_load($ocid); + + + $atts = $entity->field_attribute['und']; + + $atts_mapped = _openmindattribute_field_remap($atts); + + + + + + $elements[$delta] = array( + '#theme' => 'openmindattribute_reference_format', + '#entid' => $entid, + '#type' => $term->name, + '#attributes' => $atts_mapped, + '#ov' =>$entity->field_ov['und'][0]['value'], + '#nid' => $entity->nid + + + ); + } + + return $elements; + } + + + + + + + } + + + if ($field['type'] == 'openmindattribute_fields'){ // nur ausgabe feld! + + switch($display['type']){ + + + case ("openmindattribute_fields_specialized"): + + + $ocid = $entity->field_oc['und'][0]['tid']; + + $term = taxonomy_term_load($ocid); + + + $atts = $entity->field_attribute['und']; + + $atts_mapped = _openmindattribute_field_remap($atts); + + + $elements = array( + '#theme' => 'openmindattribute_formatter_fields_specialized', + '#attributes' => $atts_mapped, + '#type' => $term->name + ); + + break; + + case ("openmindattribute_fields_default"): + + + $ocid = $entity->field_oc['und'][0]['tid']; + + $term = taxonomy_term_load($ocid); + + + + $elements = array( + '#theme' => 'openmindattribute_formatter_fields_default', + '#attributes' => $entity->field_attribute['und'], + '#type' => $term->name + ); + + break; + + // show only the identifier TODO only preliminary should define a formatter where you can configure the field + + + case ("openmindattribute_field_identifier"): + + //foreach ($items as $delta => $item) { + $ocid = $entity->field_oc['und'][0]['tid']; + + $term = taxonomy_term_load($ocid); + + + $atts = $entity->field_attribute['und']; + + $atts_mapped = _openmindattribute_field_remap($atts); + + + $output = array( + '#theme' => 'openmindattribute_formatter_field_identifier', + '#attributes' => $atts_mapped, + '#type' => $term->name, + ); + + $elements[] = $output; + + //} + + + //$elements[$delta] = array ('#markup' => render($element_tmp)); + //} + break; + + case ("openmindattribute_field_full_title"): + + //foreach ($items as $delta => $item) { + $ocid = $entity->field_oc['und'][0]['tid']; + + $term = taxonomy_term_load($ocid); + + + $atts = $entity->field_attribute['und']; + + $atts_mapped = _openmindattribute_field_remap($atts); + + + $output = array( + '#theme' => 'openmindattribute_formatter_field_full_title', + '#attributes' => $atts_mapped, + '#type' => $term->name, + ); + + $elements[] = $output; + + //} + + + //$elements[$delta] = array ('#markup' => render($element_tmp)); + //} + break; + + + case ("openmindattribute_field_full_title_translit_romanization"): + + //foreach ($items as $delta => $item) { + $ocid = $entity->field_oc['und'][0]['tid']; + + $term = taxonomy_term_load($ocid); + + + $atts = $entity->field_attribute['und']; + + $atts_mapped = _openmindattribute_field_remap($atts); + + + $output = array( + '#theme' => 'openmindattribute_formatter_field_full_title_translit_romanization', + '#attributes' => $atts_mapped, + '#type' => $term->name, + ); + + $elements[] = $output; + + //} + + + //$elements[$delta] = array ('#markup' => render($element_tmp)); + //} + break; + + + case ("openmindattribute_field_name_translit_romanization"): + + //foreach ($items as $delta => $item) { + $ocid = $entity->field_oc['und'][0]['tid']; + + $term = taxonomy_term_load($ocid); + + + $atts = $entity->field_attribute['und']; + + $atts_mapped = _openmindattribute_field_remap($atts); + + + $output = array( + '#theme' => 'openmindattribute_formatter_field_name_translit_romanization', + '#attributes' => $atts_mapped, + '#type' => $term->name, + ); + + $elements[] = $output; + + //} + + + //$elements[$delta] = array ('#markup' => render($element_tmp)); + //} + break; + case ("openmindattribute_field_name"): + + //foreach ($items as $delta => $item) { + $ocid = $entity->field_oc['und'][0]['tid']; + + $term = taxonomy_term_load($ocid); + + + $atts = $entity->field_attribute['und']; + + $atts_mapped = _openmindattribute_field_remap($atts); + + + $nid = $entity->nid; + + $output = array( + '#theme' => 'openmindattribute_formatter_field_name', + '#attributes' => $atts_mapped, + '#type' => $term->name, + '#nid' => $nid + ); + + $elements[] = $output; + + //} + + + //$elements[$delta] = array ('#markup' => render($element_tmp)); + //} + break; + + + case ("openmindattribute_field_ahlwardt"): + + //foreach ($items as $delta => $item) { + $ocid = $entity->field_oc['und'][0]['tid']; + + $term = taxonomy_term_load($ocid); + + + $atts = $entity->field_attribute['und']; + + $atts_mapped = _openmindattribute_field_remap($atts); + + + $output = array( + '#theme' => 'openmindattribute_formatter_field_ahlwardt', + '#attributes' => $atts_mapped, + '#type' => $term->name, + ); + + $elements[] = $output; + + //} + + + //$elements[$delta] = array ('#markup' => render($element_tmp)); + //} + break; + + case ("openmindattribute_field_MPIWG_viewer"): + + + $ocid = $entity->field_oc['und'][0]['tid']; + + $term = taxonomy_term_load($ocid); + + + $atts = $entity->field_attribute['und']; + + $atts_mapped = _openmindattribute_field_remap($atts); + + + if (isset($atts_mapped['mpiwg_id']['ov'])){ + + $elements = array( + '#theme' => 'digitalobjects_item_thumbnail', + '#objid' => strtoupper($atts_mapped['mpiwg_id']['ov']), + + + + ); + + + } + + break; + + case ("openmindattribute_field_MPIWG_viewer_for_view"): + + + + + + + $ocid = $entity->field_oc['und'][0]['tid']; + + $term = taxonomy_term_load($ocid); + + + $atts = $entity->field_attribute['und']; + + $atts_mapped = _openmindattribute_field_remap($atts); + + $entid = $entity->field_id['und'][0]['value']; + + if (isset($atts_mapped['mpiwg_id']['ov'])){ + + $elements[] = array( + '#theme' => 'openmindattribute_item_thumbnail', + '#objid' => strtoupper($atts_mapped['mpiwg_id']['ov']), + '#entid' => $entid, + '#type' => $term->name, + + + + ); + + + } + + break; + + + } + + + return $elements; + } else { + + + $elements = array(); + + + foreach ($items as $delta => $item) { + $elements[$delta] = array( + '#theme' => 'openmindattribute_formatter_default', + '#element' => $item, + '#field' => $instance, + '#display' => $display, + '#entity' => $entity + ); + } + return $elements; + } +} + +/** + * Formats a link. + */ +function theme_openmindattribute_formatter_default($vars) { + + + $entity = $vars['type']; + + + $ocid = $entity->field_oc['und'][0]['tid']; + + + $term = taxonomy_term_load($ocid); + + + + return $vars['element']['name'] . $vars['element']['ov'] . $vars['element']['nov'] . $vars['element']['romanization']; + +} + +function theme_openmindattribute_formatter_fields_specialized($vars) { + + $type = $vars['type']; + + + return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute_" . $type . ".tpl.php", $vars); + + + + + + +} + + + +function theme_openmindattribute_formatter_field_identifier($vars) { + + $type = $vars['type']; + + + return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute_identifier.tpl.php", $vars); + + + + +} + + +function theme_openmindattribute_formatter_field_full_title($vars) { + + $type = $vars['type']; + + + return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute_full_title.tpl.php", $vars); + + + + +} + + + +function theme_openmindattribute_formatter_field_full_title_translit_romanization($vars) { + + $type = $vars['type']; + + + return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute_full_title_translit_romanization.tpl.php", $vars); + + + + +} + +function theme_openmindattribute_formatter_field_name_translit_romanization($vars) { + + $type = $vars['type']; + + + return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute_name_translit_romanization.tpl.php", $vars); + + + + +} + + + +function theme_openmindattribute_formatter_field_name($vars) { + + $type = $vars['type']; + + + return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute_name.tpl.php", $vars); + + + + +} + + + +function theme_openmindattribute_formatter_field_ahlwardt($vars) { + + $type = $vars['type']; + + + return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute_ahlwardt.tpl.php", $vars); + + + + +} + +function theme_openmindattribute_formatter_field_MPIWG_viewer($vars) { + + $type = $vars['type']; + + + return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute_MPIWG_viewer.tpl.php", $vars); + + +} + + +function theme_openmindattribute_formatter_fields_default($vars) { + + + + return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute_default.tpl.php", $vars); + + + + + +} + +function theme_openmindattribute_formatter_fields_diva_link($vars) { + + + return theme_render_template(drupal_get_path('module', 'openmindattribute') . "/templates/openmindattribute_diva_link.tpl.php", $vars); + +} + + +/** + * Implements hook_views_api(). + */ +function openmindattribute_views_api() { + return array( + 'api' => 2, + 'path' => drupal_get_path('module', 'openmindattribute') . '/views', + ); +} + +/** + * Implements hook_field_settings_form(). + */ +function openmindattribute_field_settings_form() { + return array(); +} + +/** + * Additional callback to adapt the property info of link fields. + * + * @see entity_metadata_field_entity_property_info(). + */ +function openmindattribute_field_property_info_callback(&$info, $entity_type, $field, $instance, $field_type) { + $property = &$info[$entity_type]['bundles'][$instance['bundle']]['properties'][$field['field_name']]; + // Define a data structure so it's possible to deal with both the link title + // and URL. + $property['getter callback'] = 'entity_metadata_field_verbatim_get'; + $property['setter callback'] = 'entity_metadata_field_verbatim_set'; + + // Auto-create the field item as soon as a property is set. + $property['auto creation'] = 'openmindattribute_field_item_create'; + + $property['property info'] = openmindattribute_field_item_property_info(); + $property['property info']['name']['required'] = !$instance['settings']['name']; + $property['property info']['ov']['required'] = ($instance['settings']['ov'] == 'required'); + if ($instance['settings']['ov'] == 'none') { + unset($property['property info']['ov']); + } + + $property['property info']['nov']['required'] = ($instance['settings']['nov'] == 'required'); + if ($instance['settings']['nov'] == 'none') { + unset($property['property info']['nov']); + } + unset($property['query callback']); +} + +/** + * Callback for creating a new, empty link field item. + * + * @see link_field_property_info_callback() + */ +function openmindattribute_field_item_create() { + return array('title' => NULL, 'url' => NULL); +} + +/** + * Defines info for the properties of the link-field item data structure. + */ +function openmindattribute_field_item_property_info() { + $properties['ov'] = array( + 'type' => 'text', + 'label' => t('The OV.'), + 'setter callback' => 'entity_property_verbatim_set', + ); + $properties['name'] = array( + 'type' => 'text', + 'label' => t('The name of the attribute'), + 'setter callback' => 'entity_property_verbatim_set', + ); + + $properties['nov'] = array( + 'type' => 'text', + 'label' => t('The NOV'), + 'setter callback' => 'entity_property_verbatim_set', + ); + return $properties; +} + +#/** +# * Implements hook_field_update_instance(). +# */ +#function openmindattribute_field_update_instance($instance, $prior_instance) { +# if (function_exists('i18n_string_update') && $instance['widget']['type'] == 'openmindattribute_field' ) { +# $i18n_string_name = "field:{$instance['field_name']}:{$instance['bundle']}:title_value"; +# i18n_string_update($i18n_string_name, $instance['settings']['title_value']); +# } +#} + +/** + * Implements hook_i18n_string_list_TEXTGROUP_alter(). + */ +#function link_i18n_string_list_field_alter(&$strings, $type = NULL, $object = NULL) { +# if ($type != 'field_instance' || !is_array($object) || !isset($object['widget']['type'])) { +# return; +# } +# if ($object['widget']['type'] == 'link_field' && isset($object['settings']['title_value'])) { +## $strings['field'][$object['field_name']][$object['bundle']]['title_value']['string'] = $object['settings']['title_value']; +#} +#} + + +/** + * @file + * implementation of Feeds mapping API for link.module. + */ + +/** + * Implements hook_feeds_processor_targets_alter(). + * + * @see FeedsProcessor::getMappingTargets() + */ +/* + function openmindattribute_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) { + + foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) { + $info = field_info_field($name); + + if ($info['type'] == 'openmindattribute_field') { + if (array_key_exists('name', $info['columns'])) { + $targets[$name . ':name'] = array( + 'name' => t('@name: name', array('@name' => $instance['label'])), + 'callback' => 'openmindattribute_feeds_set_target', + 'description' => t('The @label field of the entity.', array('@label' => $instance['label'])), + 'real_target' => $name, + ); + } + if (array_key_exists('ov', $info['columns'])) { + $targets[$name . ':ov'] = array( + 'name' => t('@name: OV', array('@name' => $instance['label'])), + 'callback' => 'openmindattribute_feeds_set_target', + 'description' => t('The @label field of the entity.', array('@label' => $instance['label'])), + 'real_target' => $name, + ); + } + if (array_key_exists('ov', $info['columns'])) { + $targets[$name . ':nov'] = array( + 'name' => t('@name: NOV', array('@name' => $instance['label'])), + 'callback' => 'openmindattribute_feeds_set_target', + 'description' => t('The @label field of the entity.', array('@label' => $instance['label'])), + 'real_target' => $name, + ); + } + } + } + } + */ + +function openmindattribute_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) { + + foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) { + $info = field_info_field($name); + #map the whole attr + + if ($info['type'] == 'openmindattribute_field') { + $targets[$name] = array( + 'name' => t('@name', array('@name' => $instance['label'])), + 'callback' => 'openmindattribute_feeds_set_target', + 'description' => t('The @label field of the entity.', array('@label' => $instance['label'])), + 'real_target' => $name, + ); + } + + + } +} + + + +/** + * Callback for mapping. Here is where the actual mapping happens. + * + * When the callback is invoked, $target contains the name of the field the + * user has decided to map to and $value contains the value of the feed item + * element the user has picked as a source. + */ +/* + function openmindattribute_feeds_set_target($source, $entity, $target, $value) { +if (empty($value)) { +return; +} + +// Handle non-multiple value fields. +if (!is_array($value)) { +$value = array($value); +} + +// Iterate over all values. +list($field_name, $column) = explode(':', $target); +$info = field_info_field($field_name); + +$field = isset($entity->$field_name) ? $entity->$field_name : array(); +$delta = 0; + +foreach ($value as $v) { +if ($info['cardinality'] == $delta) { +break; +} + +if (is_object($v) && ($v instanceof FeedsElement)) { +$v = $v->getValue(); +} + +if (is_scalar($v)) { +$field['und'][$delta][$column] = $v; +$delta++; +} +} +$entity->$field_name = $field; +} +*/ + +function openmindattribute_feeds_set_target($source, $entity, $target, $value) { + + if (empty($value)) { + return; + } + + // Handle non-multiple value fields. + if (!is_array($value)) { + $value = array($value); + } + + // Iterate over all values. + #list($field_name, $column) = explode(':', $target); + + $field_name=$target; + $info = field_info_field($field_name); + + $field = isset($entity->$field_name) ? $entity->$field_name : array(); + $delta = 0; + + + foreach ($value as $v) { + + + if ($info['cardinality'] == $delta) { + break; + } + + if (is_object($v) && ($v instanceof FeedsElement)) { + $v = $v->getValue(); + } + + if (is_scalar($v)) { + $field['und'][$delta] = $v; + $delta++; + } + + if (is_array($v)){ + $newVal = array(); + $newVal['ov'] = $v['ov']; + $newVal['nov'] = $v['nov']; + $newVal['name'] = $v['name']; + $newVal['romanization'] = $v['romanization']; + $field['und'][$delta]= $newVal; + $delta++; + + } + } + $entity->$field_name = $field; +} + + +function openmindattribute_addIDs(){ + #adds the author id from openmind to the biographies and umgekehrt + $query = new EntityFieldQuery(); + + $query->entityCondition('entity_type', 'node') + ->entityCondition('bundle', 'openmind_entity') + ->propertyCondition('status', 1) + ->fieldCondition('field_oc', 'tid', '1', '='); #1 is PERSON #TODO should search for PERSON and not the id + + $result = $query->execute(); + + + if (isset($result['node'])) { + $persons_nids = array_keys($result['node']); + $persons = entity_load('node', $persons_nids); + + + } + + #hole mapping bea url -> id + + $beamapping=array(); + $beamappingNodeId=array(); + foreach ($persons as $person){ + + $attrs = $person->field_attribute['und']; + + + $mappedattrs = _openmindattribute_field_remap($attrs); + + if (isset($mappedattrs['url'])){ + + $url = $mappedattrs['url']['ov']; + + $exploded = explode("/", $url); + + #urls haben die Form http://islamsci.mcgill.ca/rasi/bea/tusi_bea.htm + #mich interessiert nur das ende ohne htm + + dpm($exploded); + $ident = $exploded[count($exploded)-1]; + dpm($ident); + $ident = strtolower(str_replace(".htm", "", $ident)); + + dpm($ident); + $beamapping[$ident]=$person->field_id['und'][0]['value']; + //$beamappingNodeId[$ident]=$person->nid; + $beamappingNodeId[$ident][]=$person->nid; + } + + } + + #hole jetzt alle biographien + + $query = new EntityFieldQuery(); + + $query->entityCondition('entity_type', 'node') + ->entityCondition('bundle', 'biography'); + + + $result = $query->execute(); + + + if (isset($result['node'])) { + $bios_nids = array_keys($result['node']); + $bios = entity_load('node', $bios_nids); + + } + + foreach ($bios as $bio){ + $url = strtolower(drupal_get_path_alias("node/" . $bio->nid)); + + dpm($url); + + if (isset ($beamapping[$url])){ + $authorid = $beamapping[$url]; + + $bio->field_id['und'][0]['value']=$authorid; + + + + + node_save($bio); + + dpm($url . " -->" . $authorid); + + dpm($bio); + + + foreach ($beamappingNodeId[$url] as $entNid){ + //$entNid = $beamappingNodeId[$url]; + + $ent = entity_load_single("node", $entNid); + + $ent->field_bio_id['und'][0]['value']=$bio->nid; + $ent->field_bio_id_reference['und'][0]['nid']=$bio->nid; + dpm($ent); + dpm($ent->nid); + node_save($ent); + }} + + } + + +} + +function openmindattribute_addIDbibliographieID(){ + #adds the add bibliographie + $query = new EntityFieldQuery(); + + $query->entityCondition('entity_type', 'node') + ->entityCondition('bundle', 'openmind_entity') + ->propertyCondition('status', 1) + ->fieldCondition('field_oc', 'tid', '10', '='); #10 is reference #TODO should search for REFERENCE nd not the id + + $result = $query->execute(); + + + if (isset($result['node'])) { + $reference_nids = array_keys($result['node']); + $references = entity_load('node', $reference_nids); + + } + + foreach ($references as $reference){ + #{King, 1983 #1290} References haben diese Titel + # Hole die Nummer + + $exploded = explode("#", $reference->title); + $number = str_replace("}", "", $exploded[1]); + + + #suche jetzt in biblios nach der Nummer "=feld Custom 3" + + $query = db_select('node', 'n'); + $query->addField('n', 'nid'); + $query->leftJoin('biblio', 'b', 'n.vid=b.vid'); + + $query->addField('b', 'biblio_custom3'); + $query->condition("b.biblio_custom3", $number); + + $results=$query->execute(); + + foreach ($results as $node){ + $nid= $node->nid; + $ent = entity_load_single("node", $nid); + dpm($reference); + $reference->field_biblio_reference['und'][0]['nid']=$nid; + node_submit($reference); + node_save($reference); + } + + + } +} + + +function _openmindattribute_collection_list($name,&$form){ + $query = new EntityFieldQuery(); + + $query->entityCondition('entity_type', 'node') + ->entityCondition('bundle', 'openmind_entity') + ->propertyCondition('status', 1) + ->fieldCondition('field_oc', 'tid', '8', '='); #8 is COLLECTION #TODO should search for COLLECTION and not the id + + $result = $query->execute(); + + $options = array(); + + if (isset($result['node'])) { + $cols_nids = array_keys($result['node']); + $cols = entity_load('node', $cols_nids); + + + } + + + $options['']='All'; + + $titel = array(); + + foreach ($cols as $col){ + $titel[]=$col->title; + } + + sort($title); + + foreach($title as $t){ + $options[$t]=$t; + } + + + $form[$name]=array( + '#type' => 'radios', + '#options' => $options, + '#default_value' => '' + ); +} + +function openmindattribute_form_views_exposed_form_alter(&$form, $form_state, $form_id) { + + + if($form["#id"]=="views-exposed-form-codices-page-codices"){ + _openmindattribute_collection_list("title",$form); + + + } elseif ($form["#id"]=="views-exposed-form-codices-page-2"){ + + _openmindattribute_collection_list("title_1",$form); + } + +} + +