scald_example_content_type.module in Scald: Media Management made easy 6
Contains an example implementation of a node type that will be used to provide atoms to Scald. For this example sake, we(ll be providing Image atoms based on pictures attached to this node.
File
scald_example_content_type/scald_example_content_type.moduleView source
<?php
/**
* @file
* Contains an example implementation of a node type that will be
* used to provide atoms to Scald.
* For this example sake, we(ll be providing Image atoms based on
* pictures attached to this node.
*/
/**
* Implements hook_node_info.
*/
function scald_example_content_type_node_info() {
$types = array();
$types['scald_example_content_type'] = array(
'name' => 'Scald Example Image',
'module' => 'scald_example_content_type',
'description' => 'An example content type that registers files uploaded to its nodes as Atoms',
);
// return $types;
}
/**
* Implements hook_nodeapi.
* Dispatch the call to the corresponding D7 hook.
*/
function scald_example_content_type_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($node->type == 'scald_example_content_type') {
$function = 'scald_example_content_type_node_' . $op;
if (function_exists($function)) {
$function($node, $a3, $a4);
}
}
}
/**
* Implements hook_node_load (D7)
*/
function scald_example_content_type_node_load(&$node) {
$query = array(
'provider' => 'scald_example_content_type',
'base_id' => $node->nid,
);
$sid = scald_search($query, FALSE, TRUE);
return array(
'scald_sid' => $sid,
);
}
/**
* Implements hook_node_insert.
*/
function scald_example_content_type_node_insert(&$node) {
$atom = scald_example_content_type_get_atom($node);
scald_register_atom((array) $atom);
}
/**
* Implements hook_node_update.
*/
function scald_example_content_type_node_update(&$node) {
$atom = scald_example_content_type_get_atom($node);
if ($atom->sid) {
scald_update_atom($atom);
}
else {
scald_register_atom((array) $atom);
}
}
/**
* Returns an atom based on the node information.
*/
function scald_example_content_type_get_atom($node) {
$atom = new stdClass();
$atom->type = 'image';
$atom->provider = $node->type;
$atom->base_id = $node->nid;
$atom->publisher = $node->uid;
$atom->title = $node->title;
$aid = scald_uid_to_aid($node->uid);
$atom->authors = array(
$aid,
);
if (isset($node->scald_sid)) {
$atom->sid = $node->scald_sid;
}
return $atom;
}
/**
* Implements hook_scald_provider.
*/
function scald_example_content_type_scald_provider() {
return array(
'atoms' => array(
'image' => array(
'An image attached to an example node',
),
),
);
}
/**
* Implements hook_scald_fetch.
*/
function scald_example_content_type_scald_fetch(&$atom) {
$node = node_load($atom->base_id);
if (is_array($node->files) && count($node->files)) {
$file = reset($node->files);
}
$atom->base_entity = $node;
$atom->file_source = $atom->thumbnail_source = $file->filepath;
}
Functions
Name![]() |
Description |
---|---|
scald_example_content_type_get_atom | Returns an atom based on the node information. |
scald_example_content_type_nodeapi | Implements hook_nodeapi. Dispatch the call to the corresponding D7 hook. |
scald_example_content_type_node_info | Implements hook_node_info. |
scald_example_content_type_node_insert | Implements hook_node_insert. |
scald_example_content_type_node_load | Implements hook_node_load (D7) |
scald_example_content_type_node_update | Implements hook_node_update. |
scald_example_content_type_scald_fetch | Implements hook_scald_fetch. |
scald_example_content_type_scald_provider | Implements hook_scald_provider. |