/** * {@inheritdoc} */ protected function buildSelector(array $root_element, FormStateInterface $form_state, array $plugins) { $element = parent::buildSelector($root_element, $form_state, $plugins); /** @var \Drupal\Component\Plugin\PluginInspectionInterface[] $plugins */ $element['container']['plugin_id'] = array('#ajax' => array('callback' => array(get_class(), 'ajaxRebuildForm'), 'effect' => 'fade', 'event' => 'change', 'trigger_as' => array('name' => $element['container']['change']['#name'])), '#default_value' => $this->getSelectedPlugin() ? $this->getSelectedPlugin()->getPluginId() : NULL, '#empty_value' => '', '#options' => $this->buildOptionsLevel($this->buildPluginHierarchy($this->selectablePluginDiscovery)), '#required' => $this->isRequired(), '#title' => $this->getLabel(), '#description' => $this->getDescription(), '#type' => 'select'); return $element; }
/** * {@inheritdoc} */ protected function buildSelector(array $root_element, FormStateInterface $form_state, array $plugins) { $element = parent::buildSelector($root_element, $form_state, $plugins); /** @var \Drupal\Component\Plugin\PluginInspectionInterface[] $plugins */ $plugin_options = []; foreach ($plugins as $plugin) { $plugin_definition = $this->selectablePluginType->ensureTypedPluginDefinition($plugin->getPluginDefinition()); $plugin_options[$plugin->getPluginId()] = $plugin_definition instanceof PluginLabelDefinitionInterface ? $plugin_definition->getLabel() : $plugin_definition->getId(); } natcasesort($plugin_options); $element['container']['plugin_id'] = array('#ajax' => array('callback' => array(get_class(), 'ajaxRebuildForm'), 'effect' => 'fade', 'event' => 'change', 'progress' => 'none', 'trigger_as' => array('name' => $element['container']['change']['#name'])), '#attached' => ['library' => ['plugin/plugin_selector.plugin_radios']], '#default_value' => $this->getSelectedPlugin() ? $this->getSelectedPlugin()->getPluginId() : NULL, '#empty_value' => 'select', '#options' => $plugin_options, '#required' => $this->isRequired(), '#title' => $this->getlabel(), '#description' => $this->getDescription(), '#type' => 'radios'); return $element; }