Skip to content

Instantly share code, notes, and snippets.

@init90
Created July 13, 2016 14:16
Show Gist options
  • Save init90/c08abc0f67a15d87be55a5a898a8a348 to your computer and use it in GitHub Desktop.
Save init90/c08abc0f67a15d87be55a5a898a8a348 to your computer and use it in GitHub Desktop.
Drupal 8 programing added empty text for views
/**
* Implements hook_views_pre_view().
*/
function icareix_global_views_pre_view(ViewExecutable $view, $display_id, array &$args) {
if ($view->id() == 'job_list' && $display_id == 'page_1') {
if (\Drupal::currentUser()->hasPermission('add job entities')) {
$url = \Drupal\Core\Url::fromUserInput('/admin/structure/job/add');
$empty = \Drupal::l(t('Add new job'), $url);
$options = array(
'id' => 'area_text_custom',
'table' => 'views',
'field' => 'area_text_custom',
'relationship' => 'none',
'group_type' => 'none',
'admin_label' => '',
'empty' => TRUE,
'tokenize' => FALSE,
'content' => $empty,
'plugin_id' => 'text_custom',
);
$view->setHandler('page_1', 'empty', 'area_text_custom', $options);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment