View source
<?php
function cmis_field_field_info() {
return array(
'cmis_field_path' => array(
'label' => t('CMIS Field'),
'description' => t('Attach a CMIS object to a Drupal entity'),
'default_widget' => 'cmis_field_widget',
'default_formatter' => 'cmis_field_link',
'instance settings' => array(
'cmis_field_rootFolderPath' => '',
),
),
);
}
function cmis_field_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
foreach ($items as $delta => $item) {
if (!empty($item['cmis_field_path'])) {
if (1 == 0) {
$errors[$field['cmis_field']][$langcode][$delta][] = array(
'error' => 'cmis_field_invalid',
'message' => t('You are in the anti-universe, where 1 == 0.'),
);
}
}
}
}
function cmis_field_field_is_empty($item, $field) {
return empty($item['path']);
}
function cmis_field_field_instance_settings_form($field, $instance) {
$settings = $instance['settings'];
$form['cmis_field_rootFolderPath'] = array(
'#title' => t('Root Directory'),
'#description' => t('Root folder for CMIS nodes'),
'#type' => 'textfield',
'#default_value' => isset($settings['cmis_field_rootFolderPath']) ? $settings['cmis_field_rootFolderPath'] : '',
);
$form['#attached']['js'] = array(
array(
'data' => drupal_get_path('module', 'cmis_field') . '/js/cmis_field.js',
),
);
return $form;
}
function cmis_field_field_widget_info() {
return array(
'cmis_field_browser' => array(
'label' => t('CMIS link'),
'field types' => array(
'cmis_field_path',
),
'settings' => array(
'cmis_field_rootFolderPath' => array(),
),
),
);
}
function cmis_field_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
$title = isset($items[$delta]['title']) ? $items[$delta]['title'] : '';
$path = isset($items[$delta]['path']) ? $items[$delta]['path'] : '';
$element += array(
'#delta' => $delta,
);
$element['path'] = array();
$element['title'] = array();
$element['title'] += array(
'#type' => 'textfield',
'#default_value' => $title,
'#attributes' => array(
'class' => array(
'edit-field-cmis-field',
),
),
'#title_display' => 'before',
'#title' => check_plain($instance['label']),
);
$element['path'] += array(
'#type' => 'hidden',
'#attributes' => array(
'class' => array(
'edit-field-cmis-path',
'search-form',
),
),
'#default_value' => $path,
);
$element['#attached']['js'] = array(
array(
'data' => drupal_get_path('module', 'cmis_field') . '/js/cmis_field.js',
),
array(
'data' => array(
'cmispath' => $instance['settings']['cmis_field_rootFolderPath'],
),
'type' => 'setting',
),
);
return $element;
}
function cmis_field_field_formatter_info() {
return array(
'cmis_field_link' => array(
'label' => t('CMIS browser'),
'field types' => array(
'cmis_field_path',
),
),
);
}
function cmis_field_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
switch ($display['type']) {
case 'cmis_field_link':
foreach ($items as $delta => $item) {
$element[$delta]['#markup'] = l($item['title'], 'cmis/browser', array(
'query' => array(
'id' => $item['path'],
),
));
}
break;
}
return $element;
}