Drupal 8: How to Display Checkbox in List View

Submitted by admin on Sun, 03/04/2018 - 01:20

For example shown below, ['data'] requires after ['active'] like ['active']['data'].
public function buildRow(EntityInterface $entity) {

$row['active']['data'] = [ // @IMPORTANT: add ['data'] here
'#type' => 'checkbox',
'#default_value' => (bool) $entity->isActive(),
'#checked' => (bool) $entity->isActive(),
'#attributes' => ['disabled' => 'disabled'],
'#disabled' => TRUE,
];

return $row + parent::buildRow($entity);
}

Since it is a list, you may want to disable it. In that case, you need to add:
['disabled' => 'disabled']

Just in case, it is also adding'#disabled' => TRUE,.

Tags