Im generating datatypes pragmatically (Quicker and easier to maintain accross multiple websites)
using umbraco 11.1.0
but I have an issue where I have created some custom property editors. They show up fine in the back end of the website if you create a datatype manually.
However in generation code for my datTypes I have a line
var editor = _dataTypeService.GetByEditorAlias(docType).FirstOrDefault();
is meant to get the propertyEditor the given alias. however it returns a null there is no dataType with this alias already created.
but If I create a dataType with a the given property editor as named anything. This code finds the property editor via the alias.
Not I have checked and checked and checked the Aliase names match etc. not code works if there is a least 1 dataType that uses this propertyEditor alias.
It is like you have 2 lists
List "A" contains all the possable propertyEdits available and this is the list that we see in the backoffice when creating dataTypes manually.
Then there is List "B" that contains al thepropertyEditors that have been used at least once.
so list B is smaller than List A but the code above searchs list B but it should be searching list A
full code
public void CreateDataType(int containerId, string name, string docType, Dictionary<string, object> preValues)
{
var exists = _dataTypeService.GetDataType(name);
if (exists == null)
{
var editor = _dataTypeService.GetByEditorAlias(docType).FirstOrDefault();
if (editor != null)
{
DataType newDataType = new DataType(editor.Editor, _serializer, containerId);
newDataType.Name = name;
_dataTypeService.Save(ConfigureDataType(newDataType,docType,preValues));
int newDataTypeId = newDataType.Id;
}
}
else
{
DataType created = (DataType)_dataTypeService.GetDataType(name);
_dataTypeService.Save(ConfigureDataType(created, docType, preValues));
}
}
ConfigureDataType handles the different prevalue types.
public void CreateDataType(int containerId, string name, string docType, Dictionary<string, object> preValues, IDataEditor newEditor)
{
var exists = _dataTypeService.GetDataType(name);
if (exists == null)
{
DataType newDataType = newEditor == null ? new DataType(_dataTypeService.GetByEditorAlias(docType).FirstOrDefault().Editor, _serializer, containerId) : new DataType(editor: newEditor, _serializer, containerId);
newDataType.Name = name;
_dataTypeService.Save(ConfigureDataType(newDataType,docType,preValues));
int newDataTypeId = newDataType.Id;
}
else
{
DataType created = (DataType)_dataTypeService.GetDataType(name);
_dataTypeService.Save(ConfigureDataType(created, docType, preValues));
}
}
line in question is from above
DataType newDataType = newEditor == null ? new DataType(_dataTypeService.GetByEditorAlias(docType).FirstOrDefault().Editor, _serializer, containerId) : new DataType(editor: newEditor, _serializer, containerId);
this replaced the code in the question above.
works from the perspective that the dataTypes that are not working are my new ones that have never been used therefore it i pass the into newEditor the IDataEditor it uses that and it works and if its a standard umbraco editor or another editor that I havent found the model for and pass it as a null it works as long as there is a property editor thathas been already created.
in looking into it deep I established that
var editor = _dataTypeService.GetByEditorAlias(docType).FirstOrDefault();
finds the first Data Type that exists and using that to create the new one. Its not finding the Property Editor by that alias.
with the work around both these work
_install.CreateDataType(formPickerId, "IBD Advanced Form Block Settings", "Umbraco.BlockList", preValues, null);
_install.CreateDataType(formPickerId, "IBD Advanced Form Template Block Picker", "IBD.BlockMultinodePicker", preValues, new BlockMultinodePickerEditor(_ioHelper, _dataValueEditorFactory, _editorConfigurationParser, EditorType.PropertyValue));
not ideal solution as if the Property has not been used yet and I dont noe the model then it will fail.
error getting datType in code
Im generating datatypes pragmatically (Quicker and easier to maintain accross multiple websites)
using umbraco 11.1.0
but I have an issue where I have created some custom property editors. They show up fine in the back end of the website if you create a datatype manually.
However in generation code for my datTypes I have a line
is meant to get the propertyEditor the given alias. however it returns a null there is no dataType with this alias already created.
but If I create a dataType with a the given property editor as named anything. This code finds the property editor via the alias.
Not I have checked and checked and checked the Aliase names match etc. not code works if there is a least 1 dataType that uses this propertyEditor alias.
It is like you have 2 lists
List "A" contains all the possable propertyEdits available and this is the list that we see in the backoffice when creating dataTypes manually.
Then there is List "B" that contains al thepropertyEditors that have been used at least once.
so list B is smaller than List A but the code above searchs list B but it should be searching list A
full code
ConfigureDataType handles the different prevalue types.
Hi Daniel,
If you do
_dataTypeService.GetAll()
does it appear in the results?Tried that. But no it doesnt come up in the list.
temporarily got round it by passing
Editor decleared
then inside routine did this
line in question is from above
this replaced the code in the question above.
works from the perspective that the dataTypes that are not working are my new ones that have never been used therefore it i pass the into newEditor the IDataEditor it uses that and it works and if its a standard umbraco editor or another editor that I havent found the model for and pass it as a null it works as long as there is a property editor thathas been already created.
in looking into it deep I established that
finds the first Data Type that exists and using that to create the new one. Its not finding the Property Editor by that alias.
with the work around both these work
not ideal solution as if the Property has not been used yet and I dont noe the model then it will fail.
its like I should be looking for something like
but it doesn't exist.
Hope this makes sense
is working on a reply...