I have created a custom column in the content listing section using hook_views_data()
. I want to add a button to the every row of that custom column. Can anyone help me with this issue?
function sortd_views_data() {
$data['node_field_data']['SortdAction'] = [
'title' => t('Sortd Action'),
'help' => t('Manual Sync/Unsync articles.'),
'field' => [
'handler' => 'views_handler_field',
'id' => 'numeric',
],
'sort' => [
'handler' => 'views_handler_sort',
'click sortable' => TRUE,
],
'filter' => [
'handler' => 'views_handler_filter_string',
],
'argument' => [
'handler' => 'views_handler_argument_string',
],
];
return $data;
}
The 0 show for every row needs to be replaced with the button.
I tried to solve the problem using the following code.
function sortd_preprocess_views_view_table(&$variables) {
drupal_set_message($variables['rows']);
if ($variables['view']->id() == 'content') {
foreach ($variables['rows'] as &$row) {
$row['SortdAction'] = [
'#type' => 'submit',
'#value' => t('Sortd'),
];
}
}
}
Whenever I try to print $variables['row']
, it shows me the correct data in that table.