-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extending BlockList blocks? #61
Comments
Hi @chris-evansnz, In this case, you want to extend the BasicBlockListItem and use this instead of the BasicBlockListItem that is used in the documentation. The BasicBlockListModel takes a type of BasicBlockListItem as the generic parameter so you just need to have another class inherit from the BasicBlockListItem eg. public class CustomBlockListItem : BasicBlockListItem<BasicProperty> {
public string MyCustomProperty { get; set; }
public CustomBlockListItem (CreateBlockListItem createBlockListItem, IPropertyFactory<BasicProperty> propertyFactory) {
MyCustomProperty = "Hello I'm Custom!";
}
} public class CustomBlockListModel : BasicBlockListModel<CustomBlockListItem> {
public string MyCustomProperty { get; set; }
public CustomBlockListModel(CreatePropertyValue createPropertyValue, IDependencyReflectorFactory dependencyReflectorFactory) : base(createPropertyValue, dependencyReflectorFactory) {
MyCustomProperty = "Hello I'm Custom!";
}
} |
@chris-evansnz Did this answer your question? |
@nikcio thanks so much for the quick response! I live in New Zealand so my time zone is a bit odd - hence the slower reply. I figured something like this was required. I just tried implementing that, and the code compiles ok but I'm not sure how to query my new property. I've got this: public class CustomBlockListModel : BasicBlockListModel<BasicBlockListItem<BasicProperty>>
{
public string MyCustomProperty { get; set; }
public CustomBlockListModel(CreatePropertyValue createPropertyValue, IDependencyReflectorFactory dependencyReflectorFactory) : base(createPropertyValue, dependencyReflectorFactory)
{
MyCustomProperty = "Hello I'm Custom at parent!";
}
}
public class CustomBlockListItem : BasicBlockListItem<BasicProperty>
{
public string MyCustomProperty2 { get; set; }
public CustomBlockListItem(CreateBlockListItem createBlockListItem, IPropertyFactory<BasicProperty> propertyFactory) : base(createBlockListItem, propertyFactory)
{
MyCustomProperty2 = "Hello I'm Custom in block item!2";
}
} And I'm running this graphql query on a page I have called Contact Us: {
contentByAbsoluteRoute (route: "/contact-us") {
name,
id,
properties {
alias,
value,
editorAlias,
__typename
}
}
} I get this response, which shows the first custom property on the parent Block List, but not the second custom property on the block children: {
"data": {
"contentByAbsoluteRoute": {
"name": "Contact us",
"id": 1070,
"properties": [
{
"alias": "contentBlocks",
"value": {
"myCustomProperty": "Hello I'm Custom at parent!",
"blocks": [
{
"contentProperties": [
{
"alias": "title",
"value": {
"value": "My test feature"
},
"editorAlias": "Umbraco.TextBox"
},
{
"alias": "text",
"value": {
"value": "<p>This is some text for the feature</p>"
},
"editorAlias": "Umbraco.TinyMCE"
},
{
"alias": "image",
"value": {
"mediaItems": [
{
"url": "https://localhost:44387/media/ivmfpss5/90mmplusnailerpluswebplusp1.png",
"id": 1069
}
]
},
"editorAlias": "Umbraco.MediaPicker3"
},
{
"alias": "showImageOnRight",
"value": {
"value": false
},
"editorAlias": "Umbraco.TrueFalse"
}
],
"settingsProperties": [],
"contentAlias": "featureBlock",
"settingsAlias": null
},
{
"contentProperties": [
{
"alias": "title",
"value": {
"value": "Second feature"
},
"editorAlias": "Umbraco.TextBox"
},
{
"alias": "text",
"value": {
"value": "<p>Some text for the second feature</p>"
},
"editorAlias": "Umbraco.TinyMCE"
},
{
"alias": "image",
"value": {
"mediaItems": [
{
"url": "https://localhost:44387/media/b1sgsw1d/_0002_layer-30.png",
"id": 1072
}
]
},
"editorAlias": "Umbraco.MediaPicker3"
},
{
"alias": "showImageOnRight",
"value": {
"value": true
},
"editorAlias": "Umbraco.TrueFalse"
}
],
"settingsProperties": [],
"contentAlias": "featureBlock",
"settingsAlias": null
}
]
},
"editorAlias": "Umbraco.BlockList",
"__typename": "BasicProperty"
}
]
}
}
} Is there something else I need to do in code to expose this new custom property on the children, or is there something I need to add in the graphql query? I couldn't see the MyCustomProperty2 in the playground schema docs. If I try to query it explicity I get this response in the graphql playground:
Thanks again for your help! |
@chris-evansnz you need to change this line: public class CustomBlockListModel : BasicBlockListModel<BasicBlockListItem<BasicProperty>> To this public class CustomBlockListModel : BasicBlockListModel<CustomBlockListItem<BasicProperty>> Otherwise you don't use your custom implementation of the block list item. About the properties not being available in the GraphQL playground. This will be fixed in version 3. Right now it's just a normal JSON text that's put into the property hence why you can't specifically query the properties value. |
Oh sorry @chris-evansnz. It needs to say: public class CustomBlockListModel : BasicBlockListModel<CustomBlockListItem> Your |
Ah yes, that makes sense. I can see the property in the results now, thanks so much for your responses! Will keep experimenting with this package and see how we can make use of it in our projects, it's very promising indeed. |
First of all, just wanted to say this package is very exciting - thanks so much for your work on it!
Also, I had a question about extending the Block List editor.
I can see how we can add custom properties to the parent block list property as per here:
https://github.com/nikcio/Nikcio.UHeadless/blob/v2/contrib/docs/v2/propertyValues/extendBlockList.md
But I can't figure out the syntax if we wanted to add a custom property to the child blocks elements themselves, e.g. having a custom property show in each of the "blocks" items underneath the value property of the BlockList. Is that possible?
The text was updated successfully, but these errors were encountered: