class WidgetManager in Fivestar 8
Contains methods for managing votes.
Hierarchy
- class \Drupal\fivestar\WidgetManager
Expanded class hierarchy of WidgetManager
2 files declare their use of WidgetManager
- FivestarFormatterBase.php in src/
Plugin/ Field/ FieldFormatter/ FivestarFormatterBase.php - FivestarWidgetBase.php in src/
Plugin/ Field/ FieldWidget/ FivestarWidgetBase.php
1 string reference to 'WidgetManager'
1 service uses WidgetManager
File
- src/
WidgetManager.php, line 10
Namespace
Drupal\fivestarView source
class WidgetManager {
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Constructs a new VoteManager object.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(ModuleHandlerInterface $module_handler) {
$this->moduleHandler = $module_handler;
}
/**
* Returns an array of all widgets.
*
* @return array
* An associative array of widgets and their info.
*
* @see hook_fivestar_widgets()
*/
public function getWidgets() {
$widgets =& drupal_static(__FUNCTION__);
if (isset($widgets)) {
return $widgets;
}
$widgets = $this->moduleHandler
->invokeAll('fivestar_widgets');
// Invoke hook_fivestar_widgets_alter() to allow all modules to alter the
// discovered widgets.
$this->moduleHandler
->alter('fivestar_widgets', $widgets);
return $widgets;
}
/**
* Returns a widget's info.
*
* @param string $widget_key
* The key of the target widget.
*
* @return array
* An array of widget info.
*
* @see hook_fivestar_widgets()
*/
public function getWidgetInfo($widget_key) {
$widgets_info = $this
->getWidgets();
return isset($widgets_info[$widget_key]) ? $widgets_info[$widget_key] : [];
}
/**
* Returns the label for a given widget if it exists.
*
* @param string $widget_key
* The key of the target widget.
*
* @return string
* The widget label.
*/
public function getWidgetLabel($widget_key) {
if (!($widget_info = $this
->getWidgetInfo($widget_key))) {
return '';
}
return $widget_info['label'];
}
/**
* Returns the library for a given widget if it exists.
*
* @param string $widget_key
* The key of the target widget.
*
* @return string
* The library name.
*/
public function getWidgetLibrary($widget_key) {
if (!($widget_info = $this
->getWidgetInfo($widget_key))) {
return '';
}
return $widget_info['library'];
}
/**
* Returns an array of field options based on available widgets.
*
* @return array
* Associative array where the key is the option value and the value is the
* option label.
*/
public function getWidgetsOptionSet() {
$options = [];
foreach ($this
->getWidgets() as $widget_key => $widget_info) {
$options[$widget_key] = $widget_info['label'];
}
return $options;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
WidgetManager:: |
protected | property | The module handler. | |
WidgetManager:: |
public | function | Returns a widget's info. | |
WidgetManager:: |
public | function | Returns the label for a given widget if it exists. | |
WidgetManager:: |
public | function | Returns the library for a given widget if it exists. | |
WidgetManager:: |
public | function | Returns an array of all widgets. | |
WidgetManager:: |
public | function | Returns an array of field options based on available widgets. | |
WidgetManager:: |
public | function | Constructs a new VoteManager object. |