-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
[RTM] Added PaletteManipulator #474
[RTM] Added PaletteManipulator #474
Conversation
Cool stuff! I do think, you should not use static methods though. $pm = new PaletteManipulator();
$pm->append('feed_legend', 'calendarfeeds'); works just as well as the static methods. But compared to the static API it e.g. allows us to think about adding a service for it (a factory service) so we can inject it into other services. When I think about the fact that we want to have YAML for dca files one day, I'll need a service that handles my palette manipulation. Also see symfony/symfony#15850 why Symfony has changed the CSS Selector API. |
I disagree.
No idea how to solve YAML, but I don't think that should be related. This is just a helper class for our current "broken" palette problem, I would probably not use a string for palettes in YAML :D |
I like it. |
While I like the overall approach for making things more easy, I feel like it is guiding people in the wrong direction. I mean, the long term goal is to have DCA file contain simple "information" about the table structure and edit masks. This "simple information" should be able to be contained in YAML and all other things. Therefore I second the statement by @Toflar above, this has to be transformed into an service and/or preprocessor. Aside from these concerns, I think it should have a more fluent interface, like the config builder. // CalendarBundle/Resources/contao/dca/tl_content.php
$GLOBALS['TL_DCA']['tl_layout']['palettes']['default'] =
// Create a new manipulator
PaletteManipulator::create()
// we want to manipulate the feed_legend
->manipulateLegend('feed_legend')
// if that one is not found, we want special handling.
->ifLegendNotFound()
// we want to create it.
->createLegend('feed_legend')
// we want it after the picturefill_legend.
->after('picturefill_legend')
// the inital state shall be hidden ("xyz_legend:hide")
->hidden()
// end of not found handling
->end()
// end of legend not found
->end()
// append the field to the legend.
->appendField('calendarfeeds')
// end legend handling
->end()
// finally apply everything to the passed palette
->applyTo($GLOBALS['TL_DCA']['tl_layout']['palettes']['default']) Using such an approach, seems more intuitive. It could even eventually be defined in any compiler pass which processes the DCAs before caching (long term goal). |
As briefly discussed on Mumble, this is what we want: PaletteManipulator::create()
->addLegend('legend', 'afterThisLegend') // or at the end
->addLegend('legend', ['afterThisLegend', 'orAfterThisLegend']) // or at the end
->addField('field', 'afterField', 'orAtTheEndOfThisLegend') // add the legend if it does not exist
->addField('field', ['afterThisField', 'orThisField'], 'orAtTheEndOfThisLegend') // add the legend if it does not exist
->addField(['thisField', 'andThisField'], 'afterField', 'orAtTheEndOfThisLegend') // add the legend if it does not exist
->addField(['thisField', 'andThisField'], ['afterThisField', 'orThisField'], 'orAtTheEndOfThisLegend') // add the legend if it does not exist
->applyToPalette('thisPalette', 'table')
->applyToPalette('thatPalette', 'table')
->applyToSubpalette('thisSubpalette', 'table')
; |
Just a small reminder: Pls consider manipulating subpalettes too. So maybe |
I also changed |
I've rewritten everything based on our feedback. Now 🍻 |
happy 🍻 ! :) |
Looks waaaay better!!! :) I'm happy now. Almost :D |
Yeah, and someone should write 1000 unit tests for all possible cases :D |
I've changed everything to |
Merged in d15585c. |
FYI I'm not very happing with your merge. You removed a lot of my comments on how methods and arguments work, and I don't think thats a good thing… |
AFAIR, I only shortened the comments and did not remove them. |
Also, I had to fix several CS and code duplication issues. Actually, I still am on it right now. |
Yeah, you shortened a lot: 5155f16#diff-dcb2151bb12749e152bdd80279ed8d0fL67 |
Btw. we recently also discussed not to add useless names for variables like in 5155f16#diff-dcb2151bb12749e152bdd80279ed8d0fR334 |
Yes, we have discussed it but we have not agreed on anything. If we agree on skipping the description, we would need to remove it everywhere and not just in a single class (consistency!). |
I was able to refactor the methods so there is no more code duplication and there are no more C rated methods. However, the class itself is still C rated (the only C rated class in the new code), because it is much too complex. And I don't really like that :) |
I'm not gonna discuss that, that's just silly… |
Well, of course we should keep comments as descriptive as possible. Where's the point of comments when they do not make sense? This is btw. the only downside I see with Symfony, their class comments are next to useless. In order to drop the class rating from C to A, I'm afraid, we will need to refactor it to a bunch builder classes, which you have already decided against. |
Extracting the A reasonable thing to do IMHO, but @aschempp is not willing to discuss today. |
PaletteManipulator
is finally a helper tool to add fields in existing DCA palettes. It handles the following cases:It is intentionally kept as simple as possible. I did not want to introduce object-oriented palettes, as I doubt that would be backwards compatible. The class is simply a helper to string replace.
I'm actually in need of such a tool to continue working on #471. There's a field
tl_layout.calendarfeeds
andtl_layout.newsfeeds
which should not be incore-bundle
(see https://github.com/contao/core-bundle/blob/master/src/Resources/contao/dca/tl_layout.php#L100).Example how to add
tl_layout.calendarfeeds
fields:What it does:
calendarfeeds
(could also be an array of fields) to legendfeed_legend
.feed_legend
with new fields afterpicturefill_legend