sulu / SuluArticleBundle

Bundle for managing localized content-rich entities like blog-posts in the Sulu content management system
MIT License
56 stars 77 forks source link

Set a default type for each article type #473

Open antoinemineau opened 4 years ago

antoinemineau commented 4 years ago

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"
man-andy commented 4 years ago

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

niklasnatter commented 4 years ago

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.

martinlagler commented 4 years ago

+1

manuxi commented 4 years ago

+1

jordygroote commented 4 years ago

I am experiencing this issue :) +1

jordygroote commented 4 years ago

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.

mavimedia commented 4 years ago

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?

jordygroote commented 4 years ago

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?

mavimedia commented 4 years ago

@jordygroote yes, your yaml

jordygroote commented 4 years ago

@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

niklasnatter commented 4 years ago

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.

jordygroote commented 4 years ago

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!

almare commented 4 years ago

Perfect, thank you for sharing this

alexander-schranz commented 3 years ago

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.