You are here

function tca_node_views_query_alter in Token Content Access 8

Same name and namespace in other branches
  1. 2.0.x modules/tca_node/tca_node.module \tca_node_views_query_alter()

Implements hook_views_query_alter().

File

modules/tca_node/tca_node.module, line 55
Contains tca_node.module.

Code

function tca_node_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
  $account = \Drupal::currentUser();
  $bypass_permitted = $account
    ->hasPermission('tca bypass node');
  if (!$bypass_permitted) {
    $disabled_types = _tca_node_get_disabled_types();
    $info = $query
      ->getEntityTableInfo('node_field_data');
    if (isset($info['node'])) {
      $alias = $info['node']['alias'];
      $group_name = 'tca_node';
      $query->where[$group_name] = [
        'conditions' => [
          [
            'field' => $alias . '.tca_active',
            'value' => NULL,
            'operator' => 'IS NULL',
          ],
          [
            'field' => $alias . '.tca_active',
            'value' => 0,
            'operator' => '=',
          ],
        ],
        'args' => [],
        'type' => 'OR',
      ];

      // Add disabled types condition.
      if (!empty($disabled_types)) {
        $query->where[$group_name]['conditions'][] = [
          'field' => $alias . '.type',
          'value' => $disabled_types,
          'operator' => 'IN',
        ];
      }
    }
  }
}