LoginSignup
0
0

More than 5 years have passed since last update.

Viewsにて検索結果一覧に列を動的に追加する

Posted at

Viewsにて検索結果一覧に列を動的に追加する

ユーザや役割で「編集・削除」リンクを表示している列を表示/非表示の制御をしたいこともあると思います。
そんなときはこれ。

/**
 * Implements hook_views_pre_view().
 */
function MYMODULE_views_pre_view(&$view, &$display_id, &$args) {
  if ($view->name === 'test_path') {
    $view->add_item($view->current_display, 'field', 'views', 'nothing', array(
      'label' => 'DynamicField',
      'alter' => array('text' => 'test text'),
      'element_class' => 'my-field',
      'element_default_classes' => 0,
    ), 'my_field');
  }
}

あとは、$user->role などを参照して表示/非表示の制御をすればOK。
あるいは、Viewsの設定画面でフィールドを追加しておいて、
ロジックでunsetするかですかね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0