You are here

protected static function BusinessRulesViewsSelection::getViewOptions in Business Rules 8

Same name and namespace in other branches
  1. 2.x src/Plugin/EntityReferenceSelection/BusinessRulesViewsSelection.php \Drupal\business_rules\Plugin\EntityReferenceSelection\BusinessRulesViewsSelection::getViewOptions()
1 call to BusinessRulesViewsSelection::getViewOptions()
BusinessRulesViewsSelection::updateDependentField in src/Plugin/EntityReferenceSelection/BusinessRulesViewsSelection.php
Update the dependent field options.

File

src/Plugin/EntityReferenceSelection/BusinessRulesViewsSelection.php, line 226

Class

BusinessRulesViewsSelection
Plugin override of the 'selection' entity_reference.

Namespace

Drupal\business_rules\Plugin\EntityReferenceSelection

Code

protected static function getViewOptions(ViewExecutable $view) {
  $options = [];
  if ($view
    ->execute()) {
    $renderer = \Drupal::service('renderer');
    $render_array = $view->style_plugin
      ->render();
    foreach ($render_array as $key => $value) {
      $rendered_value = (string) $renderer
        ->render($value);
      $options[] = [
        'key' => $key,
        'value' => Html::decodeEntities(strip_tags($rendered_value)),
      ];
    }
  }
  uasort($options, function ($a, $b) {
    return $a['value'] < $b['value'] ? -1 : 1;
  });
  array_unshift($options, [
    'key' => '_none',
    'value' => t('-Select-'),
  ]);
  return $options;
}