I am trying to learn Umbraco, so I am very new to it. I am sure, that there is a simple answer for my question.
I try to fill up a dropdown box in a content edit form with values, as the user have defined in a Document Type Collection in the context menu (not sure if I am using the right terms here)
Just for understanding of my task, the user of the site, can create their own business categories, that should be visible in a dropdown box. So when the user wants to define a company, the user can choose between different business types for the company.
I have defined a IUserComponent and a IComponent to inject Umbraco when it starts up, and that is working just fine. But when I am going to read the values from the collections, I can not find out, how to read the collection list.
public class InitDropDownComponent : IComponent
{
private readonly IContentService _contentService;
private readonly IContentTypeService _contentTypeService;
private readonly ServiceContext _serviceContext;
public void Initialize()
{
BusinessCategories();
}
public void Terminate()
{
}
public InitDropDownComponent(IContentService contentService, IContentTypeService contentTypeService, ServiceContext serviceContext)
{
_contentService = contentService;
_contentTypeService = contentTypeService;
_serviceContext = serviceContext;
}
public void BusinessCategories()
{
var businessCategoriesContent = _contentTypeService.Get(Guid.Parse("3d988d58-609c-452c-bb37-e600564751ba"));
IEnumerable<IContentType> contentTypes = _contentTypeService.GetAll();
IEnumerable<IContentType> contentTypes2 = _contentTypeService.GetChildren(Guid.Parse("3d988d58-609c-452c-bb37-e600564751ba"));
var contentTypes3 = _contentTypeService.GetChildren(1378);
EntityContainer container = _contentTypeService.GetContainer(1378);
var fff = _contentTypeService.GetAllElementTypes();
var content = _contentTypeService.Get(Guid.Parse("3d988d58-609c-452c-bb37-e600564751ba")) as IPublishedContent;
var content2 = _serviceContext.ContentService.GetById(1378) as IPublishedContent;
}
I got confused when to use IContentService, IContentTypeService and the ServiceContext or is it the right interfaces for this.
And may be there is a smarter way of doing a task like this, I don't know. Hope someone can bring me in the right direction
It's not clear to me where the dropdown will be presented?
If I understand correctly, editors will be able to login to the backoffice of Umbraco and create new content items, that will represent Business Categories of some kind.
And these business categories need to be used in a dropdown.
But what I'm not sure is if this dropdown is on another content type in the Umbraco backoffice?
so editors will again login to Umbraco, create a new kind of thing, a blog post maybe, and then choose from a dropdown list one of these categories?
or
whether this is a form on the front end of the site, that visitors rather than editors will fill in, and the dropdown list needs to be populated from Umbraco?
If it is the backoffice dropdown you are after, then have a look at the contentment package: https://our.umbraco.com/packages/backoffice-extensions/contentment/ this has got loads of good things in, but one of them is the ability to define a dropdown from a source of Umbraco content items, to use as an editor in the backoffice.
If it's the front end the dropdown will be on, then your View that displays your form, will have access to Umbraco content via the UmbracoHelper:
And this can be used to retrieve the options from the published Umbraco cache. You only really should use the services, eg ContentService and ContentTypeService when actioning CRUD interactions, like importing content from another source - as they will hit the database directly.
Fantastic, I know that my question where very confusing, think that it was because my head were very confusing about this issue also. And also difficult to explain, when you are new to Umbraco terms.
The contentment package datalist where just what I was looking for. I would like to build up some kind of entity relationship between the content types.
I am looking forward to see, how it save the relation, but just want to answer you first, and tell you, that you just hit it on the spot - thanks a lot man, you saved my Christmas - ha ha.
fillup a dropdown box, with custom made values
I am trying to learn Umbraco, so I am very new to it. I am sure, that there is a simple answer for my question.
I try to fill up a dropdown box in a content edit form with values, as the user have defined in a Document Type Collection in the context menu (not sure if I am using the right terms here)
Just for understanding of my task, the user of the site, can create their own business categories, that should be visible in a dropdown box. So when the user wants to define a company, the user can choose between different business types for the company.
I have defined a IUserComponent and a IComponent to inject Umbraco when it starts up, and that is working just fine. But when I am going to read the values from the collections, I can not find out, how to read the collection list.
public class InitDropDownComponent : IComponent { private readonly IContentService _contentService; private readonly IContentTypeService _contentTypeService; private readonly ServiceContext _serviceContext;
I got confused when to use IContentService, IContentTypeService and the ServiceContext or is it the right interfaces for this.
And may be there is a smarter way of doing a task like this, I don't know. Hope someone can bring me in the right direction
Hi Peter
It's not clear to me where the dropdown will be presented?
If I understand correctly, editors will be able to login to the backoffice of Umbraco and create new content items, that will represent Business Categories of some kind.
And these business categories need to be used in a dropdown.
But what I'm not sure is if this dropdown is on another content type in the Umbraco backoffice?
so editors will again login to Umbraco, create a new kind of thing, a blog post maybe, and then choose from a dropdown list one of these categories?
or
whether this is a form on the front end of the site, that visitors rather than editors will fill in, and the dropdown list needs to be populated from Umbraco?
If it is the backoffice dropdown you are after, then have a look at the contentment package: https://our.umbraco.com/packages/backoffice-extensions/contentment/ this has got loads of good things in, but one of them is the ability to define a dropdown from a source of Umbraco content items, to use as an editor in the backoffice.
If it's the front end the dropdown will be on, then your View that displays your form, will have access to Umbraco content via the UmbracoHelper:
https://our.umbraco.com/Documentation/Reference/Querying/UmbracoHelper/
And this can be used to retrieve the options from the published Umbraco cache. You only really should use the services, eg ContentService and ContentTypeService when actioning CRUD interactions, like importing content from another source - as they will hit the database directly.
Not sure if I've understood correctly.
but hopefully that's useful in someway...
regards
Marc
Hi Marc,
Fantastic, I know that my question where very confusing, think that it was because my head were very confusing about this issue also. And also difficult to explain, when you are new to Umbraco terms. The contentment package datalist where just what I was looking for. I would like to build up some kind of entity relationship between the content types. I am looking forward to see, how it save the relation, but just want to answer you first, and tell you, that you just hit it on the spot - thanks a lot man, you saved my Christmas - ha ha.
Merry Christmas
Peter
is working on a reply...