O
O
Otrivin2018-10-30 17:57:24
Drupal
Otrivin, 2018-10-30 17:57:24

How to display "Fivestar" module in custom tpl.php for taxonomy?

Hello!
There is a site on Drupal 7, there was a need to add a rating to the pages, which are taxonomy terms. Installed the Fivestar module, set it up, now you need to bring it to the frontend.
The developer created a separate template for the term pages. I'm trying to display a module in it, I found an example code for this:

<?php
$settings = array(
    'content_type' => 'profile2',
    'content_id' => $profileView->pid,
    'entity' => $profileView,
    'stars' => 5,
    'field_name' => 'field_profile_rating',
    'autosubmit' => TRUE,
    'allow_clear' => FALSE,
    'langcode' => 'und',
    'text' => 'none', // options are none, average, smart, user, and dual
    'tag' => 'vote',
    'style' => 'average', // options are average, dual, smart, user
    'widget' => array( 'name' => 'oxygen', 'css' => drupal_get_path('module', 'fivestar') . '/widgets/oxygen/oxygen.css' )
);
print render(drupal_get_form('fivestar_custom_widget', $profileView->field_profile_rating['und'][0], $settings));
?>

I'm trying to finish it for myself, but I don't have enough experience with Drupal and I have questions
<?php
$term = taxonomy_term_load(arg(2));
$settings = array(
    'content_type' => 'taxonomy_term', // Видимо, тип материала. Для таксономий такое понятие существует?
    'content_id' => arg(2), // arg(2) достаточно для передачи id материала?
    'entity' => $term, // Что сюда нужно передавать? В примере указан объект. 
    'stars' => 5,
    'field_name' => 'field_rating_term',
    'autosubmit' => TRUE,
    'allow_clear' => FALSE,
    'langcode' => 'und',
    'text' => 'average', // options are none, average, smart, user, and dual
    'tag' => 'vote',
    'style' => 'average', // options are average, dual, smart, user
    'widget' => array( 'name' => 'basic', 'css' => drupal_get_path('module', 'fivestar') . '/widgets/basic/basic.css' )
);
print render(drupal_get_form('fivestar_custom_widget', $term->field_rating_term['und'][0], $settings));
?>

Questions:
1) 'content_type' - What type of content is specified for the term?
2) Is 'content_id' - arg(2) enough to pass the content id?
3) 'entity' - What should be passed here? Current term object or entity type name ( 'term' )?
Or maybe I'm digging in the wrong direction and there is another output method (I found a couple more, but they either don't work or work on Drupal 6)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
andead, 2018-10-30
@andead

The fivestar rating is a normal field. Output like any other field:
echo render($content['field_name']);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question