diff --git a/src/Form/Pagingform.php b/src/Form/Pagingform.php index cbb4101..3389ee8 100644 --- a/src/Form/Pagingform.php +++ b/src/Form/Pagingform.php @@ -39,6 +39,7 @@ class Pagingform extends FormBase { '#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( @@ -49,14 +50,14 @@ class Pagingform extends FormBase { 'two' => t('Two'), ), '#attributes' => array('class' => array('paging-pager')), + '#default_value' => \Drupal::config('paging.pagerCount')->get('paging.pagerCount') ); $contentTypesList = []; foreach ($contentTypes as $contentType) { $contentTypesList[$contentType->id()] = $contentType->label(); - $content_type= $contentType->label(); - + $content_type= $contentType->id(); $form[$content_type] = array( '#type' => 'fieldset', '#title' => $content_type, @@ -76,6 +77,7 @@ class Pagingform extends FormBase { '#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. @@ -89,6 +91,7 @@ class Pagingform extends FormBase { ':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. @@ -103,6 +106,7 @@ class Pagingform extends FormBase { ':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. @@ -116,6 +120,7 @@ class Pagingform extends FormBase { ':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. @@ -146,7 +151,7 @@ class Pagingform extends FormBase { ':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); @@ -168,6 +173,7 @@ class Pagingform extends FormBase { ':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. @@ -185,6 +191,7 @@ class Pagingform extends FormBase { ':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. @@ -202,6 +209,7 @@ class Pagingform extends FormBase { ':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. @@ -221,6 +229,7 @@ class Pagingform extends FormBase { ':input[name="paging_automatic_method_' . $content_type . '"]' => array('value' => 'words'), ), ), + '#default_value' => \Drupal::config('paging.automaticMethodWordsOrphan_' . $content_type)->get('paging.automaticMethodWordsOrphan_' . $content_type) ); } @@ -242,7 +251,80 @@ 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) { + $typeId = $type->id(); + + $pagingSeparator = \Drupal::service('config.factory')->getEditable('paging.separator') + ->set('paging.separator',$form_state->getValue('paging_separator')) + ->save(); + + $pagingPagerCount = \Drupal::service('config.factory')->getEditable('paging.pagerCount') + ->set('paging.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)) + ->save(); + + $pagingSettings = \Drupal::service('config.factory')->getEditable('paging.field_' . $typeId) + ->set('paging.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)) + ->save(); + + $pagingChangeTitle = \Drupal::service('config.factory')->getEditable('paging.changeTitle_' .$typeId) + ->set('paging.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)) + ->save(); + + 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,'') + ->save(); + + $pagingWordsOrphan = \Drupal::service('config.factory')->getEditable('paging.automaticMethodWordsOrphan_' .$typeId) + ->set('paging.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)) + ->save(); + + $pagingCharsOrphan = \Drupal::service('config.factory')->getEditable('paging.automaticMethodCharsOrphan_' .$typeId) + ->set('paging.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,'') + ->save(); + + $pagingCharsOrphan = \Drupal::service('config.factory')->getEditable('paging.automaticMethodCharsOrphan_' .$typeId) + ->set('paging.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)) + ->save(); + + $pagingWordsOrphan = \Drupal::service('config.factory')->getEditable('paging.automaticMethodWordsOrphan_' .$typeId) + ->set('paging.automaticMethodWordsOrphan_' .$typeId,$form_state->getValue('paging_automatic_words_orphan_' .$typeId)) + ->save(); + } + } + } } }