Using a plugin, I have added some nested entry sources to some of the default section entry sources in my site.
For example:
'section:6' => [
'label' => 'News',
...
'nested' => [
'foo' => [
'label' => 'Foo',
...
],
'bar' => [
'label' => 'Bar',
...
]
]
];
Now, for the main entry source (section:6), I am able to select the visible columns (table attributes) that appear in the element index listing. However, that selection of table attributes does not filter down to the nested entry sources. When I click on a nested entry source, the default table attributes are utilised rather than the attributes that were selected for the parent source. I want my nested entry sources to utilise the same table attributes as the parent entry source.
I did some digging around in the Craft CMS code and database, and it appears as though the craft_elementindexsettings table only saves the table attributes selected for top level entry sources and not nested ones. So when the ElementIndexesService is called upon to getTableAttributes for the nested source key, it is returning the default attributes (as evident below).
public function getTableAttributes($elementTypeClass, $sourceKey)
{
...
// Is there a custom attributes list?
if (isset($settings['sources'][$sourceKey]['tableAttributes']))
{
$attributeKeys = $settings['sources'][$sourceKey]['tableAttributes'];
}
else
{
$elementType = craft()->elements->getElementType($elementTypeClass);
$attributeKeys = $elementType->getDefaultTableAttributes($sourceKey);
}
...
return $attributes;
}
Hopefully someone can shed some light on why I cannot customise the table attributes of the nested entry source.
Here is a real life demonstration of the issue using Pixel and Tonic's Happy Lager demo site and Category sources plugin.
As you can see above, in my 'Alcoholic' top-level entry source, I've specified custom columns/attributes so that the 'Heading', 'Section' and 'Entry Type' are also included in the element index listing for the entry source.
However, if I then click one of the nested entry sources, 'Beer' for instance, those 3 custom columns/attributes are no longer present as is evident below.
In my opinion, the expected behaviour would be that the nested entry sources would utilise the custom columns/attributes defined for the top level entry source. So 'Heading', 'Section' and 'Entry Type' should have been visible when clicking on 'Beer'.
I expect it's more work technically, but it might also be useful if it were possible to independently configure the columns/attributes of the nested entry sources too.