Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\CrudView\Listener\ViewListener::_associations receives $whitelist as [0, 1, 2, 3, 4] #332

Open
mehov opened this issue Jul 15, 2024 · 1 comment

Comments

@mehov
Copy link

mehov commented Jul 15, 2024

Hi,

I'm trying to have CrudView use displayField values when linking to associated entries. Right now it links to them via their IDs.

It isn't really documented, I guess because it should just work by default. For me it doesn't, and the only resource I found is #280, which at least gave me an idea of where to poke around.

$keys = $associations->keys();

Doing debug([$keys, $whitelist]); right after that says I have an array of normal model names as $keys (Pages, Posts) and an array of integers as $whitelist (0, 1). The latter has exactly as many elements as the former and starts from 0, which makes it seem someone just used array keys instead of values.

@mehov
Copy link
Author

mehov commented Jul 15, 2024

Yep, it's here in beforePaginate() callback:

$this->associations = $this->_associations(array_keys($related));

Changing that to $this->associations = $this->_associations($related); hotfixes the issue for me, meaning associated entries are now linked to using their displayFields.

As I was looking through the file, I've seen other calls to $this->_associations (e.g. in beforeRender()) with whatever value passed there, first handled with array_keys. Not sure what's the logic there, so won't suggest any solution. Will keep the hotfix for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant