diff --git a/content_pager.module b/content_pager.module index 9141214..656f05d 100644 --- a/content_pager.module +++ b/content_pager.module @@ -226,11 +226,34 @@ function content_pager_preprocess_node(&$variables) { //load custom template for pagination function content_pager_preprocess(&$variables, $hook, &$info) { - if ($hook == 'node') { - if (substr($info['theme path'], 0, 7) != 'themes/') { - $info['theme path'] = 'modules/custom/content_pager'; - $info['path'] = 'modules/custom/content_pager/templates'; + if($node = \Drupal::routeMatch()->getParameter('node')) { + $nid = $node->id(); + $node = \Drupal\node\Entity\Node::load($nid); + $body = $node->body->value; + $type = $node->bundle(); + $word_count = str_word_count($body); + $character_count = strlen($body); + + // Fetching all the available content types + $contentTypes = \Drupal::service('entity.manager') + ->getStorage('node_type') + ->loadMultiple(); + foreach ($contentTypes as $type) { + $typeId = $type->id(); + $paging_enabled = \Drupal::config('content_pager.enabled_' . $typeId) + ->get('content_pager.enabled_' . $typeId); + + if($paging_enabled == TRUE){ + if ($hook == 'node') { + if (substr($info['theme path'], 0, 7) != 'themes/') { + $info['theme path'] = 'modules/custom/content_pager'; + $info['path'] = 'modules/custom/content_pager/templates'; + } + } + } + else{ + unset($info); + } } } - }