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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the insert tags in picker providers configurable #450

Open
wants to merge 3 commits into
base: master
from

Conversation

Projects
None yet
3 participants
@Toflar
Copy link
Member

commented Apr 24, 2019

I just had the problem that I wanted to use the page picker but not with the default {{link_url::<value>}} insert tag because I need absolute links, so I want the |absolute flag to always be added.
I noticed that the insert tag is unfortunately hard coded which I find a very limiting factor for a general picker provider.
So here we go, you can now specify whatever insert tag you like by specifying

'eval' => [
    'dcaPicker' => [
        'insertTag' => '{{my_super_insert_tag::%s}}',
    ],
],

which will take the insert tag for all picker providers (news, page etc.), though.
However, you can also do this:

'eval' => [
    'dcaPicker' => [
        'pagePicker' => [
            'insertTag' => '{{link_url::%s}}',
        ],
        'newsPicker' => [
            'insertTag' => '{{news_url::%s}}',
        ],
    ],
],

I've implemented it for all the core pickers so it will also work for news, faq, events etc. not just for the page picker provider 馃槉
Also there's a new $config->getExtraForProvider() so pickers can implement fetching provider specific extras falling back to general extras if they want to.

@Toflar Toflar force-pushed the Toflar:picker-configurable-inserttag branch 2 times, most recently from 136b258 to 1bafbe6 Apr 24, 2019

@Toflar Toflar force-pushed the Toflar:picker-configurable-inserttag branch from 1bafbe6 to 9ee3835 Apr 24, 2019

@Toflar

This comment has been minimized.

Copy link
Member Author

commented Apr 25, 2019

I just noticed an issue here. I need to be able to specify the extras to be only applicable for e.g. the page picker but not the news picker.
How do I do that? @contao/developers

@leofeyer leofeyer closed this Apr 25, 2019

@leofeyer leofeyer reopened this Apr 25, 2019

@Toflar

This comment has been minimized.

Copy link
Member Author

commented Apr 26, 2019

Updated PR to support extras per provider and also updated the issue description to demonstrate the usage 馃槃

@leofeyer leofeyer added the feature label Apr 30, 2019

@leofeyer leofeyer added this to the 4.8.0 milestone Apr 30, 2019

@@ -45,7 +47,9 @@ public function supportsContext($context): bool
*/
public function supportsValue(PickerConfig $config): bool
{
return false !== strpos($config->getValue(), '{{event_url::');
$insertTagChunks = explode('%s', $this->getInsertTag($config, self::DEFAULT_INSERTTAG), 2);

This comment has been minimized.

Copy link
@leofeyer

leofeyer Apr 30, 2019

Member

Can we encapsulate this in a getInsertTagChunk() method so we do not have to use multiple explode() calls?

This comment has been minimized.

Copy link
@Toflar

Toflar May 1, 2019

Author Member

I'm not even sure if that should be named insertTag or if that should be something else? I mean, in fact it's just whatever string you want to provide and we're going to replace '%s' with the value. I just don't know if there's any other use case other than an insert tag 馃槃 wdyt?

This comment has been minimized.

Copy link
@leofeyer

leofeyer May 2, 2019

Member

I just don't know if there's any other use case other than an insert tag

I cannot think of one.

This comment has been minimized.

Copy link
@Toflar

Toflar May 2, 2019

Author Member

Done 馃槃

@Toflar Toflar force-pushed the Toflar:picker-configurable-inserttag branch from dc5d0b4 to 51f997d May 2, 2019

@aschempp

This comment has been minimized.

Copy link
Contributor

commented May 6, 2019

Instead of splitting the default inserttag by %s, why not simply store the prefix + suffix in the class constant? Or even more so have a _PREFIX and _SUFFIX?

@Toflar

This comment has been minimized.

Copy link
Member Author

commented May 7, 2019

Because it makes no sense to me. %s as the placeholder for sprintf() is well known so I don't really want to configure a value prefix and suffix in the dca configuration.

@aschempp

This comment has been minimized.

Copy link
Contributor

commented May 7, 2019

I don't really want to configure a value prefix and suffix in the dca configuration.

Yeah, I would configure an array with two values for that case. I don't see why we would need to split on every use instead of already having an array.

* Provides a shortcut get the "insertTag" extra value for child classes and
* split them at the placeholder (%s).
*/
protected function getInsertTagChunks(PickerConfig $config, string $default): array

This comment has been minimized.

Copy link
@leofeyer

leofeyer Jun 5, 2019

Member

Can we not set a default value for the second argument?

string $default = static::DEFAULT_INSERTTAG

Due to the late static binding, this should be set to the value of the constant of the child class.

This comment has been minimized.

Copy link
@Toflar

Toflar Jun 5, 2019

Author Member

And what if I forget to set this in my child? I would only notice it at runtime which makes the whole idea of an abstract class and interfaces pointless 馃槃

This comment has been minimized.

Copy link
@leofeyer

leofeyer Jun 5, 2019

Member

It would use the constant of the parent class then.

This comment has been minimized.

Copy link
@Toflar

Toflar Jun 5, 2019

Author Member

Which does not exist because what value would it provide? 馃槃

This comment has been minimized.

Copy link
@leofeyer

leofeyer Jun 5, 2019

Member

Ok, then why did you make the constant protected instead of private? Also, the naming is misleading: DEFAULT_INSERTTAG implies that there are constants for other, non-default insert tags, which there are not. We should change it to just INSERTTAG.

This comment has been minimized.

Copy link
@Toflar

Toflar Jun 6, 2019

Author Member

So that they can be replaced by a class extending a specific picker? I don't think the name is misleading, it's the default insert tag if no other configuration was provided.

@leofeyer

This comment has been minimized.

Copy link
Member

commented Jun 5, 2019

I just noticed an issue here. I need to be able to specify the extras to be only applicable for e.g. the page picker but not the news picker.

Is this still an unsolved problem?

@Toflar

This comment has been minimized.

Copy link
Member Author

commented Jun 5, 2019

Is this still an unsolved problem?

Bildschirmfoto 2019-06-05 um 13 45 37

@leofeyer leofeyer force-pushed the contao:master branch 2 times, most recently from 6c52109 to 03f6899 Jun 5, 2019

@leofeyer leofeyer force-pushed the contao:master branch from 67bdc5c to d42ccf4 Jun 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can鈥檛 perform that action at this time.