strange content type in drupal - drupal-6

i want to have a content type for my properties. let's name it 'my properties'.
and i have a taxonomy called 'my properties type' that contains 'books,shoes,clothes'.
the form for adding properties change on taxonomy selected item,because each of its type have different fields.
is it possible to have such content type in drupal ??

The solution within Drupal is to create separate content types for each property type. However, you can easily write some jquery to show/hide fields when taxonomy field is modified:
$('#your-taxonomy-dropdown').change(function() {
if($(this).val() == 'book') {
$('#field1').hide();
$('#field2').show();
}
});

Related

Access content field from views in Orchard CMS 1.10.1

I would like to display certain first level menuitem in bold.
This setting should be done by a checkbox when the user create / edit a menu item. (I have a workaround using the Model.Href, but it is not nice).
So I created a boolean field in Content definition / Menuitem URL (I don't know the name of the corresponding content definition in English Orchard).
How to access a custom field (Content Field) from a view?
(There already is a view which is used to customize the menu)
The examples I found use custom shapes, where the fields are accessed as built in fields (e.g. Model.ContentItem.FieldName ). But this is a different case.
With the help of "Piedone", the solution:
Model.Content.ContentItem.MenuItem.FieldTechnicalName.Value
Explanation
Examining the Model object in Visual Studio, the Model is a dynamic shape that have eg. Href property and a Content.
Content is a MenuPart, that is a content part that have a ContentItem property with the content item itself. Technically only content parts have Fields. When you (seemingly) add a field to a type it will be a part corresponding the type's name, that is MenuItem in this case (It's confusing that the display name of 'MenuItem' content type is Custom Link...)
The field's technical name is as you name it. When you add to a type, the Value will be a property of the BooleanField class. (By the way, it is nullable, so if you dont't save after adding the field, it will be null else the value you set).

Are Containable Parts and Widgets exclusive of each other?

I'm struggling with a decision to choose between creating a custom type as a Content Type with the Containable Part, or to create them as a Widget. I know that an existing Content Part can be used to create a new Widget, but this leaves me with having to create each instance from within the Widget Management section of the dashboard (I think). I'm not able to select a content item that already exists and have it act as a widget.
What I would really like is to have the ability to select a single, existing, Content Item and display it as a Widget. The widget could then expose a link that would take the user to the page-level display of that item. This would also allow me to have a list of these content types on a page where I also had html elements (html widgets) sprinkled in and amoungst them.
Alternatively, I could create my Content Type and attach the Containable Part. This would allow me to create the ad-hoc list (not a Projection) of content items I want. I would, however, have to create another Content Type to hold the HTML want to have appearing between the primary types.
Are my assumptions correct?: Must one create a new instance of a widget when they add it to a zone? Or can they select one from a list of existing content types?
Are Containable Parts and Widgets exclusive of each other?
Create a widget type with a content item picker field.
Thanks, Bertrand for the suggestion to create a widget type with a content item picker field. Here is my implementation:
public UpdateFrom1() {
ContentDefinitionManager.AlterTypeDefinition("BioPickerWidget", cfg => cfg
.WithPart("BioPickerWidget")
.WithPart("WidgetPart")
.WithPart("CommonPart")
.WithSetting("Stereotype", "Widget"));
ContentDefinitionManager.AlterPartDefinition("BioPickerWidget", cfg => cfg
.WithField("BioPicker", fb => fb
.OfType("ContentPickerField")
.WithSetting("ContentPickerFieldSettings.Hint", "Add Bio Content Items here.")
.WithSetting("ContentPickerFieldSettings.Required", "True")
.WithSetting("ContentPickerFieldSettings.Multiple", "True")
.WithSetting("ContentPickerFieldSettings.ShowContentTab", "True")
.WithSetting("ContentPickerFieldSettings.ShowSearchTab", "True")
.WithSetting("ContentPickerFieldSettings.DisplayedContentTypes", "BioPart")
.WithDisplayName("Bio Content Picker"))
.WithSetting("ContentPartSettings.Attachable", "True")
);
return 2;
}
This allows me to add 1 or more of my Bio Content Types to a widget. Seems to be working nicely. All I have to do now is figure out the view customization.

Orchard CMS 1.4: Adding a Text Field to Custom ContentPart

In the module for a custom ContentPart, how do I set a field to be a Text field?
In my migrations.cs class, I have created the table for the part:
public int UpdateFrom1()
{
SchemaBuilder.CreateTable("RightContentPartRecord", table =>
table.ContentPartRecord()
.Column<string>("Html"));
return 2;
}
So, I have a column called Html. I want to use the WYSIWYG editor, so I am told I need a Text field to get this to work "out of the box".
However, this isn't happening for me, so what do I need to do to turn my column called Html into a Text field on the part?
And how do I configure it to use the WYSIWYG editor?
If you want a property of your own custom contentpart to be displayed as a htmleditor, configure it as follows in the editortemplate of your part.
#Script.Require("OrchardTinyMce")
#Html.TextAreaFor(x => x.Header, new { #class = "html tinymce" })
In this case the 'Header' property is displayed as a html editor.
If you need this in more parts you can consider writing a Html extension or editor template for it.
A text field is not the same thing as a part property. Fields are not stored as their own database column. Here is an example of how you add a field to a part from a migration:
ContentDefinitionManager.AlterPartDefinition("Product",
builder => builder.WithField("ProductImage", fieldBuilder => fieldBuilder.OfType("MediaPickerField").WithDisplayName("Product Image")));
For text field, you'd also need to set the flavor setting by adding .WithSetting("Flavor", "html") to the field builder.

Hide a content type field programmatically

I've got a field referenced by two content types and I use some code in a feature receiver to hide the title field. One content type inherits from the other but doesn't add anything, only changes the name. They are going to have different workflows attached to them. The problem is that the code only hides the title field on one content type, not the derived one.
SPList members = web.Lists["Inspections"];
SPField titleField = members.Fields["Title"];
titleField.ShowInNewForm = false;
titleField.ShowInEditForm = false;
titleField.Required = false;
titleField.Update();
Updating a field in the list will not do anything to the child content types, seeing as each content type in a list not the actual content type itself, but a "silent" child. (inspect the content type id's of the type in the site settings and that of the "same" content type in the list).
use the Site collection's content type collection instead, change the field and properties and then call the content type object's Update method:
SPContentType.Update(true); // true means you want to push any changes made down to all child content types.

Person & Group custom field type sharepoint

I have created a custom field type as it is there in sharepoint OOTB, the difference is only that the end user does not need to check the name i.e I have replaced it with DropDownList. The dropdownlist suggest the no. of users available in the web site for that I have created a FieldClass which inherits from SPFieldUser and a FieldControlClass which inherits from UserField. It is working fine in all conditions i.e when I create a List or Document Libarary it shows me the DropDownList
with respective users after saying OK it creates an item for me. I have overriden a Value property in FieldControlClass as follows,
public override object Value
{
get
{
SPUserCollection userscollection = rootWeb.SiteUsers;
//ddlInfoBox is a DropDownList to which I have Binded the collection of users in the form of string
SPUser user = userscollection.Web.EnsureUser(this.ddlInfoBox.SelectedValue);
SPFieldUserValue userval = new SPFieldUserValue(user.ParentWeb, user.ID, user.LoginName);
return userval;
}
set
{
SPFieldUserValue userval = (SPFieldUserValue) this.ItemFieldValue;
this.ddlInfoBox.SelectedValue = userval.Lookupvalue; //Here look up value is nothing but a Login name e.g In-Wai-Svr2\tjagtap
}
}
Due to above property the Custom Field's Value for this current ListItem will be stored as SPFieldUserValue e.g 27#;In-Wai-Svr2\tjagtap.
The main problem is here, when this particular ListItem is shown in the list page views e.g on AllItems.aspx or the custom view pages associated with it, it shows the
number as 27 as a FieldValue insted of HyperLink with text as "In-Wai-Svr2\tjagtap" and PostBackURL as "/_layouts/userdisp.aspx?ID=27".
When I edit this Item it makes the respective value selected in the dropdownlist, also while viewing this item i.e on DispForm.aspx it also shows the hyperlink. I have
acheived it by writting a custom logic in createchildcontrol() method i.e by using ControlMode if it is New or Edit then fill the dropdown list, if it is Display then get the ItemFieldValue Type Cast it into SPFieldUserValue and get corresponding lookupid and value for making the URL and showing Text of the HyperLink.
I have spent a lot of time on searching and bringing the HyperLink as the user name with navigation insted of UserID (27) as a string on the list view pages e.g AllItem.aspx but to no avail, then after a lot of research I found that there might be a way of achieving such kind of functionality by using field type definition xml file where there is a provision to define a DisplayPatteren as you wish by specifying the html code. But here is a problem How can I get the UserID (27) with respective UserName e.g In-Wai-Svr2\tjagtap inorder to make an anchor tag like In-Wai-Svr2\tjagtap which will solve my problem. I have hard coded this anchor tag within the Default case statement of a switch under DisplayPatteren but it shows me the field value on AllItems.aspx as
In-Wai-Svr2\tjagtap27 i.e the value defined in xml file is concatenating with the string value (27).
Please help me to resolve the above mentioned 2 issue. I am really in need of solving this problem ASAP.
Thanks & Regards,
Tejas Jagtap
Have u tried to override the GetFieldValueAsHtml() method in the the custom field class or maybe the RenderFieldForDisplay() method in the custom field control class.
Can you use the DisplayPattern CAML from the User field type?

Resources