I try to use 'item' type, as the last code example show in this section:

http://drupal.org/node/224333#markup

But Drupal doesn't render any html output.

For example:

<?php
  $form['something'] = array(
    '#type' => 'item',
    '#title' => 'Title',
    '#markup' => 'value',
  );
?>
CommentFileSizeAuthor
#5 Screenshot-2.png3.95 KBrfay

Comments

naraku’s picture

The problem is the default value of #title_display.

if #title_display is unavailable, then item won't be displayed.

Notice: Undefined index: #title_display in theme_form_element() (line 3373 of /var/www/drupal7/includes/form.inc).

This information about #title_display trick is not in documentation. Is it a bug?

I think, If #title_display doesn't set by user (!isset($element['#title_display'])), then should have a default value, for example 'before'.

Following code works:

  $form['something'] = array(
    '#type' => 'item',
    '#title' => 'Title',
    '#title_display' => 'before',
    '#markup' => 'value',
  );
tstoeckler’s picture

Priority: Critical » Major

I'm pretty sure this isn't critical.

rfay’s picture

Priority: Major » Normal
Status: Active » Postponed (maintainer needs more info)

I can't duplicate this. Just tried this:


function oneoff_generic_form($form, &$form_state) {

  $form['my_item'] = array(
    '#type' => 'item',
    '#title' => t('Title of the item'),
  );
  $form['marking'] = array(
    '#type' => 'markup',
    '#markup' => t('This is some markup')
  );
  return $form;
}

It worked perfectly, as I expected. I've used it in other code as well.

naraku’s picture

I want to show a title and a value in one element, as I read in the documentation.

Here is the documentation about it:
http://drupal.org/node/224333#markup

This code is work:
<?
$form['something'] = array(
'#type' => 'item',
'#title' => 'Title',
'#title_display' => 'before',
'#markup' => 'value',
);
?>

This displays similar this:
Title:
value

You've made this with two element. But it should work in one item element, without #title_display. See: http://drupal.org/node/224333#markup

But it doesn't work without #title_display.
There is a bug in parser code or in documentation.

rfay’s picture

StatusFileSize
new3.95 KB

I apologize - I didn't really write what I meant. This code works perfectly for me.

function oneoff_generic_form($form, &$form_state) {

  $form['my_item'] = array(
    '#type' => 'item',
    '#title' => t('Title of the item'),
    '#markup' => t('This is the markup'),
  );
  return $form;
}

This is the result:

naraku’s picture

I didn't write about the context. Sorry.

It works perfectly for me too In form context as you try it.

The my context is the hook_view() function. I defined a custom node, and I try to define a custom node view:

/**
 * hook_view($node, $view_mode) implementation.
 */
function mynode_type_view($node, $view_mode) {
  $node->content['my_item'] = array(
    '#type' => 'item',
    '#title' => 'My item',
    '#markup' => 'My value'
  );
  return $node;
}

I also defined the other node functions. I've created a new node, and a I've viewed it.
But drupal didn't show my_item.
But I've got a PHP notice:

Notice: Undefined index: #title_display in theme_form_element() (line 3373 of /var/www/drupal7/includes/form.inc).

I see the following in the HTML source:

<div class="content clearfix">
    <div class="form-item form-type-item"> 
</div> 
  </div> 

It works with #title_display => 'before' option.

rfay’s picture

Category: bug » support
Status: Postponed (maintainer needs more info) » Fixed

You're trying to use a form element as if it were a render element. You even used the Form API document as your source for the information. But render types are a small subset of form types, and 'item' is a form type, unless I'm mistaken.

Status: Fixed » Closed (fixed)

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