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.

CommentFileSizeAuthor
#5 no_method_execute-1745060-5.patch1.6 KBidflood

Comments

idflood’s picture

I finally got something a little bit better.
I changed the return template.execute(vars); to simply return 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

idflood’s picture

I'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:

function backbone_init() {
  global $base_path;
  drupal_add_library('backbone', 'drupalbackbone-services');
  $backbone_settings = array(
    'backbone' => array(
      'endpoint' => $base_path . _backbone_variable_get('endpoint'),
    ),
  );
  drupal_add_js($backbone_settings, 'setting');
}

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:

return template.call(vars);
return template.call(this, vars);
return template(vars);

Any idea?

ethanw’s picture

This 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.

idflood’s picture

Ok 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).

idflood’s picture

Status: Active » Needs review
StatusFileSize
new1.6 KB

So here is a first patch that fixes the example.

For underscore template rendering it changed return template.execute(vars); to return 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).

frega’s picture

Status: Needs review » Reviewed & tested by the community

Was working on a similar patch :) fixes the issue for me.

ethanw’s picture

ethanw’s picture

It 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

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.