Skip to content
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

Set a default type for each article type #473

Open
antoinemineau opened this issue May 12, 2020 · 14 comments
Open

Set a default type for each article type #473

antoinemineau opened this issue May 12, 2020 · 14 comments
Labels
Feature New functionality not yet included

Comments

@antoinemineau
Copy link

antoinemineau commented May 12, 2020

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
Copy link

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
Copy link
Contributor

niklasnatter commented May 22, 2020

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
Copy link
Contributor

+1

1 similar comment
@manuxi
Copy link

manuxi commented Jun 15, 2020

+1

@jordygroote
Copy link

I am experiencing this issue :) +1

@jordygroote
Copy link

jordygroote commented Jun 18, 2020

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
Copy link

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
Copy link

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
Copy link

@jordygroote yes, your yaml

@jordygroote
Copy link

jordygroote commented Jun 29, 2020

@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
Copy link
Contributor

niklasnatter commented Jul 2, 2020

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
Copy link

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
Copy link

almare commented Sep 2, 2020

Perfect, thank you for sharing this

@alexander-schranz
Copy link
Member

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 alexander-schranz added the Feature New functionality not yet included label Mar 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New functionality not yet included
Projects
None yet
Development

No branches or pull requests

9 participants