Skip to content

Commit 25c52d5

Browse files
authored
Merge pull request #11944 from umbraco/v9/hotfix/remove-element-from-blocklist
V9: Fix removing element from BlockList
2 parents 58b75c5 + d7fef7c commit 25c52d5

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

src/Umbraco.Web.UI.Client/src/common/services/blockeditormodelobject.service.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,30 @@
101101

102102
/**
103103
* Generate label for Block, uses either the labelInterpolator or falls back to the contentTypeName.
104-
* @param {Object} blockObject BlockObject to recive data values from.
104+
* @param {Object} blockObject BlockObject to receive data values from.
105105
*/
106106
function getBlockLabel(blockObject) {
107107
if (blockObject.labelInterpolator !== undefined) {
108-
var labelVars = Object.assign({"$contentTypeName": blockObject.content.contentTypeName, "$settings": blockObject.settingsData || {}, "$layout": blockObject.layout || {}, "$index": (blockObject.index || 0)+1 }, blockObject.data);
108+
// blockobject.content may be null if the block is no longer allowed,
109+
// so try and fall back to the label in the config,
110+
// if that too is null, there's not much we can do, so just default to empty string.
111+
var contentTypeName;
112+
if(blockObject.content != null){
113+
contentTypeName = blockObject.content.contentTypeName;
114+
}
115+
else if(blockObject.config != null && blockObject.config.label != null){
116+
contentTypeName = blockObject.config.label;
117+
}
118+
else {
119+
contentTypeName = "";
120+
}
121+
122+
var labelVars = Object.assign({
123+
"$contentTypeName": contentTypeName,
124+
"$settings": blockObject.settingsData || {},
125+
"$layout": blockObject.layout || {},
126+
"$index": (blockObject.index || 0)+1
127+
}, blockObject.data);
109128
var label = blockObject.labelInterpolator(labelVars);
110129
if (label) {
111130
return label;
@@ -511,23 +530,22 @@
511530
* @methodOf umbraco.services.blockEditorModelObject
512531
* @description Retrieve a Block Object for the given layout entry.
513532
* The Block Object offers the necessary data to display and edit a block.
514-
* The Block Object setups live syncronization of content and settings models back to the data of your Property Editor model.
515-
* The returned object, named ´BlockObject´, contains several usefull models to make editing of this block happen.
533+
* The Block Object setups live synchronization of content and settings models back to the data of your Property Editor model.
534+
* The returned object, named ´BlockObject´, contains several useful models to make editing of this block happen.
516535
* The ´BlockObject´ contains the following properties:
517-
* - key {string}: runtime generated key, usefull for tracking of this object
536+
* - key {string}: runtime generated key, useful for tracking of this object
518537
* - content {Object}: Content model, the content data in a ElementType model.
519538
* - settings {Object}: Settings model, the settings data in a ElementType model.
520539
* - config {Object}: A local deep copy of the block configuration model.
521540
* - label {string}: The label for this block.
522541
* - updateLabel {Method}: Method to trigger an update of the label for this block.
523542
* - data {Object}: A reference to the content data object from your property editor model.
524543
* - settingsData {Object}: A reference to the settings data object from your property editor model.
525-
* - layout {Object}: A refernce to the layout entry from your property editor model.
544+
* - layout {Object}: A reference to the layout entry from your property editor model.
526545
* @param {Object} layoutEntry the layout entry object to build the block model from.
527-
* @return {Object | null} The BlockObject for the given layout entry. Or null if data or configuration wasnt found for this block.
546+
* @return {Object | null} The BlockObject for the given layout entry. Or null if data or configuration wasn't found for this block.
528547
*/
529548
getBlockObject: function (layoutEntry) {
530-
531549
var contentUdi = layoutEntry.contentUdi;
532550

533551
var dataModel = getDataByUdi(contentUdi, this.value.contentData);

0 commit comments

Comments
 (0)