-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathos_slideshow.module
57 lines (52 loc) · 1.51 KB
/
os_slideshow.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* @file
* Code for the OpenSourcery Slideshow feature.
*/
include_once('os_slideshow.features.inc');
/**
* Implements hook_bean_types_api_info().
*/
function os_slideshow_bean_types_api_info() {
return array(
'api' => 3,
);
}
/**
* Implements hook_bean_types().
*/
function os_slideshow_bean_types() {
$plugins = array();
$plugins['slideshow'] = array(
'label' => t('Slideshow'),
'handler' => array(
'class' => 'slideshow_bean',
'parent' => 'bean',
),
'file' => 'os_slideshow.info',
);
return $plugins;
}
/**
* Creates a new slide and adds it to the given slideshow bean.
*/
function os_slideshow_add_slide($bean, $image_path, $headline, $teaser, $link_title, $link_path) {
// Create a new slide field_collection entity
$slide = entity_create('field_collection_item', array('field_name' => 'field_slideshow_slides'));
$slide->field_slide_headline['und'][0]['value'] = $headline;
$slide->field_slide_teaser['und'][0]['value'] = $teaser;
$slide->field_slide_teaser['und'][0]['format'] = 'full_html';
$slide->field_slide_link['und'][0]['title'] = $link_title;
$slide->field_slide_link['und'][0]['url'] = $link_path;
$slide->setHostEntity('bean', $bean);
$file = (object) array(
'uid' => 1,
'uri' => $image_path,
'filemime' => file_get_mimetype($image_path),
'status' => 1,
);
$file = file_copy($file, 'public://');
$slide->field_slide_image['und'][0] = (array)$file;
$slide->field_slide_image['und'][0]['display'] = TRUE;
$slide->save();
}