public static function Fivestar::getElementDescription in Fivestar 8
Return rating description.
Parameters
array $element: Fivestar element data.
Return value
array
1 call to Fivestar::getElementDescription()
- Fivestar::process in src/
Element/ Fivestar.php - Process callback: process fivestar element.
File
- src/
Element/ Fivestar.php, line 200
Class
- Fivestar
- Provides a fivestar form element.
Namespace
Drupal\fivestar\ElementCode
public static function getElementDescription(array $element) {
if (empty($element['#settings']['text_format']) || empty($element['#values'])) {
return [];
}
$settings = $element['#settings'];
$values = $element['#values'];
$base_element_data = [
'#theme' => 'fivestar_summary',
'#stars' => $element['#stars'],
'#microdata' => isset($settings['microdata']) ? $settings['microdata'] : NULL,
];
switch ($settings['text_format']) {
case 'user':
return [
'#user_rating' => $values['vote_user'],
'#votes' => $settings['display_format'] == 'dual' ? NULL : $values['vote_count'],
] + $base_element_data;
case 'average':
return [
'#average_rating' => $values['vote_average'],
'#votes' => $values['vote_count'],
] + $base_element_data;
case 'smart':
return $settings['display_format'] == 'dual' && !$values['vote_user'] ? [] : [
'#user_rating' => $values['vote_user'],
'#average_rating' => $values['vote_user'] ? NULL : $values['vote_average'],
'#votes' => $settings['display_format'] == 'dual' ? NULL : $values['vote_count'],
] + $base_element_data;
case 'dual':
return [
'#user_rating' => $values['vote_user'],
'#average_rating' => $settings['display_format'] == 'dual' ? NULL : $values['vote_average'],
'#votes' => $settings['display_format'] == 'dual' ? NULL : $values['vote_count'],
] + $base_element_data;
case 'none':
return [];
}
}