You are here

function _tac_lite_get_terms in Taxonomy Access Control Lite 8

Same name and namespace in other branches
  1. 5 tac_lite.module \_tac_lite_get_terms()
  2. 6 tac_lite.module \_tac_lite_get_terms()
  3. 7 tac_lite.module \_tac_lite_get_terms()

Gets terms from a node that belong to vocabularies selected.

1 call to _tac_lite_get_terms()
tac_lite_node_access_records in ./tac_lite.module
Implements hook_node_access_records().

File

./tac_lite.module, line 90
Control access to site content based on taxonomy, roles and users.

Code

function _tac_lite_get_terms($node) {
  $tids = [];

  // Get the vids that tac_lite cares about.
  $config = \Drupal::config('tac_lite.settings');
  $vids = $config
    ->get('tac_lite_categories') ? array_keys($config
    ->get('tac_lite_categories')) : NULL;
  if ($vids) {

    // Load all terms found in term reference fields.
    // This logic should work for all nodes (published or not).
    $terms_by_vid = tac_lite_node_get_terms($node);
    if (!empty($terms_by_vid)) {
      foreach ($vids as $vid) {
        if (!empty($terms_by_vid[$vid])) {
          foreach ($terms_by_vid[$vid] as $tid => $term) {
            $tids[$tid] = $tid;
          }
        }
      }
    }
  }
  elseif (\Drupal::currentUser()
    ->hasPermission('administer tac_lite')) {
    \Drupal::messenger()
      ->addStatus(t('tac_lite.module enabled, but not <a href=:admin_url>configured</a>. No tac_lite terms associated with :title.', [
      ':admin_url' => Url::fromRoute('tac_lite.administration')
        ->toString(),
      ':title' => $node
        ->getTitle(),
    ]));
  }
  return $tids;
}