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' => '
', - '#suffix' => '
', - '#states' => array( - 'visible' => array( - ':input[name="paging_enabled_' . $content_type . '"]' => array('checked' => TRUE), - ':input[name="paging_automatic_method_' . $content_type . '"]' => array('value' => 'chars'), - ), - ), - '#default_value' => \Drupal::config('paging.automaticMethodChars_' . $content_type)->get('paging.automaticMethodChars_' . $content_type) - ); - - // Automatic paging method. Text box to choose orphan size. - $form[$content_type]['paging_config']['paging_right']['paging_automatic_chars_orphan_' . $content_type] = array( - '#type' => 'textfield', - '#title' => t('Length of orphans'), - '#size' => 6, - '#field_suffix' => t('characters'), - '#description' => '
' . t('Number of characters to consider as an orphan.'), - '#prefix' => '
', - '#suffix' => '
', - '#states' => array( - 'visible' => array( - ':input[name="paging_enabled_' . $content_type . '"]' => array('checked' => TRUE), - ':input[name="paging_automatic_method_' . $content_type . '"]' => array('value' => 'chars'), - ), - ), - '#default_value' => \Drupal::config('paging.automaticMethodCharsOrphan_' . $content_type)->get('paging.automaticMethodCharsOrphan_' . $content_type) - ); - - // Automatic paging method. Select list to choose the number of words per page. - $form[$content_type]['paging_config']['paging_right']['paging_automatic_words_' . $content_type] = array( - '#type' => 'select', - '#title' => t('Length of each page'), - '#options' => $word_len, - '#field_suffix' => t('words'), - '#description' => '
' . t('Number of words to display per page.'), - '#prefix' => '
', - '#suffix' => '
', - '#states' => array( - 'visible' => array( - ':input[name="paging_enabled_' . $content_type . '"]' => array('checked' => TRUE), - ':input[name="paging_automatic_method_' . $content_type . '"]' => array('value' => 'words'), - ), - ), - '#default_value' => \Drupal::config('paging.automaticMethodWords_' . $content_type)->get('paging.automaticMethodWords_' . $content_type) - ); - - // Automatic paging method. Text box to set orphan page size. - $form[$content_type]['paging_config']['paging_right']['paging_automatic_words_orphan_' . $content_type] = array( - '#type' => 'textfield', - '#title' => t('Length of orphans'), - '#size' => 6, - '#field_suffix' => t('words'), - - '#description' => '
' . t('Number of wordss to consider as an orphan.'), - // '#default_value' => variable_get('paging_automatic_words_orphan_' . $content_type, 200), - '#prefix' => '
', - '#suffix' => '
', - '#states' => array( - 'visible' => array(// action to take. - ':input[name="paging_enabled_' . $content_type . '"]' => array('checked' => TRUE), - ':input[name="paging_automatic_method_' . $content_type . '"]' => array('value' => 'words'), - ), - ), - '#default_value' => \Drupal::config('paging.automaticMethodWordsOrphan_' . $content_type)->get('paging.automaticMethodWordsOrphan_' . $content_type) - ); - } + $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' => '
', + '#suffix' => '
', + '#states' => array( + 'visible' => array( + ':input[name="paging_enabled_' . $content_type . '"]' => array('checked' => TRUE), + ':input[name="paging_automatic_method_' . $content_type . '"]' => array('value' => 'chars'), + ), + ), + '#default_value' => \Drupal::config('content_pager.automaticMethodChars_' . $content_type) + ->get('content_pager.automaticMethodChars_' . $content_type) + ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => $this->t('Save Configuration'), + // Automatic paging method. Text box to choose orphan size. + $form[$content_type]['paging_config']['paging_right']['paging_automatic_chars_orphan_' . $content_type] = array( + '#type' => 'textfield', + '#title' => t('Length of orphans'), + '#size' => 6, + '#field_suffix' => t('characters'), + '#description' => '
' . t('Number of characters to consider as an orphan.'), + '#prefix' => '
', + '#suffix' => '
', + '#states' => array( + 'visible' => array( + ':input[name="paging_enabled_' . $content_type . '"]' => array('checked' => TRUE), + ':input[name="paging_automatic_method_' . $content_type . '"]' => array('value' => 'chars'), + ), + ), + '#default_value' => \Drupal::config('content_pager.automaticMethodCharsOrphan_' . $content_type) + ->get('content_pager.automaticMethodCharsOrphan_' . $content_type) + ); + // Automatic paging method. Select list to choose the number of words per page. + $form[$content_type]['paging_config']['paging_right']['paging_automatic_words_' . $content_type] = array( + '#type' => 'select', + '#title' => t('Length of each page'), + '#options' => $word_len, + '#field_suffix' => t('words'), + '#description' => '
' . t('Number of words to display per page.'), + '#prefix' => '
', + '#suffix' => '
', + '#states' => array( + 'visible' => array( + ':input[name="paging_enabled_' . $content_type . '"]' => array('checked' => TRUE), + ':input[name="paging_automatic_method_' . $content_type . '"]' => array('value' => 'words'), + ), + ), + '#default_value' => \Drupal::config('content_pager.automaticMethodWords_' . $content_type) + ->get('content_pager.automaticMethodWords_' . $content_type) ); + // Automatic paging method. Text box to set orphan page size. + $form[$content_type]['paging_config']['paging_right']['paging_automatic_words_orphan_' . $content_type] = array( + '#type' => 'textfield', + '#title' => t('Length of orphans'), + '#size' => 6, + '#field_suffix' => t('words'), + + '#description' => '
' . t('Number of wordss to consider as an orphan.'), + // '#default_value' => variable_get('paging_automatic_words_orphan_' . $content_type, 200), + '#prefix' => '
', + '#suffix' => '
', + '#states' => array( + 'visible' => array(// action to take. + ':input[name="paging_enabled_' . $content_type . '"]' => array('checked' => TRUE), + ':input[name="paging_automatic_method_' . $content_type . '"]' => array('value' => 'words'), + ), + ), + '#default_value' => \Drupal::config('conten_pager.automaticMethodWordsOrphan_' . $content_type) + ->get('content_pager.automaticMethodWordsOrphan_' . $content_type) + ); + } + + $form['submit'] = array( + '#type' => 'submit', + '#value' => $this->t('Save Configuration'), + + ); + return $form; } @@ -251,81 +265,105 @@ class Pagingform extends FormBase { * The current state of the form. */ public function submitForm(array &$form, FormStateInterface $form_state) { - $contentTypes = \Drupal::service('entity.manager')->getStorage('node_type')->loadMultiple(); - foreach($contentTypes as $type) { + $contentTypes = \Drupal::service('entity.manager') + ->getStorage('node_type') + ->loadMultiple(); + foreach ($contentTypes as $type) { $typeId = $type->id(); - $pagingSeparator = \Drupal::service('config.factory')->getEditable('paging.separator') - ->set('paging.separator',$form_state->getValue('paging_separator')) + $pagingSeparator = \Drupal::service('config.factory') + ->getEditable('content_pager.separator') + ->set('content_pager.separator', $form_state->getValue('paging_separator')) ->save(); - $pagingPagerCount = \Drupal::service('config.factory')->getEditable('paging.pagerCount') - ->set('paging.pagerCount',$form_state->getValue('paging_pager_count')) + $pagingPagerCount = \Drupal::service('config.factory') + ->getEditable('content_pager.pagerCount') + ->set('content_pager.pagerCount', $form_state->getValue('paging_pager_count')) ->save(); //Save pager enable settings - $pagingSettings = \Drupal::service('config.factory')->getEditable('paging.enabled_' . $typeId) - ->set('paging.enabled_'.$typeId,$form_state->getValue('paging_enabled_' .$typeId)) + $pagingSettings = \Drupal::service('config.factory') + ->getEditable('content_pager.enabled_' . $typeId) + ->set('content_pager.enabled_' . $typeId, $form_state->getValue('paging_enabled_' . $typeId)) ->save(); - $pagingSettings = \Drupal::service('config.factory')->getEditable('paging.field_' . $typeId) - ->set('paging.field_'.$typeId,$form_state->getValue('paging_field_' .$typeId)) + $pagingSettings = \Drupal::service('config.factory') + ->getEditable('content_pager.field_' . $typeId) + ->set('content_pager.field_' . $typeId, $form_state->getValue('paging_field_' . $typeId)) ->save(); - $pagingReadMore = \Drupal::service('config.factory')->getEditable('paging.readMore_' .$typeId) - ->set('paging.readMore_' .$typeId,$form_state->getValue('paging_read_more_enabled_' .$typeId)) + $pagingReadMore = \Drupal::service('config.factory') + ->getEditable('content_pager.readMore_' . $typeId) + ->set('content_pager.readMore_' . $typeId, $form_state->getValue('paging_read_more_enabled_' . $typeId)) ->save(); - $pagingChangeTitle = \Drupal::service('config.factory')->getEditable('paging.changeTitle_' .$typeId) - ->set('paging.changeTitle_' .$typeId,$form_state->getValue('paging_name_title_' .$typeId)) + $pagingChangeTitle = \Drupal::service('config.factory') + ->getEditable('content_pager.changeTitle_' . $typeId) + ->set('content_pager.changeTitle_' . $typeId, $form_state->getValue('paging_name_title_' . $typeId)) ->save(); - $pagingAutoMethod = \Drupal::service('config.factory')->getEditable('paging.automaticMethod_' .$typeId) - ->set('paging.automaticMethod_' .$typeId,$form_state->getValue('paging_automatic_method_' .$typeId)) + $pagingAutoMethod = \Drupal::service('config.factory') + ->getEditable('content_pager.automaticMethod_' . $typeId) + ->set('content_pager.automaticMethod_' . $typeId, $form_state->getValue('paging_automatic_method_' . $typeId)) ->save(); - if($form_state->getValue('paging_automatic_method_' .$typeId) != 'disabled') { +//Getting the value of the index for character count + $char_len_options = array(-1 => 750) + range(500, 7500, 500); + $val_arr = array(); + $paging_automatic_chars = $form_state->getValue('paging_automatic_chars_' . $typeId); + foreach ($char_len_options as $key => $value) { + $val_arr[$key] = $value; + } + if ($form_state->getValue('paging_automatic_method_' . $typeId) != 'disabled') { if ($form_state->getValue('paging_automatic_method_' . $typeId) == 'chars') { // Removing word settings - $pagingWords = \Drupal::service('config.factory')->getEditable('paging.automaticMethodWords_' .$typeId) - ->set('paging.automaticMethodWords_' .$typeId,'') + $pagingWords = \Drupal::service('config.factory') + ->getEditable('content_pager.automaticMethodWords_' . $typeId) + ->set('content_pager.automaticMethodWords_' . $typeId, '') ->save(); - $pagingWordsOrphan = \Drupal::service('config.factory')->getEditable('paging.automaticMethodWordsOrphan_' .$typeId) - ->set('paging.automaticMethodWordsOrphan_' .$typeId,'') + $pagingWordsOrphan = \Drupal::service('config.factory') + ->getEditable('content_pager.automaticMethodWordsOrphan_' . $typeId) + ->set('content_pager.automaticMethodWordsOrphan_' . $typeId, '') ->save(); //Setting Paging by Characters - $pagingChars = \Drupal::service('config.factory')->getEditable('paging.automaticMethodChars_' .$typeId) - ->set('paging.automaticMethodChars_' .$typeId,$form_state->getValue('paging_automatic_chars_' .$typeId)) + $pagingChars = \Drupal::service('config.factory') + ->getEditable('content_pager.automaticMethodChars_' . $typeId) + ->set('content_pager.automaticMethodChars_' . $typeId, $val_arr[$paging_automatic_chars]) ->save(); - $pagingCharsOrphan = \Drupal::service('config.factory')->getEditable('paging.automaticMethodCharsOrphan_' .$typeId) - ->set('paging.automaticMethodCharsOrphan_' .$typeId,$form_state->getValue('paging_automatic_chars_orphan_' .$typeId)) + $pagingCharsOrphan = \Drupal::service('config.factory') + ->getEditable('content_pager.automaticMethodCharsOrphan_' . $typeId) + ->set('content_pager.automaticMethodCharsOrphan_' . $typeId, $form_state->getValue('paging_automatic_chars_orphan_' . $typeId)) ->save(); } else { //Removing char settings - $pagingChars = \Drupal::service('config.factory')->getEditable('paging.automaticMethodChars_' .$typeId) - ->set('paging.automaticMethodChars_' .$typeId,'') + $pagingChars = \Drupal::service('config.factory') + ->getEditable('content_pager.automaticMethodChars_' . $typeId) + ->set('content_pager.automaticMethodChars_' . $typeId, '') ->save(); - $pagingCharsOrphan = \Drupal::service('config.factory')->getEditable('paging.automaticMethodCharsOrphan_' .$typeId) - ->set('paging.automaticMethodCharsOrphan_' .$typeId,'') + $pagingCharsOrphan = \Drupal::service('config.factory') + ->getEditable('content_pager.automaticMethodCharsOrphan_' . $typeId) + ->set('content_pager.automaticMethodCharsOrphan_' . $typeId, '') ->save(); //Setting Paging by Words - $pagingWords = \Drupal::service('config.factory')->getEditable('paging.automaticMethodWords_' .$typeId) - ->set('paging.automaticMethodWords_' .$typeId,$form_state->getValue('paging_automatic_words_' .$typeId)) + $pagingWords = \Drupal::service('config.factory') + ->getEditable('content_pager.automaticMethodWords_' . $typeId) + ->set('content_pager.automaticMethodWords_' . $typeId, $form_state->getValue('paging_automatic_words_' . $typeId)) ->save(); - $pagingWordsOrphan = \Drupal::service('config.factory')->getEditable('paging.automaticMethodWordsOrphan_' .$typeId) - ->set('paging.automaticMethodWordsOrphan_' .$typeId,$form_state->getValue('paging_automatic_words_orphan_' .$typeId)) + $pagingWordsOrphan = \Drupal::service('config.factory') + ->getEditable('content_pager.automaticMethodWordsOrphan_' . $typeId) + ->set('content_pager.automaticMethodWordsOrphan_' . $typeId, $val_arr[$paging_automatic_chars]) ->save(); } } } - + drupal_set_message(t('The configuration options have been saved. ')); } }