added share field formatter
This commit is contained in:
@@ -499,15 +499,16 @@ function chapitre_field_default_field_instances() {
|
|||||||
'display' => array(
|
'display' => array(
|
||||||
'chapter' => array(
|
'chapter' => array(
|
||||||
'label' => 'above',
|
'label' => 'above',
|
||||||
'module' => 'text',
|
'module' => 'jeemod',
|
||||||
'settings' => array(),
|
'settings' => array(),
|
||||||
'type' => 'text_default',
|
'type' => 'share_butons',
|
||||||
'weight' => 4,
|
'weight' => 4,
|
||||||
),
|
),
|
||||||
'default' => array(
|
'default' => array(
|
||||||
'label' => 'above',
|
'label' => 'above',
|
||||||
|
'module' => 'jeemod',
|
||||||
'settings' => array(),
|
'settings' => array(),
|
||||||
'type' => 'hidden',
|
'type' => 'share_butons',
|
||||||
'weight' => 4,
|
'weight' => 4,
|
||||||
),
|
),
|
||||||
'teaser' => array(
|
'teaser' => array(
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ dependencies[] = features
|
|||||||
dependencies[] = field_collection
|
dependencies[] = field_collection
|
||||||
dependencies[] = field_group
|
dependencies[] = field_group
|
||||||
dependencies[] = image
|
dependencies[] = image
|
||||||
|
dependencies[] = jeemod
|
||||||
dependencies[] = node
|
dependencies[] = node
|
||||||
dependencies[] = strongarm
|
dependencies[] = strongarm
|
||||||
dependencies[] = text
|
dependencies[] = text
|
||||||
|
|||||||
@@ -41,8 +41,6 @@ function jeemod_entity_info_alter(&$entity_info) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements hook_video_embed_field_handlers_alter().
|
* Implements hook_video_embed_field_handlers_alter().
|
||||||
*/
|
*/
|
||||||
@@ -106,3 +104,81 @@ function jeemod_handle_vimeo($url, $settings) {
|
|||||||
'?' . $settings_str . '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowfullscreen></iframe>',
|
'?' . $settings_str . '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowfullscreen></iframe>',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_field_formatter_info().
|
||||||
|
*/
|
||||||
|
function jeemod_field_formatter_info() {
|
||||||
|
return array(
|
||||||
|
'share_butons' => array(
|
||||||
|
'label' => t('Share butons (Twitter, Facebook)'),
|
||||||
|
'field types' => array('text'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_field_formatter_view().
|
||||||
|
*/
|
||||||
|
function jeemod_field_formatter_view($entity_type, $entity, $field, $instance, $lang_code, $items, $display) {
|
||||||
|
$element = array();
|
||||||
|
foreach ($items as $delta => $item) {
|
||||||
|
$element[$delta] = array(
|
||||||
|
'#theme' => 'jeemod_share_links',
|
||||||
|
'#entity' => $entity,
|
||||||
|
// '#url' => $entity->field_partager['und'][0]['url'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return $element;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_theme().
|
||||||
|
*/
|
||||||
|
function jeemod_theme() {
|
||||||
|
return array(
|
||||||
|
'jeemod_share_links' => array(
|
||||||
|
'template' => 'jeemod_share_links',
|
||||||
|
'variables' => array(
|
||||||
|
'entity' => NULL,
|
||||||
|
// 'url' => NULL,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function jeemod_preprocess_jeemod_share_links(&$vars){
|
||||||
|
global $base_url;
|
||||||
|
// dsm($vars);
|
||||||
|
$entity = $vars['entity'];
|
||||||
|
|
||||||
|
$sitetitle = variable_get('site_name', '');
|
||||||
|
$nodetitle = $entity->title;
|
||||||
|
$nodeurl = $base_url . base_path() . "#principe-" . $entity->nid;
|
||||||
|
|
||||||
|
$text = $nodetitle ." | ". $sitetitle . " - " . $nodeurl;
|
||||||
|
|
||||||
|
$tags = explode(' ', str_replace('#', '', $entity->field_partager['und'][0]['value']));
|
||||||
|
|
||||||
|
$vars['twitter_url'] = url("https://twitter.com/intent/tweet", array(
|
||||||
|
'absolute'=>true,
|
||||||
|
'query'=>array(
|
||||||
|
// "button_hashtag"=>implode(',',$tags),
|
||||||
|
"button_hashtag"=>$tags[0],
|
||||||
|
"text"=>$text,
|
||||||
|
)
|
||||||
|
));
|
||||||
|
$vars['twitter_title'] = "Twitter $nodetitle";
|
||||||
|
|
||||||
|
$vars['fb_url'] = url("https://www.facebook.com/sharer.php", array(
|
||||||
|
'absolute'=>true,
|
||||||
|
'query'=>array(
|
||||||
|
"u"=>$nodeurl,
|
||||||
|
"t"=>$text,
|
||||||
|
)
|
||||||
|
));
|
||||||
|
$vars['fb_title'] = "Partager $nodetitle";
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<a class="twitter-buttuon" href="<?php print $twitter_url; ?>" target="_blank">
|
||||||
|
<?php print $twitter_title; ?>
|
||||||
|
</a>
|
||||||
|
<br/>
|
||||||
|
<a class="fb-button" href="<?php print $fb_url; ?>" target="_blank">
|
||||||
|
<?php print $fb_title; ?>
|
||||||
|
</a>
|
||||||
Reference in New Issue
Block a user