-
-
Notifications
You must be signed in to change notification settings - Fork 156
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
Add a universal table picker #714
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, just a few minor details that could be improved but without an impact on the picker itself.
As briefly discussed in Slack with @aschempp, we could add an universal picker provider for all pickers that return a database ID. |
@leofeyer I think we can merge this if there's no more feedback. I'll create a separate PR for the universal picker provider. |
1ce1291
to
b1eeebb
Compare
PR updated with a universal picker provider to pick any DC record 🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM except for missing tests. I think they might influence the outcome again so I'll approve once this PR is completely ready.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the latest changes, however, the AbstractDataContainerPickerProvider
class does not really make sense to me. It contains a lot of code that is only required for DC_Table
and that would have to be overwritten to make it work with other DCAs.
I would prefer not to have an abstract class. Just rename it to TablePickerProvider
and we are all set.
How come you think that? Every custom DC I ever implemented did extend DC_Table and adjusted some fields. I don't think it's better to extend the |
You should not extend the An abstract class should contain code that is used by 90% of their child classes. In this case, however, only about 20% of the code is relevant for a folder picker, which indicates that the abstract class is too concrete. 🤷♂ |
0d70517
to
d16a28f
Compare
Thank you @aschempp. |
@aschempp I am trying to gather some documentation for this. However I noticed some discrepancies with the original description in this issue. If I try to implement a news picker like this: // contao/dca/tl_content.php
use Contao\CoreBundle\DataContainer\PaletteManipulator;
$GLOBALS['TL_DCA']['tl_content']['fields']['news'] = [
'label' => ['News', 'Choose a news article.'],
'foreignKey' => 'tl_news.headline',
'inputType' => 'picker',
'eval' => ['tl_class' => 'clr'],
'sql' => ['type' => 'integer', 'unsigned' => true, 'default' => 0],
];
PaletteManipulator::create()
->addField('news', 'text', PaletteManipulator::POSITION_AFTER)
->applyToPalette('text', 'tl_content')
; Then the following error will occur:
However if I then add a relation with // contao/dca/tl_content.php
use Contao\CoreBundle\DataContainer\PaletteManipulator;
$GLOBALS['TL_DCA']['tl_content']['fields']['news'] = [
'label' => ['News', 'Choose a news article.'],
'inputType' => 'picker',
'eval' => ['tl_class' => 'clr'],
'sql' => ['type' => 'integer', 'unsigned' => true, 'default' => 0],
'relation' => ['type' => 'hasOne', 'load' => 'lazy', 'table' => 'tl_news'],
];
PaletteManipulator::create()
->addField('news', 'text', PaletteManipulator::POSITION_AFTER)
->applyToPalette('text', 'tl_content')
; Is this correct? |
hmm. Did you build the internal cache? The relation table should be taken from the |
No, the error was taken from the |
Can you try if it works with the cache? Then maybe that's the problem… Anyway, looks like it deserves a bug report to me 😉 |
Right, but seeing as it works just with the relation... what advantages would the |
The table relations fall back to foreignKey, so our picker should do that as well. |
Replaces contao/core-bundle#1171 and contao/core-bundle#999
It's basically the same implementation as by @qzminski. It also adds a picker for articles and content elements in the respective content elements.
Example configuration:
Contrary to contao/core-bundle#1171, the
foreignKey
attribute is used to generate the value from the regular DCA callbacks. If that's not the desired result, implement a custom widget that takes over the rendering.FYI this does not mean that any DCA table can be picked, it still always needs a valid picker provider.Now added a universal picker provider that can select from any DCA table 🎉