Hi,
Before starting my own project I wanted to check the example but found that it has some issues preventing it to run.
The first one is the js error described in title:
Uncaught TypeError: Object function (a){return e.call(this,a,b)} has no method 'execute' drupalbackbone.js:199
Drupal.behaviors.backbone.attach.Drupal.Backbone.Views.Base.Backbone.View.extend.initialize.renderers.underscore.execute
...
Maybe something has changed in recent version of underscore but the only solution to this I've found is to change
return template.execute(vars);
with
return template.call(vars);
in the underscore renderer definition. (drupalbackbone.js line 198)
With this modification the form get displayed but there is a new javascript error showing up:
Uncaught ReferenceError: node is not defined
(anonymous function)
b.template.c underscore.js:30
Drupal.behaviors.backbone.attach.Drupal.Backbone.Views.Base.Backbone.View.extend.initialize.renderers.underscore.execute drupalbackbone.js:198
Drupal.behaviors.backbone.attach.Drupal.Backbone.Views.Base.Backbone.View.extend.executeTemplate drupalbackbone.js:259
Drupal.behaviors.backbone.attach.Drupal.Backbone.Views.Base.Backbone.View.extend.render drupalbackbone.js:319
I haven't debugged it further since maybe I did something wrong. I believe the first "fix" is not correct since the second issue looks like a variable not passed to the template. Let me know if there is something I can do to fix these issue.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | no_method_execute-1745060-5.patch | 1.6 KB | idflood |
Comments
Comment #1
idflood commentedI finally got something a little bit better.
I changed the
return template.execute(vars);to simplyreturn template(vars);(instead of the call).Next, i modified the theme_backbone_example_node_template function. There is an added verification "typeof(node) != "undefined" && ".
return '<% if (typeof(node) != "undefined" && node.title && node.body) { %><h2><%= node.title %></h2><div><%= node.body.und[0].safe_value %></div><% } %>';Now there is no more javascript errors on the page but if I try to load the node 1 which exists I got a 404 error:
"GET http://localhost/backbone/rest/node/1.json 404 (Not Found) "
It should be http://localhost/drupal_backbone/rest/node/1.json but if I try with this url I also get a 404.I installed the drupal in a subdirectory, so the url should be http://localhost/drupal_backbone/backbone/rest/node/1.json
Comment #2
idflood commentedI've found a way to get correct path without modifying the backbone option. I modified the backbone_init function so that it include the base_path:
Now I'm back to square 1 since nothing get displayed if I try to load the node 1. (the json is loaded)
So it's the
return template.execute(vars);correction which is wrong.I tried without success:
Any idea?
Comment #3
ethanw commentedThis is likely because of the updates to support Twig just pushed. I'll take a look at what's needed to update the example module for these updates. I'll also be pushing an additional example module shortly.
Comment #4
idflood commentedOk thanks.
Just in case, the commit where this bug was introduced: http://drupalcode.org/project/backbone.git/commitdiff/288031693ae325ac8c...
In fact there is a difference of how the "variables" value is constructed. The render function was using this before:
variables = this.model.toJSON();This returned an object with a 'node' attribute.
But now the
variables = this.model.renderAttributes();return an object with only the node properties (the equivalent of variables.node).Comment #5
idflood commentedSo here is a first patch that fixes the example.
For underscore template rendering it changed
return template.execute(vars);toreturn template(vars);I've also added the $base_path in the endpoint url. It's not really specific to this issue so tell me if you would like that I reroll the patch without this modification.
The last thing is that I changed the theme_backbone_example_node_template function so that it directly access the title variable (title instead of node.title).
Comment #6
frega commentedWas working on a similar patch :) fixes the issue for me.
Comment #7
ethanw commentedLooks great, thanks for those fixes.
Committed, split into the following commits:
http://drupalcode.org/project/backbone.git/commit/0d4f6fb132a6a2a69498a2...
http://drupalcode.org/project/backbone.git/commit/f9aaa7c1930caee4bfbddb...
http://drupalcode.org/project/backbone.git/commit/45d43abba8605f4c3e70e9...
Comment #8
ethanw commentedIt turned out that required something of a refactor in the ways urls were being constructed by the base Model and Collection objects. That should be addressed now, commit ID d54fd7d324fa749e104a884078b679cd97f6a0f1