문제

In Drupal 6, I am using the following code.

$rows[] = array(
  array('data' => drupal_render($form['collected'])),
  array(
    'data'=> drupal_render($form['count']) . drupal_render($form['submit']),
    'colspan' => 3
  )
);

In Drupal 8, I am trying to use the following code, but I see the HTML markup of $form['count'].

$rows[] = [
  ['data' => \Drupal::service('renderer')->render(($form['collected'])],
  [
    'data' => \Drupal::service('renderer')->render($form['count']) . \Drupal::service('renderer')->render($form['submit']),
    'colspan' => 3,
  ]
];
도움이 되었습니까?

해결책

In Drupal 8+, you do not need to use a separate theming function as was required in Drupal 6. You can put the form element directly into the table without rendering, and Drupal will handle that on the back-end. It's much simpler:

$row = [];
$row[] = [
  'data' => [
    'something' => $form['something'],
    'something_else' => $form['something_else'],
  ],
];

$rows[] = $row;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 drupal.stackexchange
scroll top