LIst Columns

4 posts by 2 authors in: Forums > CMS Builder
Last Post: Yesterday at 4:59pm   (RSS)

By Tim - Thursday at 9:59am - edited: Thursday at 10:04am

Hi MercerDesign,

You can if you tap into the related filter hook called "listRow_displayValue". Below is an example of using this hook to alter the display value of any list table. 

Step 1. Make sure you list the column in the Section/Database Editor >> Editor Tab >> List Columns field. This will show the column for you.

Step 2. Create a plugin file where you then implement the filter hook like shown below. Here we are looking up the specific table (in this case test_table is my table name) and the field name given to the upload field (in my case it is just called 'documents')

addFilter('listRow_displayValue', '_listRow_displayFileNameForUpload', 'admins');

function _listRow_displayFileNameForUpload($displayValue, $tableName, $fieldname, $record) {
    // Specify the specific table and field you want to modify
    if ($tableName === 'test_table' && $fieldname === 'documents') {
        if (isset($record['documents'][0])) {
            // Reference the field on that record and the first document in that field
            // Then replace its display value. Here I am customizing it to be a "badge" style value as well.
            $displayValue = '<span class="badge badge-primary">' . $record['documents'][0]['filename'] . '</span>';
        }
    }
    return $displayValue;
}

Step 3. Customize the line where I am setting up the badge to be the HTML that will replace the display value. I am creating a simple span tag here. Whatever you set displayValue to be will then be displayed. For security reasons, always make sure you are in control of the content here and escape appropriately if need be (if you are doing anything more advanced).

When you display the list for this table then it will render your filename. Since we are referencing '0' it will be the filename of the first upload for the field. Additional uploads will be referenced according (1, 2, 3 etc.)

I hope this helps push you in the right direction to a solution.

Tim Hurd
Senior Web Programmer
Interactivetools.com

List Columns

Thank you.

I have created a plugin file but I'm not sure I've done it correctly or loaded it up to the correct place, nothing has changed but I can see it in the Developer's Plugin Hook List.

List Columns

Hi MercerDesign,

I have run and tested this code before I posted, so I am sure the actual code works. Make sure you have the following set up:

  1. Make sure the plugin file you created is activated and is in the active plugin section.
  2. Make sure you replace the table name and the field name to reflect your table and field you want to target. In my example I used "test_table" and "documents" but yours will be different.
  3. The field name is referenced in a couple places so make sure all have been replaced.

If you have done all these things and still see no change, you can always post your entire plugin file and I can take a look. If all is good I should be able to take your file, change the table and fieldname as appropriate and it should just work.

Let me know how things go. :)

Tim Hurd
Senior Web Programmer
Interactivetools.com