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

Universal picker #714

Open
wants to merge 4 commits into
base: master
from

Conversation

@aschempp
Copy link
Contributor

commented Sep 3, 2019

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:

$GLOBALS['TL_DCA']['tl_module']['fields']['article'] = [
    'label' => &$GLOBALS['TL_LANG']['tl_module']['article'],
    'exclude' => true,
    'foreignKey' => 'tl_article.title',
    'inputType' => 'picker',
    'eval' => [
        'context' => 'article', // Context for picker
        'fieldType' => 'radio', // Field type (optional, defaults to radio)

        //'fieldType'    => 'checkbox',
        //'orderField'     => 'articleOrder',
    ],
    'sql' => ['type' => 'integer', 'unsigned' => true],
];

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.

@aschempp aschempp added the feature label Sep 3, 2019

@aschempp aschempp added this to the 4.9 milestone Sep 3, 2019

@aschempp aschempp requested review from Toflar and leofeyer Sep 3, 2019

@aschempp aschempp self-assigned this Sep 3, 2019

@@ -65,6 +65,9 @@
<trans-unit id="MSC.eventPicker">
<source>Events</source>
</trans-unit>
<trans-unit id="MSC.eventContentPicker">
<source>Events</source>

This comment has been minimized.

Copy link
@leofeyer

leofeyer Sep 3, 2019

Member

Is there no way to re-use MSC.eventPicker here?

This comment has been minimized.

Copy link
@aschempp

aschempp Sep 20, 2019

Author Contributor

Not sure 🤷‍♂ it's a different picker, so it should have a different label. Then again, the tab/label actually represents the back end module, not the picker implementation…

->where($qb->expr()->eq('id', $config->getValue()))
;
if ($qb->execute()->fetchColumn() === $this->getParentTable()) {

This comment has been minimized.

Copy link
@leofeyer

leofeyer Sep 3, 2019

Member

This can be simplified to return $qb->execute()->fetchColumn() === $this->getParentTable(), can't it?

return (int) $val;
};
$attributes['value'] = array_map($intval, explode(',', $value));

This comment has been minimized.

Copy link
@leofeyer

leofeyer Sep 3, 2019

Member

This should be array_map('\intval' ….

This comment has been minimized.

Copy link
@aschempp

aschempp Sep 20, 2019

Author Contributor

jup, no idea why thats present in the other pickers. Fine with me to change 😂

return (int) $val;
};
$attributes['value'] = array_map($intval, explode(',', $value));

This comment has been minimized.

Copy link
@leofeyer

leofeyer Sep 3, 2019

Member

This should be array_map('\intval' ….

@@ -84,8 +109,12 @@ public function getDcaAttributes(PickerConfig $config): array
/**
* {@inheritdoc}
*/
public function convertDcaValue(PickerConfig $config, $value): string
public function convertDcaValue(PickerConfig $config, $value)

This comment has been minimized.

Copy link
@leofeyer

leofeyer Sep 3, 2019

Member

Why did you remove the return type?

This comment has been minimized.

Copy link
@aschempp

aschempp Sep 20, 2019

Author Contributor

because it can be an integer as well now

@@ -1254,15 +1261,37 @@ public function getArticleAlias(Contao\DataContainer $dc)
return $arrAlias;
}
/**
* Saves the article alias

This comment has been minimized.

Copy link
@leofeyer

leofeyer Sep 3, 2019

Member

This does not seem to match what the method does, does it?

*
* @return mixed
*/
public function saveAlias($varValue, DataContainer $dc)

This comment has been minimized.

Copy link
@leofeyer

leofeyer Sep 3, 2019

Member

This method seems duplicate?

This comment has been minimized.

Copy link
@aschempp

aschempp Sep 20, 2019

Author Contributor

It's not, it's $dc->activeRecord->pid vs. $dc->activeRecord->id

@@ -1385,6 +1388,9 @@
<trans-unit id="MSC.articlePicker">
<source>Articles</source>
</trans-unit>
<trans-unit id="MSC.articleContentPicker">
<source>Articles</source>

This comment has been minimized.

Copy link
@leofeyer

leofeyer Sep 3, 2019

Member

Can we re-use MSC.articlePicker here?

This comment has been minimized.

Copy link
@aschempp

aschempp Sep 20, 2019

Author Contributor

🤷‍♂

@@ -35,6 +35,9 @@
<trans-unit id="MSC.newsPicker">
<source>News</source>
</trans-unit>
<trans-unit id="MSC.newsContentPicker">
<source>News</source>

This comment has been minimized.

Copy link
@leofeyer

leofeyer Sep 3, 2019

Member

Re-using MSC.newsPicker anyone?

@Toflar
Copy link
Member

left a comment

LGTM 👍

@aschempp aschempp requested a review from qzminski Sep 4, 2019

{
if ('article' === $config->getContext()) {
return (int) $value;

This comment has been minimized.

Copy link
@qzminski

qzminski Sep 4, 2019

Member

I think it should return always the same type so convert this one to a string rather than to an integer. Then you could restore the return type above.

This comment has been minimized.

Copy link
@aschempp

aschempp Sep 5, 2019

Author Contributor
$strKey = 'pageTree';
break;
case 'reloadFiletree':

This comment has been minimized.

Copy link
@qzminski

qzminski Sep 4, 2019

Member

No need for it as it fallbacks to default anyway.

This comment has been minimized.

Copy link
@aschempp

aschempp Sep 5, 2019

Author Contributor

I like it to be more explicit. One can read in the code what other case there is.

@qzminski
Copy link
Member

left a comment

Looks good to me, just a few minor details that could be improved but without an impact on the picker itself.

@leofeyer

This comment has been minimized.

Copy link
Member

commented Sep 19, 2019

As briefly discussed in Slack with @aschempp, we could add an universal picker provider for all pickers that return a database ID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.