Search code examples
arraysdrupalindexingdrupal-7hook

Undefine Index in Drupal 7 Renderable Array


Below are codes, I grabbed that display something on a page. I dont know what index should I put in Line 9.

1. /**
2.  * Implementation of hook_user_view().
3.  */
4. 
5. function mymodule_user_view($account, $view_mode, $langcode) {
6.
7.    if(user_access('administer mymodule',$account)){
8.        $content = t('Sign');
9.        $account->content['What should I put here?']=array(
10.            '#type' => 'user_profile_item',
11.            '#title' => t('Signature'),
12.            '#value' => $content,
13.            '#weight' => 10,
14.        );           
15.    }
16. }

Can anyone tell me, what kind of valid index value I should put in Line 9 to make it display correctly. It shows the following error:

Notice: Undefined index: #markup in template_preprocess_user_profile_item() (line 216 of C:\xampp\htdocs\drupal-7.34\modules\user\user.pages.inc).

Solution

  • Try to replace "#value" with "#markup":

    $account->content['What should I put here?']=array(
               '#type' => 'user_profile_item',
                '#title' => t('Signature'),
                '#markup' => $content,
                '#weight' => 10,
            );