Still working after upgrade?

Created on 28 July 2025, about 1 month ago

I have had "drupal/required_api": "^2.1" and "drupal/required_by_role": "^1.3" installed in my project.
It worked beautifully.

I now upgraded both modules to "drupal/required_api": "^3.0" and "drupal/required_by_role": "^2.0" because they have been marked out-of-date. Unfortunately required_by_role is not working at all anymore. No matter what role I select in the field setup form - the field will be required for ALL user roles.

It seems that when I select "Required by role" in the "Choose a required strategy" section the "default required" field is selected automatically? Hard to tell. My problems persist.

I have tested this behaviour on a blank Drupal 10 install and with different admin themes.
I have tested on PHP 8.2 and 8.3. Nothing seems to fix my problem.

I will cross post this into 'required_api' as well.

πŸ› Bug report
Status

Active

Version

2.0

Component

Documentation

Created by

πŸ‡©πŸ‡ͺGermany fhelms

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @fhelms
  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

    I just tested this module again and it does seem to work. What can be confusing is that the red asterisk is always present, but when saving no validation error will show if the user doesn't have one of the configured roles. Could you test again and actually try to save the entity?

  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels
  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

    The changes in πŸ› Only show red asterisk when the field is actually required Active should remove this limitation. Could you test them and let me know if it works for you?

  • πŸ‡©πŸ‡ͺGermany fhelms

    thank you @dieterholvoet for looking into this.
    unfortunately it is not just about the red asterix.
    field validation will have this field required by all roles in my (pretty vanilla) install of D10.5.2

  • πŸ‡©πŸ‡ͺGermany fhelms

    on thing I just noticed is that I went

    > composer require 'drupal/required_by_role:^2.0'

    only and composer installed 'required_by_role' AND 'required_api' but 'required_api' is not mentioned in the composer json?
    both modules are present in the contrib module folder though

  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

    I'm sorry, but I can't reproduce. I just tested on a fresh Drupal 11.2.3 installation with required_api 3.0.0 and required_by_role 2.0.0 and everything is working as it should.

    It seems that when I select "Required by role" in the "Choose a required strategy" section the "default required" field is selected automatically? Hard to tell. My problems persist.

    The default 'Required' checkbox shouldn't be visible when you have selected the 'Required by role' strategy. It should look like this:

    Are you sure the default 'Required' checkbox is visible while the 'Required by role' strategy is selected?

  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

    Just tested on a Drupal 10.5.1 site, works as well. Do you have any errors logged after changing the field settings? Did you run database updates after updating the module?

  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels
  • πŸ‡ΊπŸ‡ΈUnited States drupgirl

    This module is not working on my end.

    core: ^10.5
    required_by_role:^2.0'

    Install this module and set a few fields to be set by the module and select a couple roles that will be restricted.
    Try saving a node without providing required field data as a role that does not have the restriction.
    Node does not save, as the fields are required for ALL user roles.

  • πŸ‡ΊπŸ‡ΈUnited States drupgirl

    Updated title because my issue was on a fresh install of required_by_role:^2.0.

  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

    Okay, I was able to reproduce the issue, but only on simple fields that have HTML5 required validation through the required attribute. Before I was testing on more complex fields like entity reference and paragraphs fields. The good news is that the patch from πŸ› Only show red asterisk when the field is actually required Active seems to fix the issue. Please test this and let me know if it works for you, so I can merge the fix and make a release. Don't forget to clear caches after applying the patch.

  • πŸ‡©πŸ‡ͺGermany fhelms

    Yes, the changes in #3540426 fixed the problem for me.
    Thank you for fixing it so promptly.

  • πŸ‡ΊπŸ‡ΈUnited States BenStallings

    I am also having this problem after upgrade. The patch from #3540426 hides the red asterixes appropriately, but the fields are still required to submit the form when they should not be.

    Here's another clue that might help: If I edit the field, I see that the required strategy is set to Required by Role and everything looks good. But if I click the Core strategy, it shows the field is required. (This agrees with the config file: in v1.3 it was required: false but now it is required: true.) If I uncheck the required box and save while the Core strategy is still selected, that change gets saved. But if I switch back to the Required by Role strategy, the Core required box gets checked again immediately and gets saved with required: true.

    If I manually change the config file to say required: false and import, the change either does not import or does not stay changed. Exporting config results in required: true.

  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

    @benstallings what's the field type you tested with?

  • πŸ‡ΊπŸ‡ΈUnited States BenStallings

    @dieterholvoet it occurred with the body field, a plain text field, and a list field.

  • πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

    @benstallings sorry, but can't reproduce this with the patch from πŸ› Only show red asterisk when the field is actually required Active applied. required is also set to true in my case, but that shouldn't matter.

    third_party_settings:
      required_api:
        required_plugin: required_by_role
        required_plugin_options:
          - editor
    required: true
    
Production build 0.71.5 2024