I have installed the module, but I get this message after attempting to configure. (in RED at the top)

Notice: Undefined index: #field_name in user_readonly_admin_settings() (line 79 of /home/tsstrsvp/public_html/BRC-v1.0/sites/all/modules/user_readonly/user_readonly.module).
---------------------------------------------------------------------------------------------------------------------------------------
Then when I test the configuration and try to edit the user account, I see this error at the top
Notice: Undefined index: #field_name in user_readonly_form_alter() (line 238 of /home/tsstrsvp/public_html/BRC-v1.0/sites/all/modules/user_readonly/user_readonly.module).

I can save the changes , but the Notice at the top is in Red.

What am I missing?

Comments

stephenrobinson’s picture

I added a new user field, which doesn't show up on the config page for user_readonly, and get this error whenever someone goes to edit their profile:

Notice: Undefined index: #field_name in user_readonly_form_alter() (line 238 of /www/htdocs/sites/all/modules/contrib/user_readonly/user_readonly.module).

looked at debug:

    foreach (element_children($data) as $key => $value) {
      if (isset($data[$value][0])) {
        $field = $data[$value][0]["#field_name"];
        if(isset($data[$value][0]["#field_name"])){
          drupal_set_message('good<pre>'.htmlspecialchars(print_r($data[$value][0],1)).'</pre>');
        }
        else{
          drupal_set_message('bad<pre>'.htmlspecialchars(print_r($data[$value][0],1)).'</pre>');
        }
      }

ok so the good object looks like:

Array
(
    [#entity_type] => user
    [#entity] => stdClass Object
        (
            [uid] => 1234
            [name] => abcd
            [pass] => 

and the bad none:

    [value] => Array
        (
            [#entity_type] => user
            [#entity] => stdClass Object
                (
                    [uid] => 1234
                    [name] => abcd
                    [pass] => 
stephenrobinson’s picture

I can get this error to go away by adding:

    foreach (element_children($data) as $key => $value) {
      if (isset($data[$value][0])) {
        if(!isset($data[$value][0]["#field_name"])){
           $data[$value][0]= $data[$value][0]['value'];
        }
        $field = $data[$value][0]["#field_name"];
mikolaskova’s picture

Hi,

I tried to solve the problem, by inserting your code (#2) at link 238.

I commented the code that was there:

   foreach (element_children($data) as $key => $value) {
      if (isset($data[$value][0])) {
        if(!isset($data[$value][0]["#field_name"])){
           $data[$value][0]= $data[$value][0]['value'];
        }
        $field = $data[$value][0]["#field_name"];
    
//     foreach (element_children($data) as $key => $value) {
//       if (isset($data[$value][0])) {
//         $field = $data[$value][0]["#field_name"];
//       }
//       elseif (isset($data[$value]["#field_name"])) {
//         $field = $data[$value]["#field_name"];

but this did not help really, still 'Undefined index'

how did you solve this problem?

regards

Adriana

stephenrobinson’s picture

I uninstalled it and did it myself

/**
  * Implementation of hook_form_alter().
  */
function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if($form_id=='user_profile_form'){
    global $user;
    if(!in_array('Site Admin', array_values($user->roles))){
      $form['field_profile_faculty']['#access'] = 0;
      $form['field_profile_first_name']['#access'] = 0;
      $form['field_profile_known_as']['#access'] = 0;
      $form['field_profile_last_name']['#access'] = 0;
    }
  }
}
mikolaskova’s picture

thanks... so unless anybody has a solution to the 'undefined index' i will have to solve similar as you- thanks for the exemple!

dankh’s picture

Issue summary: View changes

@SangersDrupalDude thanks for the hint, did the same ! But this module can be really handy if it was maintained.

logii’s picture

Status: Active » Closed (duplicate)