Question

In Drupal 7 with Drupalgap, I have created a custom module in order to make a block. I have defined hook_block_info() and hook_block_view() as it is necessary.
What I want is making this block visible only in organic group nodes. So I need an access callback inside my groups_menu_module_block.js
Below you can see the function but it doesn't seem to work.

    function groups_menu_module_block_access_callback(options) {
        return og_is_group('node', Drupal.node.nid);
    }
Was it helpful?

Solution

You've stumbled across an early design flaw on my part, I didn't realize how important it would be to be able to make async calls when determining access to elements (pages, blocks, etc). To get around this (and other related issues), I added some helper functions to DrupalGap core.

The idea behind it is that the built in pages in DrupalGap are there for very simple applications, and more complex applications should build their own pages.

More info: http://docs.drupalgap.org/7/Entities/Rendering_Entities

The general idea is that you build a custom page(s), which will have a fully loaded entity delivered to its page_callback (which under the hood is actually a pageshow callback masquerading as a page_callback: http://docs.drupalgap.org/7/Pages/Page_Events).

Then in your page_callback when you are building the content object you already have access to the fully loaded entity, so you can make intelligent decisions about what is displayed.

With your example (and using the first link above), I'd recommend making a page with a path of group/%, and in your page_callback you can use custom widgets to simulate the block you are looking to render:

function my_module_group_page(node) {
  var content = {};
  content['my_nav_block'] = {
    theme: 'my_module_nav_block',
    node: node
  };
  content['foo'] = { /* ... */ };
  content['bar'] = { /* ... */ };
  content['etc'] = { /* ... */ };
  return content;
}

function theme_my_module_nav_block(variables) {
  var html = '';
  var node = variables.node;
  html += node.title;
  return html;
}

In hindsight it was silly of me to try and replicate Drupal's built in pages within DrupalGap (besides the user login/registration pages, etc) because every application should be unique. I now stricly use this approach and no longer use the vast majority of the built-in pages within DrupalGap.

So to answer your actual question, I would recommend building a Views JSON page display which only returns Group nodes, then your app can feed off of that and display a list of Group nodes, that when clicked go to your custom Group page.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top