Hello,
Amazing simple module.
In my case I want to prevent some roles from selecting the node language on node create untill they have permission to that.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

m.abdulqader’s picture

I created a patch to do the following:

  • Generate new permission for languages on content creation.
  • Alter languages list on node forms to filter languages depend on user permission.
m.abdulqader’s picture

Assigned: m.abdulqader » Unassigned
Status: Active » Needs review
m.abdulqader’s picture

Issue summary: View changes
hhschoone’s picture

Hi!

This module combined with your patch is almost exactly what I'm looking for! The only thing is: I want editors to be able to select only the languages I give them permission to. Your patch allows for selecting the default language by default. Is there any reason for that behaviour? (Admittedly, I need to check the site's language-setup, but that's for another time)

Thanks!

m.abdulqader’s picture

Change the settings of your content type to require langugage selection so it will disappear :)

hhschoone’s picture

I have done that: under the tab 'Multilingual settings' I've selected the 'Require Language' option. However, your form_alter-code excludes both the 'und' (which isn't shown due to the Require Language-option) and default languages from unsetting:

function _language_access_form_node_form_alter($form, &$form_state){
  $default_language = language_default();
  if(isset($form['language']['#options'])) {
    foreach($form['language']['#options'] as $lang => $lang_name) {
      if($lang != 'und' && $lang != $default_language->language) { // <-- After && part
        if (!user_access('create language ' . $lang)) {
          unset($form['language']['#options'][$lang]);
        }
      }
    }
  }
  return $form;
}

If I remove the 2nd part (&& $lang != $default_language->language) it won't show the default language when the user is not given permission. Is there any reason for that line of code (i.e. does the default site-language always need to be selectable for it to work correctly)?

Edit: In the case of removing that line of code it is essential to check at least one language in the permissions. If not, no content can be created...

hhschoone’s picture

m.abdulqader’s picture

I see, this is important for viewing at least one language which in our case was the default language.
Thank you :)

m.abdulqader’s picture

I updated the und issue to use the constant variable :) and update the patch with the new release published today.

Jānis Bebrītis’s picture

it was necessary to allow default language to avoid extra loops for checking if "any" language is available. Users were redirected when they had no access to language, but having no languages available led to redirect loops.

Yesterday we changed it from drupal_goto to drupal_access_denied.

m.abdulqader’s picture

Yes I noticed that in last commit, but in our case we are remove languages from node add form, so you can arrange who can add a language depend on his role.
I remove the un used variable default language.
Patch attached.

  • guncha25 committed 4b15b31 on 7.x-1.x
    -Issue #1705122 by leschekfm, guncha25 : Fixes permissions that are set...

  • guncha25 committed 2ec26fa on 6.x-1.x
    -Fixes drupal_goto() error.
    -Issue #2400421 by m.abdulqader: Filter...
m.abdulqader’s picture

FYI
Advanced patch contributor guide
https://www.drupal.org/node/1054616

m.abdulqader’s picture

Status: Needs review » Closed (fixed)
m.abdulqader’s picture

Status: Closed (fixed) » Fixed

  • m.abdulqader authored 59d4f80 on 7.x-1.x
    -Issue #1705122 by leschekfm, guncha25 : Fixes permissions that are set...

Status: Fixed » Closed (fixed)

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

erdm’s picture

Thanks M.Abdulqader .
What about patch for drupal 9/10 or custom entity other than node types... Any plan ?