Hi, I try to make the widget available as a field in the layout screen of DisplaySuite module. Creating a new field whith at admin/ds/nd/fields using following code:
but I don´t now to look for the rate widget id.

$widget_id = 'the id of the rating widget here';
print rate_generate_widget($widget_id, 'node', $object->nid);

If you can help me please
thanks

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jonlhouse’s picture

Hi. I'm having similar problems with display the rate widget with Display Suite. I'm using the dev version of rate (7.x-2.x-dev) and the 7.x-2.4 voting-api module.

For my needs I'm creating a "yes/no" vote widget for a agree/disagree vote (machine name: agree_disagree_vote) on a specific node content type. I've read through your readme and tried a number of different hacks including:
<?php print $node->rate_agree_disagree_vote['#markup']; ?>
directly in my custom display suite layout .tpl file. The contents of $node that display suite was "seeing" didn't include any array prefixed with "rate". I also tried creating a custom vote widget using the steps you outlined with the same result (not much).

When I disabled display suite the "agree" and "disagree" buttons appeared in my full node view but were text only (no link to submit a vote).

Specific to display suite the above poster suggested adding a custom field to display suite which sounds like a good idea. However, I can't figure out how to get from the exposed $entity object to your specific rate field to do a print on rate_NAME ['#markup'];.

Also, probably worth a category of its own but have you looked into created a field that can be used in the D7 field UI that way the location and style can be managed with some of the new mods (panels3, display suite).

I'm new to drupal and php (my background is java and C) and I'm learning this as I go, so sorry for any silly questions.

mauritsl’s picture

I will take a look at ways for a clean integration with ds, but for now you may use the rate_embed function:

print rate_embed($node, 'agree_disagree_vote', RATE_FULL);

jonlhouse’s picture

Thanks!

jonlhouse’s picture

Question: Where do I put the custom .css file and what is the naming convention for a custom rate widget?

Things seem to be working better, I'm getting the stock widgets to work. I'm having trouble getting a custom widget css to work though. I've created a custom widget called "agree_disagree" and have created the "rate-widget--agree-disagree.tpl.php" file and placed that in themes/mytheme/template. That is working well (full control over the output).

The css include for this custom widget isn't working though. I've created a custom css file (based on the yesno.css template) and renamed the class variable to match the tpl generated html. I've verified that css class names in the .css file match the html output as shown in firebug.

I've tried the following locations: site/all/themes/mytheme/css, sites/all/themes/mytheme/templates (where the custom .tpl file is) and the following naming conventions: rate-widget--agree-disagree.css, agree-disagree.css. Any further help would be much appreciated. Thanks.

andrebonfanti’s picture

subscribe.

TimelessDomain’s picture

I tried #2 by putting the coding here as a custom field w/ php filter http:/yoursite.com/admin/structure/ds/fields/manage_custom, but it did not work/

Another work-around: now that views integration is possible - #1083250: widget tag not showing up in views relationship. You could use a views reference field for the actual nodes & use the NID from url argument. Or even better, use http://drupal.org/project/viewfield now that it finally has a d7 branch

ozsi’s picture

DS uses the $entity variable, so you can use this code:

<?php
   print rate_embed($entity, 'agree_disagree_vote', RATE_FULL); 
?>
hedley’s picture

I'm adding rate as a custom display suite field, in a custom module:

/**
 * Implements hook_ds_fields_info().
 */
function MYMODULE_ds_fields_info($entity_type) {

  // Provide a custom field to display suite
  $fields = array();

  $fields['node']['rate'] = array(
    'title' => t('Rate'),
    'field_type' => DS_FIELD_TYPE_FUNCTION,
    'function' => 'MYMODULE_ds_field_rate',
  );

  return $fields;
}

function MYMODULE_ds_field_rate($field) {
   return rate_embed($field['entity'], 'like', RATE_FULL);
}

Just change 'like' to whatever the machine name of your widget is, and MYMODULE to your own modules name.

pedrosp’s picture

I assume because of the "entity" stuff, this code is no compatible with the D6 release.

Any tips on how to integrate Rate onto Display Suite for D6 version ?
Talking about performance is it better to go with custom field or custom module ?

Thanks

drew29’s picture

Hej,

when I put the code

<?php
   print rate_embed($entity, 'agree_disagree_vote', RATE_FULL);
?>

in a custom display suite field and change the input filter to display suite code nothing will be display in my frontend :-(

can you help me to solve this problem?

kind regards
drew

joelrotelli’s picture

Thanks, #8 works perfectly, you should try this #10 !

pardalman’s picture

Hi,
Adding the code:

$widget_id = '1'; // the id of the widget as shown in the url of the rate widget (in this case 1)
print rate_generate_widget($widget_id, 'node', $entity->nid);

Works fine for showing the widget on the content but what about showing the rate widget for comments? how can this be made?
Thanks in advance!

XmhO’s picture

I haven't tried but I guess that if you replace "node" with "comment" and "$entity->nid" with "$entity->cid", It should work.

RKopacz’s picture

I'm trying to do the same thing, generate a widget in a display suite code field, and I cannot get anything to work.

I've tried the rate_embed function but continue to get an error

'Trying to get property of non-object in rate_embed() (line 743 of /opt/lampp/htdocs/sf_new/sites/all/modules/rate/rate.module).

I'm going to try to write the module suggested in #8 next, but it seems to me one should be able to embed this as a code field in DS. I've looked at that line but I'm not enough of a PHP ninja to figure it out :(

XmhO’s picture

$widget_id = '1'; // the id of the widget as shown in the url of the rate widget (in this case 1)
print rate_generate_widget($widget_id, 'node', $entity->nid);

It should work fine. Maybe you're not specifying appropriate parameters in your rate_generate_widget() function.

Erik Seifert’s picture

Create your custom module

function my_module_ds_fields_info() {

  $fields['node']['rate_integration'] = array(
    'title' => t('Rate integration'),
    'field_type' => DS_FIELD_TYPE_FUNCTION,
    'function' => 'theme_rate_integration',
    'properties' => array(
      'settings' => array( 'widget_id' => false),
      'default' => array('widget_id' => false),
    )
  );
  return $fields ;
}

function my_module_rate_integration($vars) {
  $entity = $vars['entity'] ;
  $entity_type = $vars['entity_type'] ;
  
  $widget_id = $vars['properties']['settings']['widget_id']; 
  
  return rate_generate_widget($widget_id, 'node', $entity->nid);
  $widgets = variable_get(RATE_VAR_WIDGETS, array());
}

function my_module_ds_field_settings_form($field) {
  $settings = isset($field['formatter_settings']) ? $field['formatter_settings'] : $field['properties']['default'];
  
  $widgets = variable_get(RATE_VAR_WIDGETS, array());

  $options = array();
  $options[0] = t('Choose a widget') ;
  foreach ( $widgets as $wid => $widget ) {
    $options[$wid] = $widget->name ;
  }
  $form['widget_id'] = array(
    '#type' => 'select',
    '#title' => t('Widget'),
    '#options' => $options,
    '#default_value' => $settings['widget_id'],
  );
  
  return $form;
}
XmhO’s picture

What is the difference with #8 ?

Erik Seifert’s picture

You can choose the rate widget in the ds settings.

Erik Seifert’s picture

Here the correct version.

function my_custom_module_ds_fields_info() {

  $fields['node']['rate_integration'] = array(
    'title' => t('Rate integration'),
    'field_type' => DS_FIELD_TYPE_FUNCTION,
    'function' => 'theme_rate_integration',
    'properties' => array(
      'default' => array('widget_id' => false),
    )
  );
  
  $fields['comment']['user_rendered_profile'] = array(
    'title' => t('Rendered User'),
    'field_type' => DS_FIELD_TYPE_FUNCTION,
    'function' => 'theme_user_profile_ds',
  );
  $fields['node']['user_rendered_profile'] = $fields['comment']['user_rendered_profile'];
  return $fields ;
}

function theme_rate_integration($vars) {
  $entity = $vars['entity'] ;
  $entity_type = $vars['entity_type'] ;
  $settings = isset($vars['formatter_settings']) ? $vars['formatter_settings'] : $vars['properties']['default'];
  $widget_id = $settings['widget_id'] ;
  return rate_generate_widget($widget_id, 'node', $entity->nid);
}

function my_custom_module_ds_field_settings_form($field) {
  $settings = isset($field['formatter_settings']) ? $field['formatter_settings'] : $field['properties']['default'];
  
  $widgets = variable_get(RATE_VAR_WIDGETS, array());

  $options = array();
  $options[0] = t('Choose a widget') ;
  foreach ( $widgets as $wid => $widget ) {
    $options[$wid] = $widget->name ;
  }
  $form['widget_id'] = array(
    '#type' => 'select',
    '#title' => t('Widget'),
    '#options' => $options,
    '#default_value' => $settings['widget_id'],
  );
  
  return $form;
}
JRZ-2’s picture

Thanks ! it works perfectly.

Erik Seifert’s picture

Version: 7.x-1.0-beta2 » 7.x-1.6
FileSize
1.32 KB

New Version of Integration for Display Suite:

- Add support for comments
- Add support for Display Mode (Compact,Closed....)

Could be go as submodule into rate module

Have Fun

aalireza’s picture

New Version of Integration for Display Suite:

- Add support for comments
- Add support for Display Mode (Compact,Closed....)

Could be go as submodule into rate module

Have Fun

hi, i installed this module ,
how work? this module add new field "Rate integration" i enabled Rate integration but not showing rate module.

Erik Seifert’s picture

- Install Module
- Add new Rate widget
- A new field should appear in DS Settings for a content type

deanflory’s picture

Step 4: - Click settings cog icon and choose which widget to use
Step 5: - Save the Manage Display form to save the settings to your node type for that Display Suite display mode

Thanks erikseifert! It worked as expected and with an existing widget (in case anyone needs to know that you don't have to create a new widget to get it to work).

erikseifert, you should definitely add this as a module or submodule to ensure more people can find it and use it, otherwise it would be nearly impossible to find again without these keywords below or rummaging through countless issues:

Rate Display Suite
Rate DS
rate_ds
rate-ds
rate_field
rate-field
Rate Field
rate_ds.zip

therobyouknow’s picture

It is not clear from these comments which "Field type" is needed for a new rate widget - Integer? Decimal?

What are the complete steps for using the code provided in comment #19 ( https://drupal.org/node/1069906#comment-7047316 ) ?

erikseifert states some of the steps in comment #23 https://drupal.org/node/1069906#comment-7466882
and deanflory appears to added to erikseifert's steps in #24 https://drupal.org/node/1069906#comment-7558959

Let me have a go at creating the full steps:

1) create a module and paste in code from #19 ( https://drupal.org/node/1069906#comment-7047316 ) ? Specifically just paste the whole code from comment #19 into your .module file, nothing else needed
2) enable the module
3) create a new rate widget in admin/structure/rate
4) create a new field admin/structure/types/manage/resource-article/fields
- now here's where I need advice (where I get stuck as described above) - when I create a new field, I:
enter the word Rate beneath "Add new field" then for field type I'm not sure what to use: Decimal? Integer?
and then finally when I try to choose the rate widget from the widget drop down, it's not there, only "Text field"

fantom84’s picture

for module in the #21:
if DS version 7.x-2.x we need to add 'settings' => array() in properties array in the rate_ds_ds_fields_info() function:

function rate_ds_ds_fields_info() {

  $fields['node']['rate_integration'] = 
  $fields['comment']['rate_integration'] = array(
    'title' => t('Rate integration'),
    'field_type' => DS_FIELD_TYPE_FUNCTION,
    'function' => 'theme_rate_ds',
    'properties' => array(
      'default' => array('widget_id' => false,'display_mode' => RATE_FULL ),
      'settings' => array(),
    )
  );
  return $fields ;
}

without this function rate_ds_ds_field_settings_form($field) don't call

Erik Seifert’s picture

You don't need to add a field. You must only add a widget in admin/structure/rate . After this a new Display Field appear under manage display.

Erik Seifert’s picture

Thanks, i will update this module as soon as possible.

adam7’s picture

#21 & #26.

We also need:

function rate_ds_ds_field_format_summary($field) {
  $settings = isset($field['formatter_settings']) ? $field['formatter_settings'] : $field['properties']['default'];
  return 'widget_id: ' . $settings['widget_id'] . '<br />display_mode: ' . $settings['display_mode'];
}
gmario’s picture

#29

and last (when you are configuring fields visible in display's tab for a content type: admin/structure/types/manage/your-content-type/display) you have to configure field settings of Rate integration (click on gearwheel at right side) to choose which rate's widget has to be used

a si biri
gmario

mahipal46’s picture

#8 worked for me. Thanks.
In rate_embed($field['entity'], 'like', RATE_FULL); replace 'like' with your tag name specify in your rate widget.

bburg’s picture

FileSize
3.08 KB

This patch takes the module in #21 and subsequent suggestions and integrates them directly into the rate module. Works for me.

bburg’s picture

In hindsight, "Rating" would be a better title for the ds field...

gildir’s picture

Status: Active » Needs review
FileSize
1.62 KB

Alternative integration with DS. Creates one field per widget (in case there is the need for multiple rate widgets on a page) and follows the show/hide options in the rate module instead of in the content type field display mode layout.

mach5_kel’s picture

FileSize
1.41 KB

Here is an updated version of the rate_ds module with the suggestions posted above added. Ie #21 , #26, #29.

I tested it with the latest dev version of rate module and it appears to be working correctly. Thank you for the suggestions above. So far this is the easiest (working) solution.

gildir’s picture

FileSize
3.39 KB

Small adjustment to patch in #34 for anyone interested in that one. Reminder: this is an alternative approach than the primary one suggested in this thread for people who either need more than one widget per page and/or want to use the rate module show/hide options settings.

gildir’s picture

FileSize
3.5 KB

Additional bug fixes from #36.

dtarc’s picture

Issue summary: View changes
FileSize
1.69 KB

I couldn't get the patch in #37 to apply, it seems like it is in some kind of weird binary format. Here's a reroll.

dtarc’s picture

Updated patch with a bug fix for comment display.

Knud’s picture

The module at #35 seems to work very well, nice and easy. Thank you !

sinasalek’s picture

Module in #35 works like a charm against the latest dev version,
Thanks a lot :)

Sigvard’s picture

Okay I am a bit confused now.

I run DIsplay suit 7.x-2.6 and Rate module 7.x-1.6.

Ratings show up on comments but not on my actual content. I use a Number up/down widget for nodes and comments (same widget for both). The option to rate things (and the current rating) shows up for comments but not for nodes.

Which version of the patches/modules above should I download? And can someone give me a brief installation guide (I am very weak in Drupal-work and does not know how to apply patches)

Sigvard’s picture

Instead of patches I think it is much easier to use the original askers code but refer to $entity rather than $object.

I jsut added the following code in a code field (text format display suite code).

$widget_id = '1';
print rate_generate_widget($widget_id, 'node', $entity->nid);

Widget ID:s are easy to guess as the first widget got ID 1 and the second one ID 2 etc. Trial and error solved that for me.

jaydee1818’s picture

Patch #39 works for me. Any chance this feature will be rolled into the module?

chilic’s picture

Patch #39 works for me.

phamkhaclam90@gmail.com’s picture

The rate_ds module is useful for our project. Please push it as a Drupal project if you can, thanks!

Erik Seifert’s picture

I can open a project, but i cant maintance this project. Anybody here to become a maintancer ?

yannickoo’s picture

A new project for this integration? It's cooler to put the Display Suite integration into Rate.

Erik Seifert’s picture

Yep.

But this solution do not find a way in to this module since 3 Years.

mauritsl’s picture

Erik, I have sent you a message via the contact form about this issue. I'm open for the possibility to maintain this within the Rate module.

deanflory’s picture

Committed to Rate?

doxigo’s picture

seriously what happened to this feature? can anybody just integrate this with rate module ?

jonraedeke’s picture

Patch #39 works for me beautifully.

BarisW’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #39 works great. Please commit.

alibama’s picture

#35 worked fine, #39 worked fine - both are roughly equivalent... neither worked off the shelf with drupalgap, but that's probably not the fault here...

Dajka’s picture

#39 worked for me too. Thank you.

kopeboy’s picture

Title: How to display whith display suite » Integration with Display suite
Version: 7.x-1.6 » 7.x-1.7
Priority: Normal » Major

Can the maintainers please commit this?!?

Is this still valid for version 1.7?

NikGleb’s picture

In my opinion, the way to sub-module #35 is a more flexible solution. It has the ability to customize the widget display option, depending on the mode of output (and not only in the Rate module settings - default and teaser).
My site has a lot of view modes the output content (default, teaser, list, etc.) and for each mode I can adjust the display type of the widget.
With patch #39 I did not see such a possibility.

jOksanen’s picture

This is a really critical issue for me on using this module. I hope that a solution is provided and committed soon.

I agree with NikGleb (#58). The sub-module approach seems simply cleaner to me. Adding that Zip into github to use it in drush make builds for now.

ezoulou’s picture

#39 works for me (rate version : 7.x-1.7).
It is simple and does what I expected : create a fieldable rate widget on a display suite layout. thanks.

dtabach’s picture

I tried some of the approaches here, patch to rate module (#39), independent rate_ds module(#35), and creating a code field with Display Suite (#43) and they worked, but with the same little bug.

The 'Thumbs up/down' full widget does not display correctly in full node view.

It works in teasers as expected.

But in the full content page, it shows as if no one had ever voted , showing 50%-50%. When someone votes, it briefly behaves correctly, showning the text "You voted '[up/down]' ", but it returns to its previous state when the page is refreshed.

I described the bug here: https://www.drupal.org/node/2913010

Now I see this isn't a Rate module bug, but related to Rate integration with DS.