From 5ed7dc47e97d4655d8b7ce7563589b50a0f1ff25 Mon Sep 17 00:00:00 2001 From: mkinnan Date: Fri, 4 Aug 2017 14:59:01 -0600 Subject: [PATCH] Display Flags on Custom Entity Rendering --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/README.md b/README.md index 39a2201..79a57e0 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,48 @@ drupalgap.settings.flag = { The flag module for DrupalGap will automatically prepend a flag button to an entity's content when the entity is being viewed. +### Render Flags on Custom Entity Rendering + +If you override the default node display following the tutorial found here (http://docs.drupalgap.org/7/Entities/Rendering_Entities), then you can easily display flags on your custom rendering using the following code example: + +``` +function my_module_team_page(node) { + var content = {}; + + var entity_type = 'node'; + var bundle = node.type; + var entity_id = node.nid + + var flags = flag_get_entity_flags(entity_type, bundle); + + var page_id = drupalgap_get_page_id(); + $.each(flags, function(fid, flag) { + + // Build the render array. + content['flag_' + fid]= { markup: '
' + + drupalgap_jqm_page_event_script_code( + { + page_id: page_id, + jqm_page_event: 'pageshow', + jqm_page_event_callback: '_flag_pageshow', + jqm_page_event_args: JSON.stringify({ + fid: fid, + entity_id: entity_id, + entity_type: entity_type, + bundle: bundle + }) + }, + entity_type + '-' + entity_id + '-' + flag.fid + ) }; + + }); + + return content; +} + + +``` + #### Views Render Array Row Quick Links for Flags If you'd like to provide flags next to some list items from a Views Render, set up your Views JSON to return something like this: