Skip to content
Snippets Groups Projects
Commit c1b9a6dc authored by Rodolfo Candido's avatar Rodolfo Candido
Browse files

Issue #3201294 by azinck, 3li, Dega: Taxonomy autocomplete shows "Array" after settings are saved

parent 8f78b895
No related branches found
Tags 1.0.0-alpha17
1 merge request!9Resolve #3201294 "Taxonomy autocomplete shows"
......@@ -64,9 +64,8 @@ class ViewsReferenceExposedFilters extends PluginBase implements ViewsReferenceS
* {@inheritdoc}
*/
public function alterFormField(&$form_field) {
$view = $this->viewsUtility->loadView($this->configuration['view_name'], $this->configuration['display_id']);
$view = $this->viewsUtility->loadView($this->configuration['view_name'],
$this->configuration['display_id']);
if (!$view) {
$form_field = [];
return;
......@@ -87,40 +86,45 @@ class ViewsReferenceExposedFilters extends PluginBase implements ViewsReferenceS
// values as exposed input.
$view->setExposedInput($current_values);
$form_state = (new FormState())
->setStorage([
'view' => $view,
'display' => $view->display_handler->display,
]);
// Let form plugins know this is for exposed widgets.
// @see ViewExposedForm::buildForm()
$form_state->set('exposed', TRUE);
// Go through each handler and let it generate its exposed widget.
// @see ViewExposedForm::buildForm()
foreach ($view->display_handler->handlers as $type => $value) {
/** @var \Drupal\views\Plugin\views\HandlerBase $handler */
foreach ($view->$type as $handler) {
if ($handler->canExpose() && $handler->isExposed()) {
$handler->buildExposedForm($form_field, $form_state);
if ($info = $handler->exposedInfo()) {
if (isset($form_field[$info['value']])) {
// Method buildExposedForm() gets rid of element titles, unless
// type is 'checkbox'. So restore it if missing.
if (empty($form_field[$info['value']]['#title'])) {
$form_field[$info['value']]['#title'] = $this->t('@label', ['@label' => $info['label']]);
}
if (empty($form_field[$info['value']]['#description']) && !empty($info['description'])) {
$form_field[$info['value']]['#description'] = $info['description'];
}
// If we are using the exposed form, render it.
// So we can get the form elements to display.
if ($view->display_handler->usesExposed()) {
/** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginInterface $exposed_form */
$exposed_form = $view->display_handler->getPlugin('exposed_form');
$rendered_form = $exposed_form->renderExposedForm();
foreach (['#info', '#theme'] as $el) {
$form_field[$el] = $rendered_form[$el];
}
// Manually set default values, until we don't handle these
// properly from form_state.
// @todo use (Sub)FormState to handle default_value.
if (isset($current_values[$info['value']])) {
$form_field[$info['value']]['#default_value'] = $current_values[$info['value']];
// Go through each handler and let it generate its exposed widget.
// @see ViewExposedForm::buildForm()
foreach ($view->display_handler->handlers as $type => $value) {
/** @var \Drupal\views\Plugin\views\HandlerBase $handler */
foreach ($view->$type as $handler) {
if ($handler->canExpose() && $handler->isExposed()) {
if ($info = $handler->exposedInfo()) {
if (isset($rendered_form[$info['value']])) {
$form_field[$info['value']] = $rendered_form[$info['value']];
// Unset attributes that are not relevant for this context and
// to ensure that submitted values are appropriately mapped
// deep into the form_state tree structure.
foreach ([
'#tree',
'#parents',
'#array_parents',
'#name',
'#processed',
] as $el) {
unset($form_field[$info['value']][$el]);
}
// The handling of default values for exposed filters seems to
// be really odd. Default values are mapped directly into #value
// by the views handlers. This prevents us from properly handling
// new user-submitted values.
$form_field[$info['value']]['#default_value'] = $form_field[$info['value']]['#value'];
unset($form_field[$info['value']]['#value']);
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment