-
-
Notifications
You must be signed in to change notification settings - Fork 165
Add a Palette helper to support working with PaletteManipulator #8302
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
base: 5.x
Are you sure you want to change the base?
Conversation
I'm not sure this is a good idea. The
Checking for the existance of a field should be rather simple, maybe we could just provide helpers for that if really necessary? |
Yeah, this is exactly what I want? If I have an existing palette and want to apply this to another, I can do now. Why would I not want this? I have grid configuration that consists of 10 fields (dynamically, sometimes it's 5 depending on the type) and then I want to add that to an existing palette. Works perfectly like this. |
What do you mean by apply this to another? |
Why does that make no sense? For a new content element I basically always copy & paste the one from |
You want a class to parse a string and rebuild it with new fields instead of just writing a string into your DCA? 😮 |
Yes 👍 |
Yes of course! This is the whole purpose of the palette_callback: #[AsCallback('tl_content', 'config.onpalette')]
public function onPaletteCallback(string $palette, DataContainer $dc): string
{
$pm = PaletteManipulator::fromString($palette);
if ($pm->hasField('my_field')) {
$pm->addField('field_one,field_two,field_three', 'my_field');
}
return $pm->applyToString($palette);
} |
Now you can even simplify this to #[AsCallback('tl_content', 'config.onpalette')]
public function onPaletteCallback(string $palette, DataContainer $dc): string
{
$pm = PaletteManipulator::fromString($palette);
if ($pm->hasField('my_field')) {
$pm->addField('field_one,field_two,field_three', 'my_field');
}
return $pm->asString();
} |
As discussed in the call, @aschempp will think again to see if he can come up with a better solution, but otherwise we'll merge the PR as it is. |
How about adding a class $pm = new PaletteManipulator();
$palette = Palette::fromString($paletteString);
if ($palette->hasField('my_field')) {
$pm->addField('field_one,field_two,field_three', 'my_field');
}
return $pm->applyToPalette($palette)->toString(); The parsing logic could then be moved to the Just a suggestion |
I thought about that too, would that be okay for you @aschempp? |
04f7619
to
2d8e79f
Compare
Gave this a try in 2d8e79f. Now the The only little strange thing is that you have to call |
I was actually thinking about this PR just now and poking around in some code, coming up with the I do however think that the config array of the Let me know if you want me to contribute 🙃 |
Yes please :) |
see Toflar#19 |
# Conflicts: # core-bundle/src/DataContainer/PaletteManipulator.php
PR ready for review again. |
I wanted to create this PR for years, now I finally did it. I very often find myself modifying palettes in the
palette_callback
but thePaletteManipulator
lacks the options to create an instance based on a string and you also cannot ask if there's a legend or a field present. So I always have to resort tostr_contains()
which can of course fail if fields start with the same prefix etc.So finally, here we go 😅