Form Mode Control allow select permissions for all Form Mode for a bundle, even "Default" Form Mode is permitted.

If a user try to use a Form, before "Configure Forms Mode" (admin/structure/display-modes/form/config-form-modes), always use "Default" Form Mode for this form, even if the user roles don't have this permission.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rcechang created an issue. See original summary.

eme’s picture

Well in a sense you're right, but issue is that supposing you define default form mode for a user other that the "real" default one, without special permission, he'll be able to do ?display=default and get it even if he shoudn't...

rudam’s picture

Same issue here, the user role only have the permission to use "Generic" form_mode but in node edit He gets the "default" form_mode.

Notice: Undefined index: node.page. in getPermissionByModeAndRole() (line 83 of /var/www/html/drupal/modules/form_mode_control/form_mode_control.module).
Notice: Undefined offset: 2 in controlAccessFormMode() (line 120 of /var/www/html/drupal/modules/form_mode_control/form_mode_control.module).

megan_m’s picture

Sorry, meant to comment in Issue #2737325. I'm wondering if this permissions problem is happening because the config options aren't working (did some digging around in the code but my D8 dev skills aren't that great).

eme’s picture

Well, @rudam are your sure you selected in the config page the right form mode.

For now, you always get the default form mode unless you give permission + you define the form mode in the config page.

megan_m’s picture

I can replicate this too, with the same warnings as @rudam. This was happening when I had set the regular node permissions to create nodes of that content type. I assumed I would need that for users to be able to use the form display modes. To me the expected behaviour would be for the Form Mode control permissions to work with the default node permissions.

Now my problem is that since I've turned that permission off I can't get the Form Mode Control permissions to work ...

psiegel’s picture

Same problem as #6 for me, whatever permission I set

bander2’s picture

Anyone have a workaround for this?

eme’s picture

Can you explain me how this is an issue ? By default, if you authorize a role to create, say a article, but do not configure form mode control for it, you should be able to create a new article with the default form mode. Then you can configure if needed which role gets which form mode...

bander2’s picture

Sorry, I guess I did not understand the issue. For me, users get the default form no matter how I set permissions or defaults. I'll open a separate issue.

bacarndiaye’s picture

in debug i have see $default_id != $form_mode_id in line 120 form_mode_control is always null.
My solution is in function controlAccessFormMode before all to test if there arg display.

bacarndiaye’s picture

FileSize
5.3 KB
bacarndiaye’s picture

FileSize
5.19 KB
woprrr’s picture

Status: Active » Needs work
  1. +++ form_mode_control.module	(revision )
    @@ -96,59 +96,62 @@
     function controlAccessFormMode($configuration, $mode, $display_name, $storage, $id, &$form_display, $context) {
    

    You should use a more OOP approach to make your logic Testable.

    Like :
    return \Drupal::service('class_resolver')
    ->getInstanceFromDefinition(EntityTypeInfo::class)
    ->entityTypeAlter($entity_types);

    And you have too many parameters.

  2. +++ form_mode_control.module	(revision )
    @@ -96,59 +96,62 @@
    +  if($pathArgs) {
    ...
    +    if ($form_mode_id == "") {
    ...
    +    if (\Drupal::currentUser()->hasPermission($permission_access_all)) {
    ...
    +    else {
    +      if (\Drupal::currentUser()
    ...
    +      else {
    ...
    +        if ($change_display && \Drupal\Core\Entity\Entity\EntityFormDisplay::load($current_id)
    

    try to simply that complexity and have more decoupled approach. That seems not normal to have this needed to add all of these comments blocks.

  3. +++ form_mode_control.module	(revision )
    @@ -96,59 +96,62 @@
    +        $change_display = $storage->load($current_id);
    

    We can have these information more easily In configFactory. #2838051: Split the default permission for entities by entity type

Dakwamine’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev
Category: Support request » Bug report
Status: Needs work » Fixed

Thank you all for your answers. (Hi woprrr)

Regarding the issue, this is because the configuration of the module was not handled properly: old data in the config were not cleared when permissions were unset.

This was fixed in #2844878: Notice: Undefined index: user.user. in getPermissionByModeAndRole() (line 83 of .

Also, I think the process of manually saving the module config could be enhanced by an "automatized" resave upon permission update, at least to remove old entries. A separate issue was created for this task.

Status: Fixed » Closed (fixed)

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