I noticed that drupalgap.menu_links['taxonomy/vocabulary/%'].title_callback is not set like drupalgap.menu_links[''node/%'].title_callback is which apparently is how each node page displays the title of the node in the page title of the header.

I tried to mimic the code that drupalgap.menu_links[''node/%'] uses to display the node title but I get the following error: (entity_load(taxonomy_vocabulary) - only single ids supported!)

here is my code:

/**
* Implements hook_deviceready().
*/
function [my_module_name]_deviceready() {
try {
// Print menu links to console to inspect the JSON structure.
dpm(drupalgap.menu_links);
// Make alterations here...
drupalgap.menu_links['taxonomy/vocabulary/%'].title_callback = 'vocab_page_title';

}
catch (error) { console.log('my_module_deviceready - ' + error); }
}

/**
* based on node_page_title from drupalGap api
* error: ( entity_load(taxonomy_vocabulary) - only single ids supported! )
*/
function vocab_page_title(callback, vid) {
try {
// Try to load the vocab title, then send it back to the given callback.
var title = '';
var vocab = taxonomy_vocabulary_load(vid, {
success: function(vocab) {
if (vocab && vocab.title) { title = vocab.title; }
callback.call(null, title);
}
});
}
catch (error) { console.log('vocab_page_title - ' + error); }
}

Comments

info@cgfix.com’s picture

updae: vid is undefined for some reason.
but with some tinkering, I found that this would work if the vid was defined.

new code change vocab.title to vocab.name

function vocab_page_title(callback, vid) {
try {
// Try to load the vocab title, then send it back to the given callback.
var title = '';
console.log('vid ='+vid);
var vocab = taxonomy_vocabulary_load(vid, {
success: function(vocab) {
if (vocab && vocab.name) { title = vocab.name; }
callback.call(null, title);
console.log('title ='+title);

console.log(vocab);
}
});
}
catch (error) { console.log('vocab_page_title - ' + error); }
}

info@cgfix.com’s picture

upadate:

I found that I can rig it to work by seting var vid = arg(2); inside the vocab_page_title() funciton.
I don't know if this is a good solution or not?

info@cgfix.com’s picture

so here is my final solution: ( don't know if this is the best way )

/**
* Implements hook_deviceready().
*/
function my_module_deviceready() {
try {
// Print menu links to console to inspect the JSON structure.
dpm(drupalgap.menu_links);
// Make alterations here...
drupalgap.menu_links['taxonomy/vocabulary/%'].title_callback = 'vocab_page_title';
drupalgap.menu_links['taxonomy/term/%'].title_callback = 'term_page_title';
}
catch (error) { console.log('my_module_deviceready - ' + error); }
}

function vocab_page_title(callback, vid) {
try {
// Try to load the vocab title, then send it back to the given callback.
var title = '';
var vid = arg(2);
var vocab = taxonomy_vocabulary_load(vid, {
success: function(vocab) {
if (vocab && vocab.name) { title = vocab.name; }
callback.call(null, title);
}
});
}
catch (error) { console.log('vocab_page_title - ' + error); }
}

function term_page_title(callback, tid) {
try {
// Try to load the term title, then send it back to the given callback.
var title = '';
var tid = arg(2);
var term = taxonomy_term_load(tid, {
success: function(term) {
if (term && term.name) { title = term.name; }
callback.call(null, title);
}
});
}
catch (error) { console.log('vocab_page_title - ' + error); }
}

tyler.frankenstein’s picture

Status: Active » Closed (works as designed)

Thanks for the thorough follow up. I'll eventually move a similar solution into DrupalGap core, since it makes no sense to display the title of the page as "Taxonomy term" or "Taxonomy vocabulary" as it currently does.