array( 'label' => t('Alfresco Attachment'), 'description' => t('Attach an Alfresco node via the repository browser'), ) ); } /** * Implementation of hook_field_settings * * @param $op - operation * @param $field - field beign operated on * @return - form or settings array dependent on operation */ function cmis_alfresco_field_field_settings($op, $field) { switch ($op) { case 'form': $form['root_directory'] = array( '#title' => t('Root Directory'), '#description' => t('Root Directory for Alfresco nodes'), '#type' => 'textfield', '#autocomplete_path' => 'cmis/autocomplete', '#default_value' => '/Company Home', ); return $form; case 'save': $settings = array('root_directory'); return $settings; case 'database columns': $columns = array( 'path' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE), ); return $columns; } } /** * * @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_alfresco_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_alfresco_field_content_is_empty($item, $field) { if (empty($item['path'])) { return TRUE; } return FALSE; } /** * Implementation of hook_widget_info * * @return array defining the widget */ function cmis_alfresco_field_widget_info() { return array( 'cmis_alfresco_field_widget' => array( 'label' => t('Alfresco browser'), 'field types' => array('cmis_alfresco_field'), 'multiple values' => CONTENT_HANDLE_CORE, 'callbacks' => array('default value' => CONTENT_CALLBACK_CUSTOM), 'description' => t('Click to browse the Alfresco repository and select an Alfresco node to associate with this Drupal node.' ) ) ); } /** * Implementation of hook_elements() * * @return array elements to be processed by FAPI */ function cmis_alfresco_field_elements() { return array( 'cmis_alfresco_field_widget' => array( '#input' => TRUE, '#process' => array('cmis_alfresco_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_alfresco_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_alfresco_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_widget_settings() * * @param $op - operation * @param $widget - the widget array * @return depends on operation */ function cmis_alfresco_field_widget_settings($op, $widget) { switch ($op) { case 'form': return; case 'validate': return; case 'save': return; } } /** * Implementation of hook_field_formatter_info * * @return array */ function cmis_alfresco_field_field_formatter_info() { return array( 'default' => array( 'label' => t('Alfresco browser'), 'field types' => array('alfresco_cmis_field') ) ); } /** * Implementation of hook_theme() * * @return array of theme functions */ function cmis_alfresco_field_theme() { return array( 'cmis_alfresco_field_widget' => array('arguments' => array('element')), 'cmis_alfresco_field_formatter_default' => array('arguments' => array('element' => NULL)) ); } /** * Funciton to theme the widget form * @param $element * @return string - themed output of the widget */ function theme_cmis_alfresco_field_widget(&$element) { return theme('form_element', $element, $element['#children']); } function theme_cmis_alfresco_field_formatter_default($element = NULL) { if (empty( $element['#item'])) { return ''; } return print_r($element, TRUE); }