Orchard CMS: add image to custom Item - orchardcms

Hi once again :) My next question about Orchard CMS looks trivial but..
I have my custom NewsModule with NewsItem type which consists of TitlePart, BodyPrt, and my custom NewsPart. NewsPart is based on NewsPartRecord.
Now I have to extend my NewsItem document type with Image. So far I found that there are ImagePart and MediaLibraryPickerField.
ImagePart stores width and heihgt of image, so I think it is something for internal use.
The next one is MediaLibraryPickerField. After googling for a while, I found that I can extend my NewsPart using WithField() method.
But! First question here: when I'm configuring Page type with Admin UI, I can add field to the type. But using Migrations I can't add field to NewsItem, only to NewsPart.
The second question here. MediaLibraryPicker allows me to select any type of file from library, image, text, zip or any other. And this is not what I actually need.
So, what are the best practices in Orchard to extend Items with icons?
thanks.

You can add fields to NewsItem, it just requires a different type of definition. It confused me too as it's not as intuitive as you'd like it to be.
To add parts you are using AlterTypeDefinition.
this.ContentDefinitionManager.AlterTypeDefinition(
"NewsItem",
cfg => cfg.WithPart("NewsPart"));
But to add fields you have to also use AlterPartDefinition and specify the NewsItem not the NewsPart.
this.ContentDefinitionManager.AlterPartDefinition(
"NewsItem",
builder =>
builder.WithField(
"NewsImages",
fieldBuilder =>
fieldBuilder.OfType("MediaLibraryPickerField")
.WithDisplayName("News Images")
// Allow multiple images
.WithSetting("MediaLibraryPickerFieldSettings.Multiple", "true"))
Considering second question, MediaLibraryPickerField has option to display only selected types/parts.
.WithSetting(MediaLibraryPickerFieldSettings.DisplayedContentTypes="Document,Video")
If you need new media type you have to create new ContentType with Stereotype "Media", it also needs "MediaPart" and part that defines metadata for that type. You can look at how Document or Video is defined for sample code.

Related

Change object identifier in hybris backoffice

I wanted to add an extension in backoffice, so that it is possible for non-programming people to add new objects (of defined types) to the database.
I've almost done it:
I defined two items: offer and tile (their relation is one to many)
What i achieved is there is a possibility to add a new offer in the backoffice.
When you add it, and click to edit, you can also add a tile to this offer - either form drop-down list (if any tiles exist) or create a new tile, which will automatically be added to its table and realted to edited offer.
However, the representation of the drop-down list is unacceptable, see below:
screenshot from backoffice
as you can see, the identifier of an existing tile (within []) is its PK - which clearly is not a good identifier. I would like to inject there instead a value form one of tile's other attributes (which also is unique) so that someone could easily identify which tile to add.
Where is the mechanism responsible for it? How to override it. I tried to override toString method in the tile class, unfortunately to no avail
You need to customize the backoffice-config.xml for your custom Model. For your Tile model, you can use something like:
<context merge-by="type" type="Tile" component="base">
<y:base xmlns:y="http://www.hybris.com/cockpit/config/hybris">
<y:labels>
<y:label>nameOfTile</y:label>
</y:labels>
</y:base>
</context>

Reusing a custom ContentPart in the same ContentType

I'm trying to figure out the best way to handle a requirement I have for an Orchard module I'm building.
I have a ContentPart that has a few fields. One field is a ContentPicker that allows for multiple items to be associated to the part. The rest are descriptive information.
The issue I have is that I actually need to be able to include more than one of this ContentPart into a ContentType. I need to create a ContentType that has exactly 3 of this part.
Should I be making this into a field instead of a part? Is it even possible to have a ContentField that has other fields in it?
Or, should I somehow use all the same models and data structures, but somehow define it as 3 distinct parts?
Just wondering what the best practice to do something like this would be.
You can only have one part of each kind on a given type. You can't have fields that have other fields in it (instead - take an existing field and extend it with custom stuff).
As I understand, the actual problem is "how to make groups of fields with some metadata for each group", right? If so, there are a few approaches to solve the problem:
Create a custom field based on Content Picker (basically - take existing Content Picker and extend it with your metadata) and use this without the need for a separate part
Create one part to hold only the metadata for each field attached to it and attach 1 or more fields to it
Create 3 distinct parts. Parts should be thought of as extensions that add some unique features to an item. If you think it's logically ok to have 3 parts then go for it.

Orchard CMS Lists - how to replicate using Taxonomies

I'm new to Orchard but from various blog posts and SO answers it seems that Lists would help me achieve what I want. Unfortunately it seems that Lists have now been deprecated.
The documentation at http://docs.orchardproject.net/Documentation/Creating-lists suggests using Taxonomies instead. Is it possible to achieve the functionality of a List using Taxonomies?
You can use taxonomies to produce a list of content items. Create your taxonomy, add some items to it, attach the taxonomy field to your content type, and select the taxonomy you want to be displayed in the content type settings. Create a content item with a taxonomy selected then go to the url:
/taxonomy-name/*selected-taxonomy-item*
and it should display a list of all items with that taxonomy selected.
However, lists were deprecated and replaced by Projections, I would recommend using these. They are part of core and can be enabled from the backend. You can then create a query with your projection uses. This query determines what items you want displaying. It is pretty nice and simple, just need to play around with it. Let me know if you need more details about it, or probably just googling Orchard Projections will produce some useful links if you need to do some more complex things with it

Umbraco add custom Document Type

Is it possible to add a custom control to the Document Type? Suppose i couldn't create a multiselect or just a simple textfield control. How could i create a custom one and use that from the Document Type page in Umbraco?
If this is possible, then what steps need to be taken? Because i can add all sorts of config information in the Document Type controls that currently exist in there. Like, when i add a textfield i can gvie it a name, an alias and a validation message (and it has some others options).
Do i have to build the custom Document Type control in a specific way? And how is it saved to the database? How does Umbraco handle that?
Any information on this matter is more than welcome!
Since adding custom document types is native to Umbraco, and judging by the description in your question, I'm going to assume that you are talking about adding custom data types with user controls.
If so, check some of the following links on the subject, it's actually fairly simple:
Creating custom datatypes using the umbraco usercontrol wrapper (I personally used this one)
Custom DataTypes in Umbraco
Creating a custom datatype using the usercontrol wrapper (Video tutorial)

Change document library "Type" after it has been created from list definition

When beginning to develop against SharePoint I did not fully understand all the ins and outs initially. I created a list definition (for a document library) and associated various custom actions to it. Unfortunately, I used the following for the list definition itself:
<ListTemplate...
...
Type="101"
...
And to register the CustomActions against the list:
<CustomAction...
...
RegistrationType="List"
RegistrationId="101"
...
Of course, this means that the custom actions are visible for all document libraries where the feature is activated which is undesirable behaviour. Also, there are lots of these document libraries that have been created from the above list definition in production.
What is the best way to fix this problem? My assumption is that I somehow need to change the "Type" attribute of the already existing lists, but I do not know how to do that. Can it be done via some direct SQL manipulation perhaps? Or is there a better way?
Note: I can see that the AllLists table has a column tp_ServerTemplate, is that the right thing to change?
Modifying the SharePoint database is completely unsupported by Microsoft. Please do not do this on production!
Another option is to create a content type and associate the custom action with that. You may need to write a simple console application to iterate through your existing document libraries and add the content type so it is available for use. The existing documents that you'd like the custom action to apply to would need their content types changed as well.
From some quick initial testing it does look like changing the AllLists table does the trick.
So steps to resolve:
1) Change List Definition Type attribute to be a unique value (for example 11000)
2) Change the CustomAction RegistrationId attributes to be the same (11000)
3) Update the tp_servertemplate column in the AllLists table to be the new template Type (11000) for all the relevant lists.

Resources