HOWTO: Show fields in the same module but not in the ListView on the ListView.

bsoremsugar —  March 21, 2012 — 1 Comment

The title for this one’s kinda confusing, so let me jump right into the use case that came from our PS team on this one:
I have this line in my ListView

'customCode' => '<img id="TYPE_ICON_{$ID}" src="{$CCMS_LEVEL}.png"> {$NAME}',

The problem is that $CCMS_LEVEL is not a field we show in the list view (it is a valid field though) so it comes up blank.  If I add the CCMS_LEVEL field to the list view it works perfectly so I know its just that it isn’t set to ‘default’=true.

Is there a way to get to fields from the bean (this is not a custom field, it is in the main table) even if they are not shown on the ListView?

Seeing that $CCMS_LEVEL is actually a field in the same module, we can do a very simple upgrade-safe fix of adding a reference to that field in the listviewdefs field entry as follows:

'NAME' =>
  array (
    'width' => '20%',
    'label' => 'LBL_LIST_ACCOUNT_NAME',
    'link' => true,
    'default' => true,
    'related_fields' => array('ccms_level'),
    'customCode' => '<img id="CLIENT_ICON_{$ID}" src="custom/themes/default/images/{$CCMS_LEVEL}.png"> {$NAME}',
  ),

The key here is the ‘related_fields’ attribute, which tells the ListView code to pull this field from the database as well; otherwise the $CCMS_LEVEL field will come over as empty.

One response to HOWTO: Show fields in the same module but not in the ListView on the ListView.

  1. 

    Very glad to see this written out. I feel like in the various metadata sections we’re lacking some documentation as to the available options. You see “name” and “lable” and “default” all over the place but keys like “related_fields” and “link” are  more obscure and you really have to know to look for them.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s