1

In CP Craft Admin in the entries table view I d like to display some authors meta info.
How could I do that in my plugin?
I know public function modifyEntryTableAttributes(&$attributes, $source) and public function getEntryTableAttributeHtml(EntryModel $entry, $attribute)and but I cannot make it work.

2

You're on the right track with both of those. First, modifyEntryTableAttributes.

Gives plugins a chance to modify the table columns shown on the entry index page.

This lets you name the column for your author info. It's a hook, so you'll need to add a public method with the same name as that that to your main plugin class. You can also limit the column to particular section by checking the $source variable.

public function modifyEntryTableAttributes(&$attributes, $source)
{
    if ($source == 'section:3')
    {
        $attributes['author'] = Craft::t('Author');
    }
}

Then to actually return the information, you need getEntryTableAttributeHtml.

Gives plugins a chance to customize the HTML of the table cells on the entry index page.

Here you can just check for the attribute you set above, and return a string.

public function getEntryTableAttributeHtml(EntryModel $entry, $attribute)
{
    if ($attribute == 'author')
    {
        return $entry->getAuthor()->getFriendlyName();
    }
}
1
  • Yes thats right answer. I had it but it was not working because of a conflict with DashCols plugin indeed. So I disabled the plugin and it works great. Now I just know that its DashCols plugin or all custom made. One way or the other... not both. – migswd Aug 14 '15 at 2:46
1

From what I understand I think the methods you reference are for when you create a plugin with its own custom element type, I don't think you can interact with the entry listing as standard without a plugin.

I do think there is a plugin which might help you achieve this though without having to write your own.

https://github.com/mmikkel/DashCols-Craft/

From the looks of things this should let you add custom fields to the entry listing page, I haven't actually used this but it looks solid.

1
  • I use it all the time but in my case its useless because I want a field from a relationTo entry (the author of the entry)... Not possible with DashCols. – migswd Aug 13 '15 at 23:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.