angular-drupal icon indicating copy to clipboard operation
angular-drupal copied to clipboard

Loading other entities

Open webdobe opened this issue 9 years ago • 3 comments

I was attempting to load a menu entity. I get:

angular.js:13920 TypeError: this[this.ucfirst(...)] is not a constructor
    at Object.jDrupal.entityLoad (http://localhost:9000/bower_components/jdrupal/jdrupal.js:452:16)
    at menuLoad (http://localhost:9000/scripts/services/menu.js:14:21)
    at new <anonymous> (http://localhost:9000/scripts/controllers/main-menu.js:18:24)
    at Object.invoke (http://localhost:9000/bower_components/angular/angular.js:4718:19)
    at $controllerInit (http://localhost:9000/bower_components/angular/angular.js:10354:34)
    at nodeLinkFn (http://localhost:9000/bower_components/angular/angular.js:9263:34)
    at compositeLinkFn (http://localhost:9000/bower_components/angular/angular.js:8620:13)
    at publicLinkFn (http://localhost:9000/bower_components/angular/angular.js:8500:30)
    at Object.link (http://localhost:9000/bower_components/angular/angular.js:26734:38)
    at http://localhost:9000/bower_components/angular/angular.js:1247:18 <div ng-include="'views/main-menu.html'" class="ng-scope" data-ng-animate="1">

It looks like loading other entities besides comments users and nodes is not supported using the jDrupal api?

webdobe avatar Nov 19 '16 22:11 webdobe

I added something like this:

jDrupal.Menu = function(machine_name) {

    // Set the entity keys.
    this.entityKeys['type'] = 'menu';

    // Prep the entity.
    jDrupal.entityConstructorPrep(this, machine_name);

    // Set default values.
    if (this.entity) {
        if (!this.entity.title) {
            this.entity.title = [ { value: '' }];
        }
    }

};

/**
 * Extend the entity prototype.
 * @type {jDrupal.Entity}
 */
jDrupal.Menu.prototype = new jDrupal.Entity;

/**
 * Set the constructor.
 * @type {jDrupal.Node|*}
 */
jDrupal.Menu.prototype.constructor = jDrupal.Menu;

Further into this looks like once this in place it doesn't try to get the correct endpoint.

It might be good to have something like:

jDrupal.Entity.prototype.getEntityEndpoint = function() {
  if (this.entityKeys['endpoint']) {
    return this.entityKeys['endpoint'] + '/';
  } else {
    return '';
  }
};

then:

jDrupal.Entity.prototype.load = function() {
  try {
    var _entity = this;
    var entityType = _entity.getEntityType();
    var entityEndpoint = _entity.getEntityEndpoint();
    return new Promise(function(resolve, reject) {

      _entity.preLoad().then(function() {

        var path = jDrupal.restPath() + entityEndpoint +
            entityType + '/' + _entity.id() + '?_format=json';

webdobe avatar Nov 19 '16 23:11 webdobe

Well... lol the menu entity didn't give me the tree lol there is a seperate module for that. Good exercise non the less... Still may be a good idea to do things like above.

webdobe avatar Nov 19 '16 23:11 webdobe

@webdobe were you able to figure this out, or are you still having an issue here? Thanks.

signalpoint avatar Nov 24 '16 02:11 signalpoint