Open orchardbot opened 10 years ago
@sebastienros commented:
I am opening it as I want to analyze the impact it can have. This could potentially solve another related issue: https://orchard.codeplex.com/workitem/20574
qt1 commented:
BTW, I have tried running the the tests after the fix and it looks like there is no negative impact.
@sebastienros commented:
Fixed in changeset c6b6cb1a9897c71c1ba35ed00ae10b9eb3763343
qt1 commented:
Thanks!!!
@jeffolmstead commented:
Unfortunately while I agree this is an appropriate change, it made the issue discussed here a top priority:
https://orchard.codeplex.com/workitem/20637
As it stands right now (with the above change) when you create a content item that has a field the field data is not persisted (it is just lost). You can return and edit the item to have the field data stored but a permanent solution is needed.
qt1 commented:
Hi, Here is some more information that may be useful:
Preparation: Add a FirstName field to User type in migrations like so:
ContentDefinitionManager.AlterTypeDefinition("User",
cfg => cfg .WithPart("User") );
ContentDefinitionManager.AlterPartDefinition("User", builder => builder
.WithField("FirstName", fld =>
fld.OfType("TextField")
.WithSetting("DisplayName", "First Name")
.WithSetting("Attachable", "True")
));
UserPart userPart = _contentManager.New<UserPart>("User");
// find the field (there must be a better way, this works for me..)
TextField firstNameField = userPart.ContentItem.Parts.SelectMany(part => part.Fields.Where(field => field.PartFieldDefinition.Name == "FirstName")).Single() as TextField;
firstNameField.Value = "My first name";
_contentManager.Create(userPart);
The user item is created properly but the field is not set to "My first name"
UserPart userPart = _contentManager.New<UserPart>("User");
_contentManager.Create(userPart);
TextField firstNameField = userPart.ContentItem.Parts.SelectMany(part => part.Fields.Where(field => field.PartFieldDefinition.Name == "FirstName")).Single() as TextField;
firstNameField.Value = "My first name";
qt1 created: https://orchard.codeplex.com/workitem/20647
Item create in UI writes the raw record to DB before reading values from the entry form.
This causes problems when default values do not conform to DB - e.g. null values.
This is initial data is later overwritten with entered data and is saved again in the DB.
The fix - as far as I can tell - would be to switch a couple of lines in
File: src\Orchard.Web\Core\Contents\Controllers\AdminController.cs
switch the lines 251 and 253: _contentManager.Create(contentItem, VersionOptions.Draft);
fix: first set than save.. var model = _contentManager.UpdateEditor(contentItem, this); _contentManager.Create(contentItem, VersionOptions.Draft);