craftcms / craftcms/cms

ElementIndex Enhancements

Open
#2,437 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
3.6k
Forks
705
Avg merge
1d 5h
Merged PRs (30d)
134

Description

I've spent some time working with and trying to customize an ElementIndex. Along the way, There are a few areas (pain points) that I'm hoping to discuss and ultimately improve.

My common use case is, displaying an index of elements that are related to another element; such as users associated to an organization (custom element), but this could also apply to listing all entries associated to a category, etc.

Constructing the criteria and returning the appropriate results works great (I didn't expect it to be so easy to use). However:

1. ElementIndexesController restricts actions to 'index' contexts only

It would be great to provide a custom context (such as 'organization-index' in my case), where I can register specific actions (currently supported) to that context. In this context, my action would be 'remove' which is specific to my index context (not available via normal 'index' context).

Extending that controller is also difficult because almost everything is private so our hands are tied. Can we remove the strict 'index' context check and leave it up to the element / event?

2. Craft.BaseElementIndex JS is tightly coupled to the .sidebar UI

This makes sense in the common use of ElementIndex(s) where they are the main listing on a page, however I've found them to be useful elsewhere. In these cases, adhering to a sidebar class and UI isn't desired...and not providing one essentially aborts the index all together.

Instead of referring to 'sidebar', perhaps it's 'sourceContainer' or something similar. This leads into my next item, which would allow placing the source inside the toolbar.

3. _elements/indexcontainer.html template could support blocks for extensibility via embeds

This is somewhat related to what I'm trying to do with the JS flexibility, introducing some blocks to the toolbar would allow for extensibility. In my case, I want to move the source select into the toolbar and the only way to do this is to do the dreadful copy/paste.

I've been able to successfully accomplish everything that I have mentioned above, but it's resulted in more copy/paste that I was hoping for. It's been a great exercise and I'm happy to work this up as a pull request, but I'd like to get your feedback it before proceeding (1 and 2 would be a little more involved).

The attachment is a user element index which serves as the employee roster. It's specific to the organization and nested outside the typical 'listing' page. The sources have been moved outside the 'sidebar' and into toolbar.

source-in-toolbar

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading ElementIndexesController, Craft.BaseElementIndex, and _elements/indexcontainer.html. Compare the existing index-context actions, sidebar assumptions, and template extension points with the attached employee-roster use case. Done means custom contexts and actions work, the source can live outside the sidebar, and toolbar placement is extensible without copying the template.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, php
Domain
backend, frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.