Browse Source

Add new methods to Block

pull/3905/head
Artur Arseniev 4 years ago
parent
commit
5a416f9c3e
  1. 2
      src/block_manager/index.js
  2. 42
      src/block_manager/model/Block.js

2
src/block_manager/index.js

@ -153,6 +153,8 @@ export default () => {
if (!el) return this.__logWarn('"appendTo" element not found');
el.appendChild(this.render(blocksVisible.models));
}
this.__trgCustom();
},
/**

42
src/block_manager/model/Block.js

@ -1,4 +1,5 @@
import { Model } from 'common';
import { isFunction } from 'underscore';
/**
* @property {String} label Block label, eg. `My block`
@ -27,4 +28,45 @@ export default class Block extends Model {
attributes: {}
};
}
/**
* Get block id
* @returns {String}
*/
getId() {
return this.id;
}
/**
* Get block label
* @returns {String}
*/
getLabel() {
return this.get('label');
}
/**
* Get block media
* @returns {String}
*/
getMedia() {
return this.get('media');
}
/**
* Get block content
* @returns {Object|String|Array<Object|String>} Component definition | HTML string
*/
getContent() {
return this.get('content');
}
/**
* Get block category label
* @returns {String}
*/
getCategoryLabel() {
const ctg = this.get('category');
return isFunction(ctg.get) ? ctg.get('label') : ctg.label ? ctg.label : ctg;
}
}

Loading…
Cancel
Save