0

I am trying to do module with different share buttons in form of field to content type. It has no settings, I just need to enable it in admin panel and the button should appear on node. But I cannot get to work simple sample of code like this:

function fblike_field_info() { return array( 'fblike' => array( 'label' => t('Facebook Like'), 'description' => t('This field displays Facebook Like button.'), 'settings' => array(), 'instance_settings' => array(), 'default_widget' => 'fblike_default_widget', 'default_formatter' => 'fblike_default_formatter', ), ); } function fblike_field_widget_info() { return array( 'fblike_default_widget' => array( 'label' => 'Like Box', 'field types' => array('fblike'), ), ); } function fblike_field_formatter_info() { return array( 'fblike_default_formatter' => array( 'label' => t('Like Box (default)'), 'field types' => array('fblike'), ), ); } function fblike_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { $link = '<div class="fb-like" data-href="HTTP://ENTER.YOUR.URL.HERE" data-width="80" data-layout="box_count" data-action="like" data-show-faces="false" data-share="false"></div>'; $element = array(); $element[0] = array('#markup' => $link); return $element; } 

The result of this code is:

<div class="field field-name-field-lubi-to field-type-fblike field-label-above"> <div class="field-label">Like:&nbsp;</div> <div class="field-items"></div> </div> 

I already run out of ideas. I have created many modules with fields before, but none was that simple... Am I missing something?

1 Answer 1

0

Ok, got this. As far as my field has nothing in $items, in order to print something I had to use this snippet:

function fblike_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) { foreach ($entities as $id => $entity) { if (empty($items[$id])) { $items[$id][0] = 'something'; } } } 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.