Adding additional attributes to modifyEntryTableAttributes() Using the example code from the docs, I'm attempting to add a value from my custom field to the Entries listing. 

public function modifyEntryTableAttributes(&amp;$attributes, $source)
{
    if ($source == 'index')
    {
        unset($attributes['expiryDate']);
        $attributes['id'] = Craft::t('ID');
    }
}


How do I go about accessing additional attributes on the Entries? The custom field data is stored in MyPluginName's table and doesn't appear to be available in the attributes of the EntryElement.

Thanks for any pointers you may have!
See this question:


  Possible to add category field to modifyEntryTableAttributes?


Basically, you need to use the getEntryTableAttributeHtml hook to get the actual content to the table cells in addition to the modifyEntryTableAttributes. You can do queries here if you need to get the data if you can not access it from the entry.

public function modifyEntryTableAttributes(&amp;$attributes, $source)
{
    if ($source == 'index')
    {
        // This will be the header name of the column, the &lt;th&gt;
        $attributes['myCustomField'] = Craft::t('My Label');
    }
}

public function getEntryTableAttributeHtml(EntryModel $entry, $attribute)
{
    if ($attribute == 'myCustomField')
    {
        // Fetch the related data from your plugin. This will be placed in the &lt;td&gt;'s
        $fieldData = craft()-&gt;myPlugin-&gt;getFieldData($entry);
        // OR $entry-&gt;myCustomField-&gt;first(); if myCustomField is an ElementCriteriaModel.
        return $fieldData;
    }
}


EDIT: Think of it this way: when craft is loading up the entries (or any of the element types) to display on the index page, it has to know what fields are going to show. These fields are defined in the EntryElementType::defineTableAttributes. This method returns an array of attributes, where the key is whatever you want, and the value is what is displayed in the tables &lt;th&gt; tags. In this function, the entry type is defining some standard fields to show (title, uri, postdate etc), but Craft is nice enough to let plugins modify this array before it is returned.

Where does the array of attributes go after? The function for populating the &lt;td&gt; tags of the table, the EntryElementType::getTableAttributeHtml($entry, $attribute). The first thing this function does it to let plugins decide what to do, so it calls the getEntryTableAttributeHtml which is the function you should implement. The $attribute parameter is the key you defined. Here you have a chance to tell Craft how the data is displayed. If you in the first function defined $attributes['id'] and did nothing in the second function, the default way Craft is getting this data is doing $entry-&gt;$attribute (or $entry->id in this case), which would display the entry's id in the column. If $entry->$attribute is an array, or an object without a __toString, this will not work, so you will have to tell Craft explicitly how to represent this field, e.g.  

if ($attribute = 'myArrayOfSpecialFields'){
  return $entry-&gt;myArrayOfSpecialFields['indexOfStringToDisplay'];
}


There are tons of useful information on this in the EntryElementType, you can just follow the flow in the code (perhaps start in the ElementIndexController)

Hope that makes things more clear