You are here

function _fivestar_get_widget in Fivestar 7.2

Parameters

$widgets: Array, $widgets = module_invoke_all('fivestar_widgets'); $widgets = array('path/to/css' => 'Widget Name', 'path/to/more/css' => 'Widget 2');

$display: Array. This is the $display parameter passed to fivestar_field_formatter_view().

$instance: Array. This is the $instance parameter passed to fivestar_field_formatter_view().

Return value

array $widget = array('name' => 'my widget', 'css' => 'sites/all/mymodule/mywidget.css');

1 call to _fivestar_get_widget()
fivestar_field_formatter_view in includes/fivestar.field.inc
Implements hook_field_formatter_view().

File

includes/fivestar.field.inc, line 703
Provides CCK integration for fivestar module.

Code

function _fivestar_get_widget($widgets, $display, $instance) {

  // If the type doesn't required widgets lets get out of here.
  // @todo Implement this WAY better.
  if (in_array($display['type'], array(
    'fivestar_formatter_rating',
    'fivestar_formatter_percentage',
  ))) {
    return FALSE;
  }

  // Stars (rated while viewing) is $type = 'exposed'.
  // Stars (rated while editing) is $type = 'stars'.
  $type = $instance['widget']['type'];

  // Determine which widget to display.
  if (!($fivestar_widget = $display['settings']['widget']['fivestar_widget'])) {

    // No display has been selected and saved by the user.
    if ($type == 'exposed') {

      // Stars rated while viewing, that is, $type = 'exposed', fall backs on 'default'
      // (which is the same as nothing).
      $fivestar_widget = 'default';
    }
    elseif ($type == 'stars') {

      // Stars rated while editing, that is, $type = stars,
      // falls back on whatever the user selected to be displayed on node/add and node/%/edit.
      $fivestar_widget = $instance['widget']['settings']['widget']['fivestar_widget'];
    }
  }
  $widget = array(
    'name' => isset($widgets[$fivestar_widget]) ? strtolower($widgets[$fivestar_widget]) : 'default',
    'css' => $fivestar_widget,
  );
  return $widget;
}