Code Snippets

osCaddie Taxonomy

In this example, it shows the codes to sync taxonomy terms for Drupal and Categories in Alfresco. More in depth explanation can be found here.

Drupal Code:

/**
 * Implementation of hook_form_alter
 */ function alfresco_taxonomy_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'taxonomy_form_vocabulary':
    $form['#submit'][] = 'alfresco_taxonomy_form_vocabulary';
    break;
  case 'taxonomy_vocabulary_confirm_delete':
    $form['#submit'][] = 'alfresco_taxonomy_vocabulary_confirm_delete_submit';
    break;   case 'taxonomy_form_term':
    $form['#submit'][] = 'alfresco_taxonomy_form_term';
    break;
  } } /**
 * Alfresco taxonomy submit function
 */ function alfresco_taxonomy_form_term(&$form, $form_state = array()) {
  module_load_include('inc', 'alfresco_connector', 'includes/alfresco_connector.alfresco_api');
  module_load_include('inc', 'alfresco_connector', 'includes/alfresco_connector.helpers');
  $values = $form_state['values'];
  $alfresco_endpoint = variable_get(AFRESCO_CONNECTOR_ENDPOINT_KEY, '');
  $alf_ticket = alfresco_connector__alfresco_api_get_api_ticket();
  if(empty($alf_ticket)) {
    return NULL;
  }
  switch ($values['op']) {
    case 'Save':
      $path = ALFRESCO_TAXONOMY_CATEGORY_URL;
      break;
  }
  $url = $alfresco_endpoint . $path . "?alf_ticket=$alf_ticket";
  $boundary = 'A0sFSD';
  $method = 'POST';
  $headers = array(
    "Content-Type" => "multipart/form-data; boundary=$boundary",
  );
  $params = array(
    'tagName' => $values['name'],
  );
  $data = wl_alfresco_connector__helpers_multipart_encode($boundary, $params);
  $response = drupal_http_request($url, $headers, $method, $data); }

Alfresco Code:


// See if the tag already exists tagExists = taxonomyCheckTagExist(store, tagName); if (!tagExists) {
  tag = taggingService.createTag(store, tagName);
  if (tag == null) {
    model.result = FAILURE_MESSAGE;
  } } else {
  tag = tagName;
  model.response = ERROR_1000_DUPLICATE; }

// Put the created tag into the model model.tag = tag; model.tagExists = (tagExists) ? "TRUE" : "FALSE"; model.tags = taggingService.getTags(store); 

Resource Tags: