I need to initialize widget in modal forms that loads via ajax. I have a simple code like:

function ajaxlogin_block_view($delta = 0) {
switch ($delta) {
case 'ajaxlogin_first':
//i need it here and add lines
$element['#type'] = 'ulogin_widget';
$block['content'] .= drupal_render($element);
break;

case 'ajaxlogin_second':
//i need it here too and add lines
$element['#type'] = 'ulogin_widget';
$block['content'] .= drupal_render($element);
break;

But i only see widget in first form. What did i do wrong?

Comments

duozersk’s picture

Assigned: AbramovSV » Unassigned
Category: Bug report » Support request
Issue tags: -uLogin
duozersk’s picture

Status: Active » Postponed (maintainer needs more info)

AbramovSV,

Thank you for using the module.

Could you please post the full code of the ajaxlogin_block_view() function? My first assumption is that after the first call to drupal_render() the $element is marked as already printed and then the second call to drupal_render() just doesn't return anything... but it really depends on the context.

Thanks
AndyB

AbramovSV’s picture

Thanks fo reply

Now its looks like that:

function ajaxlogin_block_view($delta = 0) {
  $block = array();
  switch ($delta) {
    case 'ajaxlogin':
      global $user;
      if (!$user->uid || $user->uid == 0){//&& !(arg(0) == 'user' && !is_numeric(arg(1)))) {
        $block['subject'] = 'Войти';
        $block['content'] = drupal_get_form('ajaxlogin_login_wide_block_form');
        $element['#type'] = 'ulogin_widget';
        $block['content'] .= drupal_render($element);
      }
      break;
    case 'ajaxlogin_wide':
      global $user;
      if (!$user->uid || $user->uid == 0){// && !(arg(0) == 'user' && !is_numeric(arg(1)))) {
        $block['subject'] = 'Вход';

        $form = drupal_get_form('ajaxlogin_login_wide_block_form');
        $form['#action'] = 'ajaxlogin/user_login/nojs/wide';

        $form['title'] = array(
          '#type' => 'item',
          '#markup' => '<h3>Вход для клиента</h3>',
          '#weight' => -1
        );
		
	$element['#type'] = 'ulogin_widget';
        $block['content'] .= render($form);
	$block['content'] .= drupal_render($element);
        $block['content'] .= '</div>';
      }
      break;
  }
  return $block;
}

You right, i think, yesterder learnd that druapl_render() mark rendered element '#printed' and found this code in common.inc

  // Do not print elements twice.
  if (!empty($elements['#printed'])) {
    return '';
  }

So what should i do now i dont understand

duozersk’s picture

У вас какая-то каша в голове и в коде...

Модуль (ulogin) позволяет вам рендерить виджет путем предоставления элемента типа ulogin_widget - это то же самое, как и '#type' => 'textfield' в Drupal Forms API - то есть может быть частью renderable array. Как этим пользоваться - примерно так же, как и Forms API - где принимается отдача в виде renderable array - отдавайте именно массивом, не надо звать render или drupal_render - например, блоки это поддерживают.

И скорее всего ваш затык именно в этом (если вы запрашиваете блок аяксом), так как в случае, если вы отдаете просто строку - то не подцепятся нужные js файлы. Если жы вы отдадите массив - и потом правильно его заберете аяксом - то все нужные файлики подсосутся.

Надеюсь, это поможет вам разобраться.

AbramovSV’s picture

отдавайте именно массивом

А как это сделать? Я просто не знаю...

duozersk’s picture

$block['content'] может быть не строкой, а массивом. Например, http://cgit.drupalcode.org/ulogin/tree/ulogin.module#n124