Web Part with a custom property bound to a "choice" field from a content type? - sharepoint

I'm trying to make a custom property for a WebPart. The custom property should be a drop down with choices coming from a "choice" column from a content type. Is that even possible?

You have two options:
1) If your choices will never change then you can hardcode an enum with these values and use that as datatype for your custom property. SP will the automatically generate a drop down.
2) If you can't hardcode the values then you have to implement what is called an EditorPart where you can code the UI for handling entry of the custom property

You cannot data bind directly to a content type column as it does not exist as in a bindable form, only as an XML secification on the content type itself.
Better to specify the column as a lookup and databind to the list directly. However, that is not going to work well when you only want one lookup across multiple webs or site collections.
In that case create a list in a config site such as http://intranet/sites/config and code a lookup control to databind to that list. Then use the control in the webpart and in a custom field control on the content type.
A bit of work, but worth it if you require SharePoint edit control (versioning, security etc) access to the contents of the lookup and a single (changeable) source of data across the entire site.

Related

WebPart cleanly render a list of n items

I am attempting to create a WebPart in Kentico 11 that supports handling an n-length list of items. I found that creating a WebPart with property fields is pretty straightforward in Kentico, but I am having trouble finding documentation on how to best set up a WebPart that can lookup & output multiple model objects.
I've tried the following approach, but it has some drawbacks that I'm not entirely comfortable with:
Set up a Container page type to place instances of data objects inside. I restricted it to ensure that only my custom Page Type data object is available as a child of it.
Place a Pages DataSource in the template zone and direct it to the Container page.
Hook up a Repeater element to it and apply a transformation & content before+after to the Repeater.
While this works, it feels a little cludgey. Content editors have to be wise enough to know how to set up DataSources & Repeaters, plus how to bind them together and apply transforms, and additionally remember to fill in the content before and content after fields with the appropriate wrapping HTML markup.
This is not something that I expect a content editor should need to remember.
Is there a cleaner way to put lists of items inside of a template zone without needing to drag & configure a datasource and container page?
I did not see any way to set up a Page Type field in such a way that it would essentially model a one-to-many relationship with another Page Type. Did I miss something there? If I could do that, then I could write a transformation to handle the wrapping HTML markup, and the looping of children. Haven't been able to find a way to make this work though.
The best way to accomplish what you are asking is with a custom form control. In your case, the form control should be able to let users select multiple items.
You can actually use 'Sortable multiple object selector' marketplace item for this purpose. This form control will enable you to select multiple items based on a certain type (that you need to configure in code) and editors would simply use the select dialog to choose the items.

OrchardCMS Custom Forms and lookup fields

I can create custom form with Orchard Custom forms Module based on a Content Type.
Also i can add Enumerable field to the Content Type to show as combo box in created custom form.
But i can set list items of the enumerable field statically only.
How can i set this items based on result of a projection query or fill the combo box by any content items of a special content type dynamically?
You can't out of the box.
You could write your own module that provided a query driven combo field, but if you've not written a module before then you might want to start with writing a more simple field module first.
You might find the following useful:
Creating a custom field tutorial
I'd also look at the Orchard Source code for the projection module to see how they use queries.

Sharepoint Extenal List and Custom Field Types

I have an odd issue.
I have client that wants a sharepoint list what is populated from a WCFService. That part is working quite well.
I have a bdcmodel that is mapping the WCF data and I can create an external list from the bdcmodel as well so that is working fine.
The issue I have is that one of the properties in the model is actually a collection of entities called Attributes. The objects in this collection simply have 2 properties Name and Value so really they are just a key value pair.
The client wants to see the list of attributes of the parent entity in the external list. So there would be an Attributes column and within that column would be the list of attributes for each parent object.
Is there even a way to do this? I am looking into Custom Field Types, but it seems like these are really intended to be singular values.
How would I create a list within and external list?
Any help anyone can give would be great even if its just to tell me that there really isn't a stable way to do this so I can go back to the client and tell them we will need to build a custom list to support this because the OOB external list and custom fields and custom field types won't support this kind of nested listing.
I decided to set up the custom field as a string and when I get my collection in from the BdcModel I am serializing it to JSON and then passing it to the field. When the field is viewed in display, edit or new I have overridden the FieldRenderingControl and I am tiling the collection out that way.

How to display "ContentType" name in search results?

I have a MOSS site where I have created custom content types and activated those on a document library. Now I want to use a custom XSL stylesheet with search results to pull back those documents and display the name of the custom content type assigned for each one.
I know how to create managed properties and map those, etc... but can not seem to find the built-in type that would have the name I assigned to the custom content types? You would think this would be simple - but simply using a built-in one like "ContentType" returns something generic and not the name of the custom type.
Any ideas?
The default content type managed property is mapped to multiple crawled properties, with the first one usually being the mime type. I think there is a way to get all values of a property rather than just the first one in the search results xsl, but if that doesn't work out you can always add a custom managed property that only maps to the one crawled property.

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