backdrop / backdrop-issues

Issue tracker for Backdrop core.
144 stars 40 forks source link

[DX] Form API: Provide a 'type' => 'permissions' form element #3332

Open klonos opened 6 years ago

klonos commented 6 years ago

Describe your issue or idea

For some time now, we have started providing subsets of the permissions within various forms throughout the UI. Examples include:

The main permissions page under /admin/config/people/permissions is HUGE . So, being able to provide matrices of subsets of permissions where the user expects them to be is a big UX+, and I am sure that more and more admin pages for core and contrib will start using this over time.

Actual behavior

Injecting those permission tables in forms is currently too much work. See:

https://github.com/backdrop/backdrop/pull/2258/files

https://github.com/backdrop/backdrop/pull/1209/files

https://github.com/backdrop/backdrop/pull/1207/files

Expected behavior

We should be able to do this:

$form['my_form_permissions'] = array(
  '#type' => 'permissions',
  '#roles' => $subset_of_role_names,
  '#permissions' => $subset_of_permission_names,
);
klonos commented 6 years ago

...another problem I am currently having while working in #3339 is that #states visibility conditions do not work with rendered permissions matrices. So this has no effect:

$form['show_permissions'] = array(
  '#type' => 'checkbox',
  '#title' => t('Show permissions matrix'),
);
$form['permissions'] = some_function_to_build_the_permissions_matrix();
$form['permissions']['#access'] = user_access('administer permissions');
// Hide the permissions matrix if the "Show permissions matrix" option is disabled.
$form['permissions']['#states'] = array(    
  'visible' => array(
    'input[name="show_permissions"]' => array('checked' => TRUE),
  ),
);

I am either doing something wrong, or this simply does not work.

klonos commented 5 years ago

...requesting this to be considered for 1.13