diff --git a/content_pager.install b/content_pager.install
new file mode 100644
index 0000000..4d19bbe
--- /dev/null
+++ b/content_pager.install
@@ -0,0 +1,35 @@
+getStorage('node_type')->loadMultiple();
+ $typeSpecificConfig = array();
+ foreach($contentTypes as $type) {
+ $typeId = $type->id();
+ $typeSpecificConfig[$type][] = array(
+ 'content_pager.enabled_' . $typeId,
+ 'content_pager.field_' .$typeId,
+ 'content_pager.readMore_' . $typeId,
+ 'content_pager.changeTitle_' . $typeId,
+ 'content_pager.automaticMethod_' . $typeId,
+ 'content_pager.automaticMethodWords_' . $typeId,
+ 'content_pager.automaticMethodWordsOrphan_' . $typeId,
+ 'content_pager.automaticMethodChars_' . $typeId,
+ 'content_pager.automaticMethodCharsOrphan_' . $typeId
+ );
+ }
+ foreach($configArray as $config) {
+ \Drupal::configFactory()->getEditable($config)->delete();
+ }
+ foreach($typeSpecificConfig as $contentType) {
+ foreach($contentType as $val) {
+ \Drupal::configFactory()->getEditable($val)->delete();
+ }
+ }
+}
\ No newline at end of file
diff --git a/content_pager.links.menu.yml b/content_pager.links.menu.yml
index 24a41f1..b590536 100644
--- a/content_pager.links.menu.yml
+++ b/content_pager.links.menu.yml
@@ -1,6 +1,6 @@
content_type_dependency.list:
route_name: pager.form
- title: 'Paging'
+ title: 'Content Pager'
description: 'Enable or disable paging, configure separator string, toggle automatic paging and more for each content types.'
parent: system.admin_config_ui
diff --git a/content_pager.module b/content_pager.module
index 17b430a..2ca1a47 100644
--- a/content_pager.module
+++ b/content_pager.module
@@ -17,7 +17,86 @@ function content_pager_preprocess_node(&$variables) {
$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_separator = \Drupal::config('content_pager.separator')
+ ->get('content_pager.separator');
+ $paging_pager_Count = \Drupal::config('content_pager.pagerCount')
+ ->get('content_pager.pagerCount');
+ $paging_enabled = \Drupal::config('content_pager.enabled_' . $typeId)
+ ->get('content_pager.enabled_' . $typeId);
+ $paging_field = \Drupal::config('content_pager.field_' . $typeId)
+ ->get('content_pager.field_' . $typeId);
+ $paging_readmore = \Drupal::config('content_pager.readMore_' . $typeId)
+ ->get('content_pager.readMore_' . $typeId);
+ $paging_changetitle = \Drupal::config('content_pager.changeTitle_' . $typeId)
+ ->get('content_pager.changeTitle_' . $typeId);
+ $paging_auto_method = \Drupal::config('content_pager.automaticMethod_' . $typeId)
+ ->get('content_pager.automaticMethod_' . $typeId);
+ $paging_auto_method_words = \Drupal::config('content_pager.automaticMethodWords_' . $typeId)
+ ->get('content_pager.automaticMethodWords_' . $typeId);
+ $orphan_words_limit = \Drupal::config('paging.automaticMethodWordsOrphan_' . $typeId)
+ ->get('content_pager.automaticMethodWordsOrphan_' . $typeId);
+ $paging_auto_method_chars = \Drupal::config('content_pager.automaticMethodChars_' . $typeId)
+ ->get('content_pager.automaticMethodChars_' . $typeId);
+ $paging_auto_method_chars_orphan = \Drupal::config('content_pager.automaticMethodCharsOrphan_' . $typeId)
+ ->get('content_pager.automaticMethodCharsOrphan_' . $typeId);
+ dsm($paging_auto_method_chars);
+ }
+
+// // Setting Node Page Count For Pagination & breaks Count For Automatic paging method (Limit By characters)
+// $paging_separator = \Drupal::config('paging.separator')
+// ->get('paging.separator');
+// // Load the global separator.
+// if (!$paging_separator) {
+// $paging_separator = \Drupal::config('paging.separator')
+// ->get('paging.separator') ?: '';
+// }
+// $abc = \Drupal::config('paging.automaticMethodChars_' . $type)
+// ->get('paging.automaticMethodChars_' . $type);
+//
+// $body_parts = $body;
+// if (\Drupal::config('paging.automaticMethod_' . $type)
+// ->get('paging.automaticMethod_' . $type) == 'chars'
+// && ($max_chars = \Drupal::config('paging.automaticMethodChars_' . $type)
+// ->get('paging.automaticMethodChars_' . $type)) != 0
+// ) {
+// $orphan_size = \Drupal::config('paging.automaticMethodCharsOrphan_' . $type)
+// ->get('paging.automaticMethodCharsOrphan_' . $type);
+// $total_chars = strlen($body);
+//
+// // Check if pagination is possible.
+// if ($total_chars > $max_chars) {
+// $body = $body;
+// $breaks = (int) ($total_chars / $max_chars);
+// $breaks = substr($breaks, 1);
+// $bodypart = array();
+// for ($i = 0; $i <= $breaks; $i++) {
+//
+// // Now pull that off the body.
+// $bodycount = strlen($bodypart[$i]);
+// $body = substr($body, $bodycount);
+//
+// // Check for orphans.
+// if (strlen($body) < $orphan_size) {
+// drupal_set_message(t('Page @num would be an orphan; keeping with last page.',
+// array('@num' => $i + 2)), 'status', FALSE);
+// $bodypart[$i] .= $body;
+// break;
+// }
+// }
+// $body_parts = implode($paging_separator, $bodypart);
+// }
+// }
+// $node->pages = explode($paging_separator, $body_parts);
+// $node->page_count = count($node->pages);
+
+ }
+
}
diff --git a/src/Form/Pagingform.php b/src/Form/Pagingform.php
index 3389ee8..4c1c4f2 100644
--- a/src/Form/Pagingform.php
+++ b/src/Form/Pagingform.php
@@ -21,224 +21,238 @@ class Pagingform extends FormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
- $contentTypes = \Drupal::service('entity.manager')->getStorage('node_type')->loadMultiple();
- // Set the id of the top-level form tag.
- $form['#id'] = 'contentpager';
- $form['paging_general'] = array(
- '#type' => 'fieldset',
- '#title' => t('General paging settings'),
- '#collapsible' => FALSE,
- );
-
- // Paging separator string.
- // @TODO will need an upgrade path.
- $form['paging_general']['paging_separator'] = array(
- '#type' => 'textfield',
- '#title' => t('Page separator string'),
- '#size' => 20,
- '#maxlength' => 255,
- '#description' => t('Use an HTML tag that will render reasonably when
+ $contentTypes = \Drupal::service('entity.manager')
+ ->getStorage('node_type')
+ ->loadMultiple();
+ // Set the id of the top-level form tag.
+ $form['#id'] = 'contentpager';
+ $form['paging_general'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('General paging settings'),
+ '#collapsible' => FALSE,
+ );
+
+ // Paging separator string.
+ // @TODO will need an upgrade path.
+ $form['paging_general']['paging_separator'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Page separator string'),
+ '#size' => 20,
+ '#maxlength' => 255,
+ '#description' => t('Use an HTML tag that will render reasonably when
paging is not enabled, such as %pagebreak or %hr.'),
- '#default_value' => \Drupal::config('paging.separator')->get('paging.separator')
- );
-
- $form['paging_general']['paging_pager_count'] = array(
- '#type' => 'radios',
- '#title' => t('Number of Pagers on each page'),
- '#options' => array(
- 'one' => t('One'),
- 'two' => t('Two'),
- ),
- '#attributes' => array('class' => array('paging-pager')),
- '#default_value' => \Drupal::config('paging.pagerCount')->get('paging.pagerCount')
- );
+ '#default_value' => \Drupal::config('content_pager.separator')
+ ->get('content_pager.separator')
+ );
+
+ $form['paging_general']['paging_pager_count'] = array(
+ '#type' => 'radios',
+ '#title' => t('Number of Pagers on each page'),
+ '#options' => array(
+ 'one' => t('One'),
+ 'two' => t('Two'),
+ ),
+ '#attributes' => array('class' => array('paging-pager')),
+ '#default_value' => \Drupal::config('content_pager.pagerCount')
+ ->get('content_pager.pagerCount')
+ );
$contentTypesList = [];
foreach ($contentTypes as $contentType) {
$contentTypesList[$contentType->id()] = $contentType->label();
- $content_type= $contentType->id();
- $form[$content_type] = array(
- '#type' => 'fieldset',
- '#title' => $content_type,
- );
-
- $field_options = array('body');
- // Left column fieldset.
- $form[$content_type]['paging_config']['paging_left'] = array(
- '#type' => 'fieldset',
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- '#attributes' => array('class' => array('paging-left')),
- );
-
- // Paging toggle checkbox.
- $form[$content_type]['paging_config']['paging_left']['paging_enabled_' . $content_type] = array(
- '#type' => 'checkbox',
- '#title' => 'Enable paging',
- '#attributes' => array('class' => array('paging-enabled')),
- '#default_value' => \Drupal::config('paging.enabled_' . $content_type)->get('paging.enabled_' . $content_type)
- );
-
- // Paging toggle checkbox.
- $form[$content_type]['paging_config']['paging_left']['paging_field_' . $content_type] = array(
- '#type' => 'radios',
- '#title' => 'Select field to use for page breaks',
- '#options' => $field_options,
- '#attributes' => array('class' => array('paging-enabled')),
- '#states' => array(
- 'visible' => array(
- ':input[name="paging_enabled_' . $content_type . '"]' => array('checked' => TRUE),
- ),
- ),
- '#default_value' => \Drupal::config('paging.field_' . $content_type)->get('paging.field_' . $content_type)
- );
-
- // Change "Read more" path when first page is greater than or equal to the teaser.
- $form[$content_type]['paging_config']['paging_left']['paging_read_more_enabled_' . $content_type] = array(
- '#type' => 'checkbox',
- '#title' => t('Link "Read more" to second page'),
- '#description' => t('When enabled, the "Read more" link for teasers will
+ $content_type = $contentType->id();
+ $form[$content_type] = array(
+ '#type' => 'fieldset',
+ '#title' => $content_type,
+ );
+
+ $field_options = array('body');
+ // Left column fieldset.
+ $form[$content_type]['paging_config']['paging_left'] = array(
+ '#type' => 'fieldset',
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE,
+ '#attributes' => array('class' => array('paging-left')),
+ );
+
+ // Paging toggle checkbox.
+ $form[$content_type]['paging_config']['paging_left']['paging_enabled_' . $content_type] = array(
+ '#type' => 'checkbox',
+ '#title' => 'Enable paging',
+ '#attributes' => array('class' => array('paging-enabled')),
+ '#default_value' => \Drupal::config('content_pager.enabled_' . $content_type)
+ ->get('content_pager.enabled_' . $content_type)
+ );
+
+ // Paging toggle checkbox.
+ $form[$content_type]['paging_config']['paging_left']['paging_field_' . $content_type] = array(
+ '#type' => 'radios',
+ '#title' => 'Select field to use for page breaks',
+ '#options' => $field_options,
+ '#attributes' => array('class' => array('paging-enabled')),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="paging_enabled_' . $content_type . '"]' => array('checked' => TRUE),
+ ),
+ ),
+ '#default_value' => \Drupal::config('content_pager.field_' . $content_type)
+ ->get('content_pager.field_' . $content_type)
+ );
+
+ // Change "Read more" path when first page is greater than or equal to the teaser.
+ $form[$content_type]['paging_config']['paging_left']['paging_read_more_enabled_' . $content_type] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Link "Read more" to second page'),
+ '#description' => t('When enabled, the "Read more" link for teasers will
link to the second page of the content if the teaser is larger than the
first page or if they are the same.'),
- '#states' => array(
- 'visible' => array(
- ':input[name="paging_enabled_' . $content_type . '"]' => array('checked' => TRUE),
- ),
- ),
- '#default_value' => \Drupal::config('paging.readMore_' . $content_type)->get('paging.readMore_' . $content_type)
- );
-
- // Set the browser's title to current page's name.
- $form[$content_type]['paging_config']['paging_left']['paging_name_title_' . $content_type] = array(
- '#type' => 'checkbox',
- '#title' => t('Change page title to name of current page'),
- '#description' => t("Change the node's and browser window's title into
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="paging_enabled_' . $content_type . '"]' => array('checked' => TRUE),
+ ),
+ ),
+ '#default_value' => \Drupal::config('content_pager.readMore_' . $content_type)
+ ->get('content_pager.readMore_' . $content_type)
+ );
+
+ // Set the browser's title to current page's name.
+ $form[$content_type]['paging_config']['paging_left']['paging_name_title_' . $content_type] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Change page title to name of current page'),
+ '#description' => t("Change the node's and browser window's title into
name of the current page."),
- '#states' => array(
- 'visible' => array(
- ':input[name="paging_enabled_' . $content_type . '"]' => array('checked' => TRUE),
- ),
- ),
- '#default_value' => \Drupal::config('paging.changeTitle_' . $content_type)->get('paging.changeTitle_' . $content_type)
- );
-
- // Right column fieldset.
- $form[$content_type]['paging_config']['paging_right'] = array(
- '#type' => 'fieldset',
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- '#attributes' => array('class' => array('paging-right')),
- '#states' => array(
- 'visible' => array(// action to take.
- ':input[name="paging_enabled_' . $content_type . '"]' => array('checked' => TRUE),
- ),
- ),
- );
-
- $form[$content_type]['paging_config']['paging_right']['paging_automatic_method_' . $content_type] = array(
- '#type' => 'radios',
- '#title' => t('Automatic paging method'),
- '#options' => array(
- 'disabled' => t('Disabled'),
- 'chars' => t('Limit by characters (recommended)'),
- 'words' => t('Limit by words')),
- '#description' => t('Method for automatic paging (ignored where paging
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="paging_enabled_' . $content_type . '"]' => array('checked' => TRUE),
+ ),
+ ),
+ '#default_value' => \Drupal::config('content_pager.changeTitle_' . $content_type)
+ ->get('content_pager.changeTitle_' . $content_type)
+ );
+
+ // Right column fieldset.
+ $form[$content_type]['paging_config']['paging_right'] = array(
+ '#type' => 'fieldset',
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE,
+ '#attributes' => array('class' => array('paging-right')),
+ '#states' => array(
+ 'visible' => array(// action to take.
+ ':input[name="paging_enabled_' . $content_type . '"]' => array('checked' => TRUE),
+ ),
+ ),
+ );
+
+ $form[$content_type]['paging_config']['paging_right']['paging_automatic_method_' . $content_type] = array(
+ '#type' => 'radios',
+ '#title' => t('Automatic paging method'),
+ '#options' => array(
+ 'disabled' => t('Disabled'),
+ 'chars' => t('Limit by characters (recommended)'),
+ 'words' => t('Limit by words')
+ ),
+ '#description' => t('Method for automatic paging (ignored where paging
separator string is used).'),
- '#attributes' => array('class' => array('paging-method')),
- '#states' => array(
- 'visible' => array(// action to take.
- ':input[name="paging_enabled_' . $content_type . '"]' => array('checked' => TRUE),
- ),
- ),
- '#default_value' => \Drupal::config('paging.automaticMethod_' . $content_type)->get('paging.automaticMethod_' . $content_type)
- );
-
- $char_len_options = array(-1 => 750) + range(500, 7500, 500);
- $word_len = range(100, 1000, 50);
- asort($char_len_options);
+ '#attributes' => array('class' => array('paging-method')),
+ '#states' => array(
+ 'visible' => array(// action to take.
+ ':input[name="paging_enabled_' . $content_type . '"]' => array('checked' => TRUE),
+ ),
+ ),
+ '#default_value' => \Drupal::config('content_pager.automaticMethod_' . $content_type)
+ ->get('conten_pager.automaticMethod_' . $content_type)
+ );
+
+ $char_len_options = array(-1 => 750) + range(500, 7500, 500);
+ $word_len = range(100, 1000, 50);
+ asort($char_len_options);
// Automatic paging method. Select list to choose the number of characters per page.
- $form[$content_type]['paging_config']['paging_right']['paging_automatic_chars_' . $content_type] = array(
- '#type' => 'select',
- '#title' => t('Length of each page'),
- '#options' => $char_len_options,
- '#field_suffix' => t('characters'),
- '#description' => '
' . t('Number of characters to display per page.'),
- '#prefix' => '