1

I have created a custom render in group_module.js exactly as the example Rendering Entities with the exception of the line items['group/%'] = { instead of items['team/%'] = {. All other content nodes but group nodes (group/%) show ok. Group nodes show no subscribe/unsubscribe button and no menu tabs mentioned below in the groups_menu_module.js. I suppose that this module, groups_menu_module.js, is not loaded somehow.
I have to mention that without the custom rendering of entity group and with 2 LOCAL_TASK_MENU menu tabs, everything works perfect.

groups_menu_module.js

function groups_menu_module_menu() {
  try {
    var items = {};
    items['group/%']={
      title: 'view',
      page_callback: 'drupalgap_get_entity',
      page_arguments: ['groups_menu_module_default_page', 'node', 1]
    };
    items['group/%/provoli'] = {
      title: 'view',    
      type: 'MENU_DEFAULT_LOCAL_TASK'
    };
    items['group/%/melh'] = {
      title: 'members',
      type: 'MENU_LOCAL_TASK',
      page_callback: 'groups_menu_module_melh_page',
      page_arguments: [1],
      title_callback: 'groups_menu_module_melh_page_title',
      title_arguments: [1],
      access_callback: 'groups_menu_module_page_access',
      access_arguments: [1],
      options: {
        reloadPage: true
      }
    };
    items['group/%/anarthseis'] = {
      title: 'posts',
      type: 'MENU_LOCAL_TASK',
      page_callback: 'groups_menu_module_anarthseis_page',
      page_arguments: [1],
      access_callback: 'groups_menu_module_page_access',
      access_arguments: [1],
      options: {
        reloadPage: true
      }
    };
    return items;
  }
  catch (error) {
    console.log('groups_menu_module_menu - ' + error); 
  }
}

function groups_menu_module_default_page(node) {
  try {
    var content = {};
    content['title'] = { markup: node.title };
    return content;
  }
  catch (error) { 
    console.log('groups_menu_module_default_page - ' + error); 
  }
}

I have to mention that all functions needed are present in the actual .js file, i just opted them out because i think they are irrelevant. The pageshow function of the other module is as the example in the above link:

group_module.js

function example_team_pageshow(nid) {
  node_load(nid, {
    success: function(node) {
      var content = node.title; // Add other content here...
      $('#' + example_team_container_id(nid)).html(content).trigger('create');
    }
  });
}

So to conclude the question is how to make the subscribe/unsubscribe button appear in the custom entity render? How to call og_ui_field_formatter_view() from my module to make the button appear?

I don't know if i made my self clear what is needed. If anyone need more information please ask so in the comments below to clarify some points.

1

Since you are taking over the display of Organic Groups nodes using your custom page callback path group/%, DrupalGap doesn't know to apply the field format view functions to your fields. Essentially you need to manually create/render your own widgets in your page_callback:

var content = {};
content.title = { /* ... */ };
content.subscribe = { /* ... */ };
return content;

There are helper functions in the og.js file related to joining/leaving groups that will be of help. From there just use simple HTML/CSS/JS to build your button(s) (perhaps with an onclick handler) to help the user interact with the group subscriptions.

If you want to call the og_ui_field_formatter_view() function directly (not recommended) you can, you just need to pass it all the correct parameters:

(entity_type, entity, field, instance, langcode, items, display)

Not the easiest things to do to be honest, and you'll probably find yourself happier in the long run by building your own custom widget to subscribe/unsubscribe from the Group.

Feel free to copy any code you need from the og.js file to make your life easier.

| improve this answer | |
  • @tyler-frankestein So there is no other way of calling og_ui_field_formatter_view() from my module or altering the onclick handler? Of what i understand, what you suggest is making the button from scratch? – roko May 29 '17 at 21:16
  • I've updated my answer to include details about calling the function directly, but as you noticed, I'd really recommend just building the widget from scratch, that way you have complete control over it. – tyler.frankenstein May 30 '17 at 2:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.