Problem/Motivation

In Drupal 7 there are below options to print widgets, results etc and all is mentioned in documentation. It will be great help to users to add such in 8 documentation as well.

    <?php
    print theme('rate_button', array(
      'text' => $links[0]['text'],
      'href' => $links[0]['href'],
      'class' => "extra-class")
    );
    ?>

<?php print $results['rating']; ?>

print rate_embed($node, 'NAME', RATE_FULL);
print rate_embed($node, 'NAME', RATE_COMPACT);
print rate_embed($node, 'NAME', RATE_DISABLED);
print rate_embed($node, 'NAME', RATE_CLOSED);

How we can do similar in Drupal 8 twig template of node type.

Thanks!

Comments

jas1988 created an issue. See original summary.

jas1988’s picture

Title: Documentation regarding programatically printing rate widgets » Documentation regarding programmatically printing rate widgets
jordik’s picture

This functionality is not ported from D7.
And for now I do not see a necessity for it given the current functionality.
What is your use case for needing this in D8?

jas1988’s picture

Use-case examples:

  • General use is in twig template file for content type for example node--mycontenttype.html.twig and in this I have modified html of fields and added few other things in preprocess but not sure if there is way to add rate widgets
  • Have complete custom form with custom twig file where list of node are shown and under node title all fields are fetched. But with nid there is need to show voting widgets as well. Form is used for bulk editing / updating with batch process as in form, different form fileds are shown against node title.
  • custom search from and in listing of search result ie: in twig file need to print rate widget against results

Is there any way currently to print rate widgets in node template files or this is also related to port ?

In 7 it was :

rate_generate_widget('1', 'node', $node->nid, RATE_FULL, TRUE, FALSE, NULL);

jordik’s picture

The first bullet you can achieve with attaching the widget to your custom content type in the widget settings.
Second and third - with views. If you really need to "print" a widget, you will need to call the rate.vote_widget_base service and invoke the getFrom method. Check rate.module how it is done. You will have to take care about the form container and attaching the libraries yourself.
So I would friendly advise you to stick to the standard methods.

jas1988’s picture

Thanks for suggestion, I will look into code files. ( using view is not an option as completely custom functionality in my form including lot more fields/features etc )

jordik’s picture

Status: Active » Closed (works as designed)