You are here

protected function SelectList::buildOptionsLevel in Plugin 8.2

Helper function for self::options().

Parameters

array $hierarchy: A plugin ID hierarchy as returned by self::hierarchy().

integer $depth: The depth of $hierarchy's top-level items as seen from the original hierarchy's root (this function is recursive), starting with 0.

Return value

string[] Keys are plugin IDs.

1 call to SelectList::buildOptionsLevel()
SelectList::buildSelector in src/Plugin/Plugin/PluginSelector/SelectList.php
Builds the form elements for the actual plugin selector.

File

src/Plugin/Plugin/PluginSelector/SelectList.php, line 61

Class

SelectList
Provides a plugin selector using a <select> element.

Namespace

Drupal\plugin\Plugin\Plugin\PluginSelector

Code

protected function buildOptionsLevel(array $hierarchy, $depth = 0) {
  $plugin_definitions = $this->selectablePluginDiscovery
    ->getDefinitions();
  $options = [];
  $prefix = $depth ? str_repeat('-', $depth) . ' ' : '';
  foreach ($hierarchy as $plugin_id => $child_plugin_ids) {
    $plugin_definition = $plugin_definitions[$plugin_id];
    $label = $plugin_definition instanceof PluginLabelDefinitionInterface ? $plugin_definition
      ->getLabel() : $plugin_definition
      ->getId();
    $options[$plugin_id] = $prefix . $label;
    $options += $this
      ->buildOptionsLevel($child_plugin_ids, $depth + 1);
  }
  return $options;
}