public function FacetForm::buildWidgetConfigForm in Facets 8
Builds the configuration forms for all selected widgets.
Parameters
array $form: An associative array containing the initial structure of the plugin form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the complete form.
1 call to FacetForm::buildWidgetConfigForm()
- FacetForm::form in src/
Form/ FacetForm.php - Gets the actual form array to be built.
File
- src/
Form/ FacetForm.php, line 113
Class
- FacetForm
- Provides a form for configuring the processors of a facet.
Namespace
Drupal\facets\FormCode
public function buildWidgetConfigForm(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\facets\FacetInterface $facet */
$facet = $this
->getEntity();
$widget_plugin_id = $form_state
->getValue('widget') ?: $facet
->getWidget()['type'];
$widget_config = $form_state
->getValue('widget_config') ?: $facet
->getWidget()['config'];
if (empty($widget_plugin_id)) {
return;
}
/** @var \Drupal\facets\Widget\WidgetPluginBase $widget */
$facet
->setWidget($widget_plugin_id, $widget_config);
$widget = $facet
->getWidgetInstance();
$arguments = [
'%widget' => $widget
->getPluginDefinition()['label'],
];
if (!($config_form = $widget
->buildConfigurationForm([], $form_state, $facet))) {
$type = 'details';
$config_form = [
'#markup' => $this
->t('%widget widget needs no configuration.', $arguments),
];
}
else {
$type = 'fieldset';
}
$form['widget_config'] = [
'#type' => $type,
'#tree' => TRUE,
'#title' => $this
->t('%widget settings', $arguments),
'#attributes' => [
'id' => 'facets-widget-config-form',
],
] + $config_form;
}