Flexifield table formatter

chipway-drupal - August 5, 2008 - 08:27
Project:Flexifield
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review
Description

Hi,

I guess that it will be a great module.

I would like to be able to have table display for flexifield embedded fields (one line per embedded CT and one column per embedded CT field). Do you think it could do this ?

I tested and found not working with content_taxonomy (but it is still a proof of concept).

Thank you

#1

effulgentsia - August 5, 2008 - 19:03
Assigned to:Anonymous» effulgentsia

Thank you very much for the request. It's very helpful to get ideas of what people are interested in.

I expect this to be possible. The next thing I'm working on is the theming approach, but I plan on being able to have theming functions / tpl files able to control how the containing field / contained fields are themed in both view mode and edit mode.

I'll also look into whether formatters can be configured so that rendering as a table could be configured entirely through the interface and not require knowledge of how to work with theming functions / tpl files.

I don't have an estimate on when the theming / formatters will be ready. I'll be actively working on it, since we need it for a project my company is working on, but I also have other work unrelated to this module that I need to work on.

#2

chirale - August 10, 2008 - 21:16

It's good to hear this. A table-like theme as CwDrup proposal could be achieved converting field label to "table headers" reducing redundancies (repeated labels for each field). Another interesting case for a "table" theme could be the text field option widget handling. Each option could be returned as a table row under a common header, displaying each label one time.

A fixed header on scrolling like admin/build/modules on Drupal 6.x should be fine with an increasing number of elements. (@CwDrup: I've opened an issue for Content Taxonomy elements not showing).

#3

exintaexi - March 8, 2009 - 02:15

Hello,

Is this "table-like" appearance implemented?

This is a great module, but you can understand that if you have a bunch of fields to enter something as simple as a number, then it's appearance in edit mode is not very convenient!

Has anyone found any way to work around this?

Thanks!

#4

leo.ruffini - March 20, 2009 - 09:23

I would also really like to see this feature included.
Thanks for the module, it is great.

Leo

#5

crea - June 22, 2009 - 19:09
Title:Great module I fill & table request» Flexifield table formatter
Status:active» needs review

Since effulgentsia is not very active, I don't submit this as patch but instead as standalone module.
This code is maybe ugly, and "needs work" but setting it as "needs review" to get more attention. Please try and review.
Some notes:

  1. To hide field labels in cells you need to set them as 'hidden' in your source node (which provided all fields) field display settings. You can do this at "Basic" tab. Label settings seem to be universal for all contexts, so if you set labels as hidden, they are hidden everywhere. I guess this won't be problem, unless you want to display same flexifield both with and without source field labels at different places.
  2. This code creates own "display context". Would be best if effulgentsia could change this code so it would play nice with "displaycontexts" submodule. One should be able to create many table formatters with different contexts (i.e. with different display formatters of source fields).
  3. Installation: Enable module, go to "admin/content/node-type/result_node/display" where result_node is your result node type (i.e. node which contains flexifield field itself). Set flexifield to display as "Table". Then go to "admin/content/node-type/source_node/display/flexifield_table" where source_node is node type which provided fields from which you made flexifield. Here you can hide fields from table output or change how they display (i.e. change formatters). In summary: we changed flexifield formatter to table, and table at the same time is "display context" for source fields of flexifield.
AttachmentSize
flexifield_table.zip 1.75 KB

#6

galser - June 28, 2009 - 21:29

Thanks for small but great add-on module to FlexiField.
I currently testing it, and had made some useful correction, maybe it make sense for other peoples over here.
Imagen situation when your flexifield-field displayed as table, and your have all table data for some column empty, maybe better to hide this column at all. Well, that is simple.
Replace this lines (starting from line 57 in flexifield_table.module )

<?php
     
     
// Skip hidden field columns
     
if ($formatter_name != 'hidden') {
        if (!isset(
$header[$column])) {
         
$header[$column] = check_plain(t($field['widget']['label']));
        }
       
$rows[$row][$column] = $cell;
      }

?>

With this :
<?php
     
  
if(isset($cell))  /* do not set header-text if cell empty */
     
{
  
// Skip hidden field columns
      
if ($formatter_name != 'hidden') {
         if (!isset(
$header[$column])) {
          
$header[$column] = check_plain(t($field['widget']['label']));
         }
        
$rows[$row][$column] = $cell;
       }
     }

?>

E.g. - one additional check before, and a closing bracket after.
If anything wrong in my post style.. correct me please, because I am newbie here.

#7

crea - June 29, 2009 - 00:32

Why would you want to skip cells like that ? What if on one row same column is empty and on another it's not ? Header will be set up anyway.
There could be use cases to show empty columns. And as it was said in #5 there is setting to hide column so adding additional code seems unneeded.

#8

zeno129 - June 29, 2009 - 19:00

I was getting the following error:

Fatal error: Call to undefined function flexifield_item_invoke() in /var/www/gCIPMs/sites/all/modules/flexifield_table/flexifield_table.module on line 43

To make it work I changed line 43 from:

<?php 

    flexifield_item_invoke
('view', $aItem, $aElement['#node']);

?>

to this:

<?php

    _flexifield_field_invoke
('view', $aItem, $aElement['#node']);

?>

Hope someone finds this helpful. :-)

#9

zeno129 - June 29, 2009 - 20:17

The label for each item (same as the column headers) was showing in every cell (which is annoying)...
to eliminate the label from showing in every cell I had to do add a couple of lines:

<?php

/**
* Theme function for table flexifield formatter.
*/
function theme_flexifield_table_formatter_table($aElement) {
 
//variables added for label removal -zeno129 ***
 
$find = '';
 
$replace = '';
 
$result_str = '';

 
$output = '';
 
$header = array();
 
$rows = array();
  foreach (
element_children($aElement) as $row) {
   
// Invoke 'view' on the item, and let the item and content element created by
    // the view operation have access to the node.
   
$aItem = $aElement[$row]['#item'];

    if (!isset(
$aItem['#node'])) {
     
$aItem['#node'] = $aElement['#node'];
    }

   
// Setting up display context. We need it to be able to select formatters of individual fields,
    // and to hide table columns with hidden fields
   
$context = 'flexifield_table';
   
$aElement['#node']->build_mode = $context;

   
_flexifield_field_invoke('view', $aItem, $aElement['#node']);
   
$aContentElement = $aItem['value']['content'];

    if (!isset(
$aContentElement['#node'])) {
     
$aContentElement['#node'] = $aItem['#node'];
    }

    foreach (
element_children($aContentElement) as $column) {
     
$field = content_fields($column, $aContentElement[$column]['#type_name']);
     
$cell = drupal_render($aContentElement[$column]); //this line sets each field -zeno129 ***

      // Check formatter for every field in row
     
$formatter_name = isset($field['display_settings'][$context]) && isset($field['display_settings'][$context]['format']) ? $field['display_settings'][$context]['format'] : 'default';

     
// Skip hidden field columns
     
if ($formatter_name != 'hidden') {
        if (!isset(
$header[$column])) {
         
$header[$column] = check_plain(t($field['widget']['label'])); //this line sets the name for each column -zeno129 ***
       
}
       
//$rows[$row][$column] = $cell; //original line

        //additions:                                                               -zeno129 ***
       
$find = $header[$column]; //this gets the label we want to remove -zeno129 ***

       
$result_str = str_replace($find . ':',$replace,$cell);
       
//$result_str = trim($result_str); //Trim doesn't seem to work to eliminate the 2 spaces at the beginning of each item -zeno129 ***
        //$result_str = substr($result_str,2); //Cannot use substr because there is a div before where the label used to go  -zeno129 ***
       
$rows[$row][$column] = $result_str;
      }
    }
  }
  if (!empty(
$rows)) {
   
// Theme multiple flexifield items as table
   
$output = theme('table', $header, $rows);
  }
  return
$output;
}

?>

I wasn't able to eliminate the 2 spaces that appear right before the item... if anyone figures this out, please let me know.
I've attached the module with the changes I made for anyone who wants it.

AttachmentSize
flexifield_table.zip 1.97 KB

#10

effulgentsia - July 8, 2009 - 00:21
Assigned to:effulgentsia» Anonymous

This is cool. Thanks for taking the initiative to work on it. I've been busy on other issues, but I would like to get something like this rolled into the project before moving to beta releases.

Clarification in response to comment #8. Alpha4 of flexifield had the function named "_flexifield_field_invoke". With alpha5 (released a few minutes ago), the function is "flexifield_item_invoke".

#11

crea - July 20, 2009 - 16:51

One more note:
You can theme output of each field in the table same way as any CCK field: using template files like "content-field.tpl.php" (exact filename depends on your usecase - see CCK field theming documentation). Default template produces lots of trash markup code which is unneeded in Flexifield use case so you can make your own templates and remove the trash.
This may change, depending on how effulgentsia actually implements formatter code, but atm this works.

#12

NigelCunningham - August 25, 2009 - 00:33

Subscribing. I've just started using this, and it's working fine.

 
 

Drupal is a registered trademark of Dries Buytaert.