Skip to content

Instantly share code, notes, and snippets.

@mjordan
mjordan / gist:8388769
Created January 12, 2014 18:53
Example Drupal / Islandora hook_permission.
<?php
/**
* Implements hook_permission().
*/
function islandora_fits_permission() {
return array(
'view technical metadata' => array(
'title' => 'View technical metadata',
),
@mjordan
mjordan / gist:8388925
Created January 12, 2014 19:03
Example hook_theme()
<?php
/**
* Implements hook_theme().
* Registers all theme hooks defined by this module.
*/
function mymodule_theme() {
return array(
'mymodule_my_hello' => array(
'variables' => array(
@mjordan
mjordan / gist:8388943
Last active January 3, 2016 01:29
Example Drupal / Islandora theme callback
<?php
/**
* Theme callback.
* @param array $variables
*/
function theme_mymodule_my_hello($variables) {
$title = $variables['title'];
// Create markup
@mjordan
mjordan / gist:8388973
Created January 12, 2014 19:07
Example hook_theme() with template
<?php
/**
* Implements hook_theme().
* Registers all theme hooks defined by this module.
*/
function mymodule_theme() {
return array(
'mymodule_my_hello' => array(
'variables' => array(
@mjordan
mjordan / gist:8389001
Created January 12, 2014 19:09
Example Drupal / Islandora preprocess function
<?php
/**
* Preprocess function to format and sanitize output before
* sending it to the template.
*
* @param array &$variables
*/
function template_preprocess_mymodule_hello(&$variables) {
$variables['title'] = check_plain($variables['title']);
@mjordan
mjordan / gist:8391454
Last active January 3, 2016 01:49
Sample REL-EXT datastream
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:fedora="info:fedora/fedora-system:def/relations-external#"
xmlns:fedora-model="info:fedora/fedora-system:def/model#"
xmlns:islandora="http://islandora.ca/ontology/relsext#">
<rdf:Description rdf:about="info:fedora/changeme:2">
<fedora-model:hasModel rdf:resource="info:fedora/islandora:sp_basic_image">
</fedora-model:hasModel>
<fedora:isMemberOfCollection rdf:resource="info:fedora/islandora:sp_basic_image_collection">
</fedora:isMemberOfCollection>
</rdf:Description>
@mjordan
mjordan / gist:8391784
Created January 12, 2014 22:51
hook_CMODEL_PID_islandora_view_object()
<?php
/**
* Generate an object's display for the given content model.
*
* Content models PIDs have colons and hyphens changed to underscores,
* to create the hook name.
*
* @param AbstractObject $object
* A Tuque FedoraObject
@mjordan
mjordan / gist:8391848
Created January 12, 2014 22:56
Example islandora_datastream_access()
<?php
if (islandora_datastream_access(FEDORA_VIEW_OBJECTS,
$islandora_object['DC'])) {
// Do something
}
?>
@mjordan
mjordan / gist:8391902
Created January 12, 2014 23:01
hook_islandora_xml_form_builder_forms()
<?php
/**
* This hook allows modules to add default forms to form builder.
*
* @return array
* An associative array mapping unique names to associative arrays containing a
* single key:
* - form_file: A string containing the path to the form definition, relative
* to the webserver's document root (such that I might be opened
@mjordan
mjordan / gist:8392069
Created January 12, 2014 23:22
Example of pre hook_islandora_derivative derivative generation in Islandora
<?php
/**
* Implements hook_CMODEL_PID_islandora_object_ingested().
*/
function islandora_pdf_islandora_sp_pdf_islandora_object_ingested($object) {
module_load_include('inc', 'islandora_pdf', 'includes/derivatives');
islandora_pdf_create_all_derivatives($object);
}