Follow

Pugpig Hooks

Drupal hooks are PHP functions with the form MODULENAME_NAMEOFHOOK. More information on Drupal Hooks can be found here. Pugpig has many built in hooks that you can use to modify and improve your app.

  • OPDS
  • Edition Atom
  • Manifest
  • Pugpig Sounds

OPDS HOOKS

pugpig_opds_custom_categories

This hook adds custom categories in the OPDS feed. Custom categories can be used for tags, setting options (see our API Spec) and other custom needs in your app.

function custom_module_pugpig_opds_custom_categories($node) {
$type = '';
$type = $node->field_pugpig_type['und'][0]['value'];

return array('edition_type' => $type);
}

EDITION ATOM HOOKS

pugpig_page_sharing_link

This hook adds a sharing link to the edition atom feed. By default sharing is enabled and clicking the share button in the app will share a permalink to the page. Return null to disable sharing, an external url to link to that or a ' ' (space) to share an image such as a screenshot. If you return a space you need to define elsewhere in the the sharing_mode. See custom_module_pugpig_content_sharing_link below.

function custom_module_pugpig_content_sharing_link($node) {

return pugpig_value($node, 'field_sharing_link');
}

pugpig_display_title

This hook allows you to change the title of a post in the edition atom feed.

function custom_pugpig_display_title($node) {
$title = pugpig_value($node, 'field_heading', 'value', $node->title);

return $title;
}

pugpig_page_level

This hook sets the level of $node.

function custom_pugpig_page_level($node) {
$level = 2;
if(isset($node)) {
$level = 1;
}

return $level;
}

pugpig_display_summary

This hook changes the summary text in the edition atom feed. The summary text by default takes it's value from the custom field field_summary. If this field does not exist or if you want to overwrite it you can use this hook. In this case the summary is shorten to 40 character however you could just replace the summary.

function custom_pugpig_display_summary($node) {

return pugpig_value($node, 'field_title_alt');
}

pugpig_page_hidden

This hook hides a page from the edition atom feed. You should return a boolean value. True equates to hidden and False to shown.

function custom_pugpig_page_hidden($node) {

return pugpig_value($node, 'field_hide_page');
}

pugpig_page_categories

This hook adds sections in the Atom feed. Sections are used, among other things, for define sections in the Table of Contents in your app. In the example below the section name is taken from the custom_section field.

function customapp_pugpig_page_categories($node) {
$sections_names = null;
$section_tid = field_get_items('node', $node, 'field_contents_section');
if (!empty($section_tid[0]['tid'])) {
$tid = $section_tid[0]['tid'];
$taxonomy_term = taxonomy_term_load($tid);
if (!empty($taxonomy_term->name)) {
$sections_names = array($taxonomy_term->name);
}
return $sections_names;
}
return '';
}

pugpig_page_custom_categories

This hook adds custom categories in the Atom feed. Custom categories can be used for tags, setting options (see our API Spec) and other custom needs in your app.

function customapp_pugpig_page_custom_categories($node) {
$custom_categories = array();

$hidden = pugpig_value($node, 'field_hide_in_table_contents');

if ($hidden) {
$custom_categories['toc_style'] = 'hidden';
}

return $custom_categories;
}

MANIFEST HOOKS

pugpig_get_extra_manifest_attachments

This hook allows you to add attachments to the manifest. You should add a string will a link to the attachment, for example ../data/[NID]/assets/... One attachment should be added per line.

function customapp_pugpig_get_extra_manifest_attachments($node, $edition_id) 
{
Some logic ...

return $attachments;
}

Pugpig Sounds HOOKS

pugpig_page_sounds

This hook adds the the sounds link to the edition atom feed. You should return an array with the relevant values.

function customapp_pugpig_page_sounds($node) 
{
Some logic ...

$return = array(
'type' => $type,
'href' => $filepath,
'title' => $title,
'creator' => $creator,
'icon' => $iconpath
);
}

There is a Pugpig Sounds module with Pugpig for Drupal. If you activate this module it will create custom content type and hooks for you.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

Powered by Zendesk