You are here

cmis_field.module in CMIS API 6.4

File

cmis_field/cmis_field.module
View source
<?php

/**
 * Implementation of hook_field_info()
 * 
 * @return array - CCK field definition
 */
function cmis_field_field_info() {
  return array(
    'cmis_field' => array(
      'label' => t('CMIS Attachment'),
      'description' => t('Attach an CMIS object to a Drupal field'),
    ),
  );
}

/**
 * Implementation of hook_field_settings()
 * 
 * @param $op - operation
 * @param $field - field beign operated on
 * @return - form or settings array dependent on operation
 */
function cmis_field_field_settings($op, $field) {
  switch ($op) {
    case 'form':
      $form['cmis_field_rootFolderPath'] = array(
        '#title' => t('Root Directory'),
        '#description' => t('Root folder for CMIS nodes'),
        '#type' => 'textfield',
        '#autocomplete_path' => 'cmis/autocomplete',
        '#default_value' => '/',
      );
      return $form;
    case 'save':
      $settings = array(
        'cmis_field_rootFolderPath',
      );
      return $settings;
    case 'database columns':
      $columns = array(
        'path' => array(
          'type' => 'varchar',
          'length' => 255,
          'not null' => FALSE,
        ),
      );
      return $columns;
  }
}

/**
 * Implementation of hook_field()
 * 
 * @param $op - operation
 * @param $node - node
 * @param $field - field settings
 * @param $items - field value(s)
 * @param $teaser - boolean for whether or not we're displaying a teaser
 * @param $page - boolean for whether or not we're displaying a page
 * @return unknown_type
 */
function cmis_field_field($op, &$node, $field, &$items, $teaser, $page) {
  switch ($op) {
    case 'validate':
      foreach ($items as $i) {
        if (empty($i)) {
          form_set_error('', 'The field cannot be empty');
        }
      }
      return $items;
      break;
  }
}

/**
 * Implementation of hook_is_empty()
 * 
 * @param $item - field value(s)
 * @param $field - field settings
 * @return boolean - TRUE/FALSE
 */
function cmis_field_content_is_empty($item, $field) {
  return empty($item['path']);
}

/**
 * Implementation of hook_widget_info
 * 
 * @return array defining the widget
 */
function cmis_field_widget_info() {
  return array(
    'cmis_field_widget' => array(
      'label' => t('CMIS link'),
      'field types' => array(
        'cmis_field',
      ),
      'multiple values' => CONTENT_HANDLE_CORE,
      'callbacks' => array(
        'default value' => CONTENT_CALLBACK_CUSTOM,
      ),
    ),
  );
}

/**
 * Implementation of hook_elements()
 * 
 * @return array elements to be processed by FAPI
 */
function cmis_field_elements() {
  return array(
    'cmis_field_widget' => array(
      '#input' => TRUE,
      '#process' => array(
        'cmis_field_widget_process',
      ),
    ),
  );
}

/**
 * Implementation of hook_process()
 * 
 * @param $element - the form element array
 * @param $edit - 
 * @param $form_state - form state array
 * @param $form - form array
 * @return array - form element
 */
function cmis_field_widget_process($element, $edit, $form_state, $form) {
  $defaults = $element['#value'];
  if (!is_array($defaults)) {
    $defaults = unserialize($defaults);
  }
  $element['path'] = array(
    '#type' => 'textfield',
    '#default_value' => $defaults['path'],
    '#autocomplete_path' => 'cmis/autocomplete',
  );
  return $element;
}

/**
 * Implementation of hook_widget()
 * 
 * @param $form - form array
 * @param $form_state - form state array
 * @param $field - field array
 * @param $items - field values
 * @param $delta - id of the field (if there is more than one in the form)
 * @return form element array
 */
function cmis_field_widget(&$form, &$form_state, $field, $items, $delta = 0) {
  $element = array(
    '#type' => $field['widget']['type'],
    '#default_value' => isset($items[$delta]) ? $items[$delta] : '',
  );
  return $element;
}

/**
 * Implementation of hook_field_formatter_info()
 * 
 * @return array
 */
function cmis_field_field_formatter_info() {
  return array(
    'default' => array(
      'label' => t('CMIS browser'),
      'field types' => array(
        'cmis_field',
      ),
    ),
  );
}

/**
 * Implementation of hook_theme()
 * 
 * @return array of theme functions
 */
function cmis_field_theme() {
  return array(
    'cmis_field_widget' => array(
      'arguments' => array(
        'element',
      ),
    ),
    'cmis_field_formatter_default' => array(
      'arguments' => array(
        'element' => NULL,
      ),
    ),
  );
}

/**
 * Function to theme the widget form
 * 
 * @param $element
 * @return string - themed output of the widget
 */
function theme_cmis_field_widget(&$element) {
  return theme('form_element', $element, $element['#children']);
}

/**
 * CMIS field default formatter.
 *
 */
function theme_cmis_field_formatter_default($element = NULL) {
  $content = '';
  if (is_array($element) && array_key_exists('#item', $element)) {
    $content = l($element['#item']['path'], 'cmis/browser' . $element['#item']['path']);
  }
  return $content;
}

Functions

Namesort descending Description
cmis_field_content_is_empty Implementation of hook_is_empty()
cmis_field_elements Implementation of hook_elements()
cmis_field_field Implementation of hook_field()
cmis_field_field_formatter_info Implementation of hook_field_formatter_info()
cmis_field_field_info Implementation of hook_field_info()
cmis_field_field_settings Implementation of hook_field_settings()
cmis_field_theme Implementation of hook_theme()
cmis_field_widget Implementation of hook_widget()
cmis_field_widget_info Implementation of hook_widget_info
cmis_field_widget_process Implementation of hook_process()
theme_cmis_field_formatter_default CMIS field default formatter.
theme_cmis_field_widget Function to theme the widget form