I have meet 2 bugs when use bootstrap theme.

1. Repeat field_suffix and field_prefix

I add a new field with "field suffix" and "field prefix" properties on Manage Fields page for "Page" content type, but it will rendered repeat suffix and prefix on my create new page node page. I also tested with custom form element with that properties, same issues.

I found if you used #input_group properties, rendered correct, because the #field_prefix and #field_suffix values will be remove if have #input_group or #input_group_button on line 58-64 of file "src/Plugin/Preprocess/FormElement.php". But drupal core form element doesn't built-in these properties, so my solution is just map the prefix and suffix when input_group property enabled of file "src/Plugin/Preprocess/Input.php".
src/Plugin/Preprocess/FormElement.php

    // Remove the #field_prefix and #field_suffix values set in
    // template_preprocess_form_element(). These are handled on the input level.
    // @see \Drupal\bootstrap\Plugin\Preprocess\Input::preprocess().
    if ($variables->element->hasProperty('input_group') || $variables->element->hasProperty('input_group_button')) {
      $variables['prefix'] = FALSE;
      $variables['suffix'] = FALSE;
    }

src/Plugin/Preprocess/Input.php

    // Map the element properties.
    $variables->map([
      'attributes' => 'attributes',
      'icon' => 'icon',
      'type' => 'type',
    ]);
    // Just map the prefix and suffix when input_group property enabled.
    if ($variables['input_group']) {
      $variables->map([
        'field_prefix' => 'prefix',
        'field_suffix' => 'suffix',
      ]);
    }

Comments

everright created an issue. See original summary.

everright’s picture

budda’s picture

Prefix and suffix labels are now appearing correctly around the form field in my test of just Drupal Core and Bootstrap 3 theme enabled and a custom field added to the default Contact form.

budda’s picture

Issue summary: View changes
StatusFileSize
new8.27 KB

Working test field with prefix and suffix labels.

markhalliwell’s picture

Component: Plugin System » Templates
Status: Needs review » Needs work
Issue tags: -field_suffix, -field_prefix, -input_group, -input_group_button

I'll need to step through this. There's a lot of things changing in that patch and I need to make sure it's not doubling unnecessary work.

Furthermore, I'm not seeing from the above screenshots that actual Bootstrap input groups are working properly.

estoyausente’s picture

I applied the patch and now it's working correctly but I understand the @markcarver position.

Can we fix this bug without apply whole code? Without apply the input groups and then, if we can and want, implement the input group bootstrap component (http://getbootstrap.com/components/#input-groups).

I don't know too about theming and less about theming in D8 but I'm using bootstrap currently and I need this resolved and want to help.

@markcarver if you don't want apply this patch, what is your proposal? Or you prefer that we work in this using bootstrap input groups?

Thanks.

  • markcarver committed 9c76aad on 8.x-3.x
    Issue #2723847 by everright, budda, markcarver: Repeat field_prefix and...
markhalliwell’s picture

Status: Needs work » Fixed

Ok. I've stepped through this and the above patch was verbosely unnecessary. The above commit just removes the prefix and suffix rendering on form_element since it's handled at the input level anyway.

edysmp’s picture

The committed no fix the search page :( Actually is broken. With #2 worked.

markhalliwell’s picture

Yes it did. I did the exact same steps in the OP to reproduce and fixed it.

Edit: including testing the submit button

edysmp’s picture

Hi @markcarver, ok I tested with Drupal 8.0.4 and Bootstrap 8.x-3.0-rc1 and search page no works for anonymous users. Bartik is good.

Thanks.

hswong3i’s picture

Status: Fixed » Needs review
StatusFileSize
new6.76 KB

@markcarver sorry that latest drupal-8.1.6 + bootstrap-8.x-3.x-dev not works in search page, anonymous user still can't submit form. Also, bartik is good.

Patch reroll from #2 via latest bootstrap-8.x-3.x-dev, let's check again?

hswong3i’s picture

Confirmed patch from #12 works with search page form submit.

Before search form submit:

After search form submit:

markhalliwell’s picture

Title: Repeat field_prefix and field_suffix rendered, form submit action broken if used #input_group_button property. » Repeat field_prefix and field_suffix rendered
Issue summary: View changes
Status: Needs review » Fixed
Related issues: +#2765505: Search not working on /search/* page for anonymous users
  1. This issue was (primarily) about the repeat field_prefix and field_suffix.
  2. We do not (generally) combine two separate issues, no matter how "related" they are. This is why we have a "Related issues" field.
  3. I can confirm the bug for anonymous users and have created the related follow-up issue.
  4. I do not believe the patches above are the correct approach, regardless if it "works". There is a lot of circumventing and duplication of information. This shouldn't be necessary. I will have to step through this (again) to see what the issue is. It's likely a one/two liner fix somewhere.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.