|
@@ -42,6 +42,9 @@ function tode_theme() {
|
|
|
'tode' => array(
|
|
|
'arguments' => array('element' => NULL),
|
|
|
),
|
|
|
+ 'tode_node_formatter' => array(
|
|
|
+ 'variables' => array('item' => NULL, 'viewmode' => 'full', 'nodes'=>NULL),
|
|
|
+ ),
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -861,10 +864,9 @@ function DESACTIVATED_tode_field_widget_form_alter(&$element, &$form_state, $con
|
|
|
*
|
|
|
*/
|
|
|
function tode_form_alter(&$form, $form_state, $form_id){
|
|
|
- // dsm($form_id, 'tode form_alter form_id');
|
|
|
- /*
|
|
|
- TODO block the deletion if tode term has children !! because this will delete them to …
|
|
|
- */
|
|
|
+ // dsm($form_id, 'tode form_alter form_id');
|
|
|
+ // TODO block the deletion if tode term has children !! because this will delete them to …
|
|
|
+
|
|
|
if($form_id == 'test_node_form'){
|
|
|
// dsm($form_state);
|
|
|
}
|
|
@@ -1031,6 +1033,103 @@ function tode_url_outbound_alter(&$path, &$options, $original_path) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+/**
|
|
|
+ * Implements hook_field_formatter_info().
|
|
|
+ */
|
|
|
+function tode_field_formatter_info() {
|
|
|
+ return array(
|
|
|
+ 'tode' => array(
|
|
|
+ 'label' => t('tode (node of the term)'),
|
|
|
+ 'field types' => array('taxonomy_term_reference'),
|
|
|
+ 'settings'=>array('viewmode' => "full"),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Implements hook_field_formatter_settings_form().
|
|
|
+ */
|
|
|
+function tode_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
|
|
|
+ $element = array();
|
|
|
+ $display = $instance['display'][$view_mode];
|
|
|
+ $settings = $display['settings'];
|
|
|
+ $formatter = $display['type'];
|
|
|
+
|
|
|
+ if($formatter == 'tode'){
|
|
|
+ if($todefield = _tode_get_voc_tode_fields_def($field['settings']['allowed_values'][0]['vocabulary'])){
|
|
|
+ $entity_infos = entity_get_info();
|
|
|
+ foreach ($entity_infos['node']['view modes'] as $viewmode => $value) {
|
|
|
+ $viewmode_options[$viewmode] = $value['label'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $element['viewmode'] = array(
|
|
|
+ '#type' => 'select',
|
|
|
+ '#title' => t('View mode'),
|
|
|
+ '#default_value' => $settings['viewmode'],
|
|
|
+ '#description' => t('select the view mode for the node'),
|
|
|
+ '#options' => $viewmode_options,
|
|
|
+ );
|
|
|
+
|
|
|
+ }else{
|
|
|
+ // TODO: tell that vocabulary has any tode field
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $element;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Implements hook_field_formatter_settings_summary().
|
|
|
+ */
|
|
|
+function tode_field_formatter_settings_summary($field, $instance, $view_mode) {
|
|
|
+ $display = $instance['display'][$view_mode];
|
|
|
+ if($display['type'] == 'tode'){
|
|
|
+ $settings = $display['settings'];
|
|
|
+ $summary = t('viewmode : %vm', array('%vm'=> isset($settings['viewmode']) ? $settings['viewmode'] : 'full') );
|
|
|
+ return $summary;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Implements hook_field_formatter_view().
|
|
|
+ */
|
|
|
+function tode_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
|
|
|
+ $element = array();
|
|
|
+ $settings = $display['settings'];
|
|
|
+
|
|
|
+ switch ($display['type']) {
|
|
|
+ case 'tode':
|
|
|
+ foreach ($items as $delta => $item) {
|
|
|
+ $term = taxonomy_term_load($item['tid']);
|
|
|
+
|
|
|
+ $entitys = tode_get_nids_from_term($term);
|
|
|
+
|
|
|
+ $nodes = array();
|
|
|
+ if(isset($entitys['node'])){
|
|
|
+ foreach ($entitys['node'] as $nid => $n) {
|
|
|
+ $node = node_load($nid);
|
|
|
+ $nodes[$nid] = $node;
|
|
|
+ }
|
|
|
+ $element[$delta] = array(
|
|
|
+ '#theme' => 'tode_node_formatter',
|
|
|
+ '#item' => $item,
|
|
|
+ '#viewmode' => $settings['viewmode'],
|
|
|
+ '#nodes'=> $nodes,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $element;
|
|
|
+}
|
|
|
+
|
|
|
+function theme_tode_node_formatter($vars){
|
|
|
+ // dsm($vars, 'theme_tode_node_formatter | vars');
|
|
|
+ print render(entity_view('node', $vars['nodes'], $vars['viewmode']));
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* HELPERS
|
|
|
*/
|