View source
<?php
namespace Drupal\fivestar\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Render\Element;
use Drupal\fivestar\WidgetManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class FivestarFormatterBase extends FormatterBase {
protected $widgetManager;
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, WidgetManager $widget_manager) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $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['label'], $configuration['view_mode'], $configuration['third_party_settings'], $container
->get('fivestar.widget_manager'));
}
public function previewsExpand(array $element) {
foreach (Element::children($element) as $css) {
$vars = [
'#theme' => 'fivestar_preview_widget',
'#css' => $css,
'#name' => mb_strtolower($element[$css]['#title']),
];
$element[$css]['#description'] = \Drupal::service('renderer')
->render($vars);
}
return $element;
}
}