-
-
Notifications
You must be signed in to change notification settings - Fork 169
Fix order of parameters in AsContentElement and AsFrontendModule constructors #4065
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
Conversation
b61e55f to
6df2476
Compare
|
I would kinda prefer @ausi's solution in #4055 (comment) The goal should be to work the same as annotatinos did, so to use named paramters (I know we can't enforce that). Either write or write if you have a type. Making category default null and throw an exception would solve that. |
|
@m-vo Will you update this PR accordingly? |
|
I’d prefer something that works so that my IDE shows me if something is missing or what will happen. IMO only the following two possibilities accomplish that: With |
|
I‘d be fine with |
|
But then you could omit all parameters and the element would appear in the text category (why text?). I'm ok with that, but I think I would prefer a solution without adding magic. |
|
Why don‘t we just make __construct(string $type, string $category, …The maker bundle will always set the type anyway: contao/maker-bundle/src/Resources/skeleton/content-element/ContentElement.tpl.php Lines 18 to 20 in f577f1e
|
In my opinion it's a good thing, that the type is inferred by default, because it promotes a common naming scheme. And I don't want to type it when creating fragments myself. 🙂 |
|
We should also discuss the usage of the variadic parameter. |
|
I usually always end up using /**
* @ContentElement(MyContentElement::TYPE, category="texts")
*/
class MyContentElement extends AbstractContentElementController
{
public const TYPE = 'my_content_element';
}so that I can reference the type in the DCA for example. |
👍 for constants, that can be automatically refactored. Maybe the FQCN should get the default type in the future? Other aspect: We currently use the type to identify templates, but with Twig there is no point in injecting a If we want to alter the behavior in Contao 5, we could maybe already prepare this in 4.13 when using attributes. |
leofeyer
left a comment
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.
As discussed in the Contao call, we want to use miscellaneous as default category for both (!) content elements and front end modules. Also, we want to change array ...$attributes to mixed ...$attributes.
|
The changes are now implemented as discussed. Because we're now in a situation, where it's required to use named arguments to set arbitrary keys, I had to use some trickery in the tests, so that jobs < PHP8 would not result in a syntax error. If there is a better solution, let me know. |
new AsContentElement(...[
'type' => 'content_element/text',
'template' => 'a_template',
'method' => 'aMethod',
'renderer' => 'inline',
'foo' => 'bar',
'baz' => 42,
]);https://3v4l.org/3mVUg |
core-bundle/tests/DependencyInjection/ContaoCoreExtensionTest.php
Outdated
Show resolved
Hide resolved
Co-authored-by: Martin Auswöger <[email protected]>
|
Thank you @m-vo. |
Fixes #4055
This PR swaps the first two parameters of the
AsContentElementandAsFrontendModuleconstructors. This was not released yet, so no BC issue.Background info: As of PHP8.0 having optional parameters before mandatory ones is deprecated. Here is an explanation why the current code did not trigger a deprecation warning and behaved just like two mandatory parameters: php/php-src#5067 (comment)