Full ELMS Learning Network documentation
function cis_shortcodes_entity_view
cis7 cis_shortcodes.module | cis_shortcodes_entity_view($entity, $type, $view_mode, $langcode) |
cle7 cis_shortcodes.module | cis_shortcodes_entity_view($entity, $type, $view_mode, $langcode) |
elmsmedia7 cis_shortcodes.module | cis_shortcodes_entity_view($entity, $type, $view_mode, $langcode) |
icor7 cis_shortcodes.module | cis_shortcodes_entity_view($entity, $type, $view_mode, $langcode) |
meedjum_blog7 cis_shortcodes.module | cis_shortcodes_entity_view($entity, $type, $view_mode, $langcode) |
mooc7 cis_shortcodes.module | cis_shortcodes_entity_view($entity, $type, $view_mode, $langcode) |
Implements hook_entity_view().
File
- sites/
all/ modules/ elmsln_contrib/ cis_connector/ modules/ cis_shortcodes/ cis_shortcodes.module, line 23 - Handle shortcode generation for use in sites running cis_filter.
Code
function cis_shortcodes_entity_view($entity, $type, $view_mode, $langcode) {
$links = array();
// only add embed methods on full view with access
if ($view_mode == 'full' && user_access('view cis shortcode')) {
// pick a nice default title for common entity types
$title = '';
switch ($type) {
case 'node':
$title = $entity->title;
break;
case 'user':
case 'taxonomy_term':
$title = $entity->name;
break;
}
// load info so we know what the key id is
$type_info = entity_get_info($type);
// build properties array for rendering
$properties = array(
'rev' => CIS_SHORTCODES_API_REV,
'tool' => variable_get('install_profile', ''),
'item' => $entity->{$type_info['entity keys']['id']},
);
// only append type for non-node entities
if ($type != 'node') {
$properties['entity_type'] = $type;
}
// establish the fieldset container for shortcodes
$field['cis_shortcodes'] = array(
'#type' => 'fieldset',
'#collapsed' => FALSE,
'#collapsible' => TRUE,
'#title' => t('Short Codes to embed'),
'#weight' => -10,
);
if (module_exists('entity_iframe') && _entity_iframe_view_iframe($type, $entity->{$type_info['entity keys']['id']})) {
$field['cis_shortcodes']['cis_shortcodes_embed'] = array(
'#title' => t('Shortcode direct iframe'),
'#attributes' => array('class' => array('cis_shortcodes_embed')),
'#value' => _cis_shortcodes_build_code($properties),
'#type' => 'textfield',
'#pre_render' => array('_cis_shortcodes_add_js'),
'#weight' => 1,
);
}
$properties['render'] = 'link';
if (isset($type_info['bundle keys']['bundle']) && !empty($entity->{$type_info['bundle keys']['bundle']})) {
$field_list = field_info_instances($type, $entity->{$type_info['bundle keys']['bundle']});
}
else if (isset($type_info['entity keys']['bundle']) && !empty($entity->{$type_info['entity keys']['bundle']})) {
$field_list = field_info_instances($type, $entity->{$type_info['entity keys']['bundle']});
}
else {
// skip this, we don't have info about this type
$field_list = array();
}
foreach ($field_list as $fname => $fproperties) {
// check for things with uri's, if first item is, all are
if (isset($entity->{$fname}) && isset($entity->{$fname}['und'][0]['uri'])) {
foreach ($entity->{$fname}['und'] as $item_key => $item) {
$properties['field'] = $fname;
if ($type == 'node') {
$properties['text'] = t('Download @title', array('@title' => $title));
}
else {
$properties['text'] = t('Download');
}
$properties['delta'] = $item_key;
$field['cis_shortcodes']['cis_shortcodes_link_' . $fname . '_' . $item_key] = array(
'#title' => t('@field field: direct link', array('@field' => $fproperties['label'])),
'#attributes' => array('class' => array('cis_shortcodes_embed')),
'#value' => _cis_shortcodes_build_code($properties),
'#type' => 'textfield',
'#weight' => 3,
);
// special case for uri's that are images
if (isset($item['filemime']) && strpos($item['filemime'], 'image') === 0) {
$properties['item_type'] = 'image';
// support custom title and alt text in the code
if (!empty($item['title'])) {
$properties['text'] = $title;
}
else {
$properties['text'] = $title;
}
if (!empty($item['alt'])) {
$properties['alt'] = $item['alt'];
}
else {
$properties['alt'] = $title;
}
// use image as it was uploaded for defaults
$properties['width'] = $item['width'];
$properties['height'] = $item['height'];
$properties['delta'] = $item_key;
$field['cis_shortcodes']['cis_shortcodes_link_' . $fname . '_' . $item_key] = array(
'#title' => t('@field field: Render image', array('@field' => $fproperties['label'])),
'#attributes' => array('class' => array('cis_shortcodes_embed')),
'#value' => _cis_shortcodes_build_code($properties),
'#type' => 'textfield',
'#weight' => 3,
);
}
}
}
}
// check for unique tag capabilities
if (isset($entity->field_cis_tag) && isset($entity->field_cis_tag['und'])) {
// reset property array
$properties = array(
'rev' => CIS_SHORTCODES_API_REV,
'tool' => variable_get('install_profile', ''),
'item' => $entity->{$type_info['entity keys']['id']},
);
// only append type for non-node entities
if ($type != 'node') {
$properties['entity_type'] = $type;
}
$properties['item'] = $entity->field_cis_tag['und'][0]['value'];
$properties['item_type'] = 'tag';
if (module_exists('entity_iframe') && _entity_iframe_view_iframe($type, $entity->{$type_info['entity keys']['id']})) {
$field['cis_shortcodes']['cis_shortcodes_tag_iframe'] = array(
'#title' => t('Shortcode tagged iframe'),
'#attributes' => array('class' => array('cis_shortcodes_embed')),
'#value' => _cis_shortcodes_build_code($properties),
'#type' => 'textfield',
'#weight' => 2,
);
}
$properties['render'] = 'link';
$field['cis_shortcodes']['cis_shortcodes_tag_link'] = array(
'#title' => t('Shortcode tagged link'),
'#attributes' => array('class' => array('cis_shortcodes_embed')),
'#value' => _cis_shortcodes_build_code($properties),
'#type' => 'textfield',
'#weight' => 4,
);
}
// only render if we actually have data to display
if (count($field['cis_shortcodes']) > 5) {
$entity->content['cis_shortcodes'] = array(
'#markup' => drupal_render($field),
'#weight' => 100,
);
}
}
}