You are here

public function StarsWidget::previewsExpand in Fivestar 8

Prepares the widget's render element for rendering.

Parameters

array $element: The element to transform.

Return value

array The transformed element.

See also

::formElement()

File

src/Plugin/Field/FieldWidget/StarsWidget.php, line 77

Class

StarsWidget
Plugin implementation of the 'fivestar_stars' widget.

Namespace

Drupal\fivestar\Plugin\Field\FieldWidget

Code

public function previewsExpand(array $element) {
  $widgets = $this->widgetManager
    ->getWidgets();
  foreach (Element::children($element) as $widget_key) {
    $vars = [
      '#theme' => 'fivestar_preview_widget',
      // '#css' => ''
      '#attached' => [
        'library' => [
          $widgets[$widget_key]['library'],
        ],
      ],
      '#name' => $widgets[$widget_key]['label'],
    ];
    $element[$widget_key]['#description'] = \Drupal::service('renderer')
      ->render($vars);
  }
  return $element;
}