FivestarWidgetBase.php in Fivestar 8
File
src/Plugin/Field/FieldWidget/FivestarWidgetBase.php
View source
<?php
namespace Drupal\fivestar\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\fivestar\WidgetManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class FivestarWidgetBase extends WidgetBase {
protected $widgetManager;
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, WidgetManager $widget_manager) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings);
$this->widgetManager = $widget_manager;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($plugin_id, $plugin_definition, $configuration['field_definition'], $configuration['settings'], $configuration['third_party_settings'], $container
->get('fivestar.widget_manager'));
}
protected function getSelectedWidgetKey() {
$setting = $this
->getSetting('fivestar_widget') ?: 'default';
if (strpos($setting, '.css') === FALSE) {
return $setting;
}
$file_name = basename($setting);
$file_name_exploded = explode('.', $file_name);
$setting = reset($file_name_exploded);
return $setting;
}
}