SuluArticleBundle
SuluArticleBundle copied to clipboard
Set a default type for each article type
It should be possible to define a default type for each article type. At the moment, you can only set one default type for all article types which is a problem when using tabs. When you create an article, it doesn't select a default type. This error is displayed in the console browser:
metadataStore.js:37 Uncaught (in promise) Error: Type "default" not found for the formKey "article"
IMO it's a missing feature in the article-bundle, because it should be possible to define a default type for each article type. But it's a bug in sulu, because the first available template should be used as default template, if the configured default template can't be found. ~ Luca
Just for completeness, it should be possible to create an article by selecting the correct template in the template dropdown of the toolbar, even if an error is printed to the browser console 🙂
Obviously, this is not the desired behaviour. It should be possible to set a default type per article type IMO.
+1
+1
I am experiencing this issue :) +1
I temporary fixed it by setting the default type to the first key in the array.
In Sulu\Bundle\AdminBundle\Controller\AdminController
metadataAction.
if (method_exists($metadata, 'getForms')) {
if (!array_key_exists($metadata->getDefaultType(), $metadata->getforms())) {
if (count($metadata->getForms())) {
$metadata->setDefaultType(array_key_first($metadata->getForms()));
}
}
}
In my case this fixes the issue because the defaultTemplate has to be set to the only type in the array.
Just wanted to drop this here, hopefully this doesn't create confusion.
if (method_exists($metadata, 'getForms')) { if (!array_key_exists($metadata->getDefaultType(), $metadata->getforms())) { if (count($metadata->getForms())) { $metadata->setDefaultType(array_key_first($metadata->getForms())); } } }
How does your config look like?
if (method_exists($metadata, 'getForms')) { if (!array_key_exists($metadata->getDefaultType(), $metadata->getforms())) { if (count($metadata->getForms())) { $metadata->setDefaultType(array_key_first($metadata->getForms())); } } }
How does your config look like?
What config do you mean? The YAML?
@jordygroote yes, your yaml
@jordygroote yes, your yaml
Like this:
sulu_core:
content:
structure:
default_type:
article: 'group'
The default type is group
. But when adding a offer
i set the default type to be offer
in the Sulu\Bundle\AdminBundle\Controller\AdminController
If you need help you can contact me on SULU slack
Hey everybody,
we did not find a solution to allow for setting default templates based on the article type yet. As a partial solution, version 2.1.0 of the bundle makes the default template configuration optional. This means that you can remove the following config from your config/packages/sulu_article.yaml
:
sulu_core:
content:
structure:
default_type:
article: "default"
After removing this config (and clearing the cache of the application), you should be able to create new articles without any errors. Sulu should automatically select the first template of the selected article type as default.
Hey everybody, we did not find a solution to allow for setting default templates based on the article type yet. As a partial solution, version 2.1.0 of the bundle makes the default template configuration optional. This means that you can remove the following config from your
config/packages/sulu_article.yaml
:sulu_core: content: structure: default_type: article: "default"
After removing this config (and clearing the cache of the application), you should be able to create new articles without any errors. Sulu should automatically select the first template of the selected article type as default.
Thanks for fixing this!
Perfect, thank you for sharing this
There is a error related to this if you upgraded and forget to remove the default_type you will run into the "Missing type" dialog now instead of an hard error. So its important to not set the default_type when you are using multiple article types.