Closed qzminski closed 5 years ago
Couldn’t this be achieved by setting 'beTemplate' => 'be_wildcard'
and add a line that sets $this->wildcard
in https://github.com/madeyourday/contao-rocksolid-custom-elements/blob/2ffd50ecb4d3f900f75552f2554a66b0a5c14ad5/src/Element/CustomElement.php#L95-L98
Likely yes, but this way it's more simpler IMO ☺️ note that you also have to get the translated label, then Utf8::strtoupper
it etc.
How about updating the code to this:
if (!empty($config['beTemplate'])) {
if (!isset($this->arrData['wildcard'])) {
$label = CustomElements::getLabelTranslated($config['label'])
$this->arrData['wildcard'] = '### ' . Utf8::strtoupper(is_array($label) ? $label[0] : $label) . ' ###';
}
$this->strTemplate = $config['beTemplate'];
return null;
}
This way you could also use a custom be_wildcard
template and still use the wildcard
label in your template.
Looks good to me apart from the fact that parent::generate()
is called unnecessary. @aschempp what do you think?
I don't think it makes sense to generate the whole element in the back end?
But that’s how content elements work in contao?
I don’t like to add too many config flags, especially if they contradict each other. What if beTemplate
and showBackendWildcard
is set?
I think 'beTemplate' => 'be_wildcard'
is a better way to solve this. And if we add the code from above it would result in the exact same output.
But that’s how content elements work in contao?
If a frontend module or a content element displays a wildcard immediately without calling the parent method, e.g. https://github.com/contao/contao/blob/master/news-bundle/src/Resources/contao/modules/ModuleNewsList.php#L51
That's why I think it's better to do the same instead of calling parent::generate()
which we don't need at all.
I think 'beTemplate' => 'be_wildcard' is a better way to solve this. And if we add the code from above it would result in the exact same output.
Then maybe we can automatically generate and return a wildcard if beTemplate === be_wildcard
?
But parent::generate()
does basically do the same, it creates a template, sets the data on it and calls parse()
on it. That shouldn’t be too much overhead I think.
Additionally it has the benefit of having access to the whole data of the element inside the backend template.
Then maybe we can automatically generate and return a wildcard if
beTemplate === be_wildcard
?
That would make 'beTemplate' => 'be_wildcard_custom'
behave differently then 'beTemplate' => 'be_wildcard'
which is probably not a good idea.
Okay you convinced me. Shall I update the code or you'll take care?
I’ll take care. Thanks!
Thank YOU 🙂
I’ve added the changes to this PR, this should make 'beTemplate' => 'be_wildcard'
work as expected.
Can you confirm that my implementation works for your use case?
'beTemplate' => 'be_wildcard',
does the job, thank you @ausi!
❤️
Simply by setting the correct flag:
/cc @aschempp