SuluArticleBundle icon indicating copy to clipboard operation
SuluArticleBundle copied to clipboard

Set a default type for each article type

Open antoinemineau opened this issue 4 years ago • 14 comments

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"

antoinemineau avatar May 12 '20 15:05 antoinemineau

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

man-andy avatar May 13 '20 07:05 man-andy

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.

niklasnatter avatar May 22 '20 14:05 niklasnatter

+1

martinlagler avatar Jun 15 '20 12:06 martinlagler

+1

manuxi avatar Jun 15 '20 12:06 manuxi

I am experiencing this issue :) +1

jordygroote avatar Jun 18 '20 08:06 jordygroote

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.

jordygroote avatar Jun 18 '20 08:06 jordygroote

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?

mavimedia avatar Jun 28 '20 20:06 mavimedia

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 avatar Jun 28 '20 20:06 jordygroote

@jordygroote yes, your yaml

mavimedia avatar Jun 29 '20 08:06 mavimedia

@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

jordygroote avatar Jun 29 '20 10:06 jordygroote

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.

niklasnatter avatar Jul 02 '20 10:07 niklasnatter

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!

jordygroote avatar Jul 02 '20 18:07 jordygroote

Perfect, thank you for sharing this

almare avatar Sep 02 '20 09:09 almare

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.

alexander-schranz avatar Mar 12 '21 13:03 alexander-schranz