mjordan / islandora_repository_reports

A Drupal 8 module that provides a collection of graphical reports on various aspects of an Islandora repository.
GNU General Public License v2.0
2 stars 5 forks source link

user.private_tempstore deprecated in D9 #67

Closed elizoller closed 3 years ago

elizoller commented 3 years ago

user.private_tempstore has been deprecated in d9 and replaced with tempstore.private

diff below includes the changes:

diff --git a/modules/islandora_repository_reports_vocab/src/Plugin/DataSource/Vocab.php b/modules/islandora_repository_reports_vocab/src/Plugin/DataSource/Vocab.php
index cc371a4..4a2b1ad 100644
--- a/modules/islandora_repository_reports_vocab/src/Plugin/DataSource/Vocab.php
+++ b/modules/islandora_repository_reports_vocab/src/Plugin/DataSource/Vocab.php
@@ -55,7 +55,7 @@ class Vocab implements IslandoraRepositoryReportsDataSourceInterface {

     $selected_content_type = '';
     $selected_vocabulary = '';
-    if ($tempstore = \Drupal::service('user.private_tempstore')->get('islandora_repository_reports')) {
+    if ($tempstore = \Drupal::service('tempstore.private')->get('islandora_repository_reports')) {
       if ($form_state = $tempstore->get('islandora_repository_reports_report_form_values')) {
         // Even though the content type form widget is checkboxes, we can
         // only use one value in the query below, so we take the first one
diff --git a/src/Controller/IslandoraRepositoryReportsController.php b/src/Controller/IslandoraRepositoryReportsController.php
index 60050da..bb054c7 100644
--- a/src/Controller/IslandoraRepositoryReportsController.php
+++ b/src/Controller/IslandoraRepositoryReportsController.php
@@ -18,7 +18,7 @@ class IslandoraRepositoryReportsController extends ControllerBase {
    *   Markup used by the chart.
    */
   public function main() {
-    if ($tempstore = \Drupal::service('user.private_tempstore')->get('islandora_repository_reports')) {
+    if ($tempstore = \Drupal::service('tempstore.private')->get('islandora_repository_reports')) {
       $show_csv_link = $tempstore->get('islandora_repository_reports_generate_csv');
     }
     $form = \Drupal::formBuilder()->getForm('Drupal\islandora_repository_reports\Plugin\Form\IslandoraRepositoryReportsReportSelectorForm');
diff --git a/src/Plugin/Form/IslandoraRepositoryReportsReportSelectorForm.php b/src/Plugin/Form/IslandoraRepositoryReportsReportSelectorForm.php
index cec2df3..bd332de 100644
--- a/src/Plugin/Form/IslandoraRepositoryReportsReportSelectorForm.php
+++ b/src/Plugin/Form/IslandoraRepositoryReportsReportSelectorForm.php
@@ -59,7 +59,7 @@ class IslandoraRepositoryReportsReportSelectorForm extends FormBase {
    * {@inheritdoc}
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
-    $tempstore = \Drupal::service('user.private_tempstore')->get('islandora_repository_reports');
+    $tempstore = \Drupal::service('tempstore.private')->get('islandora_repository_reports');
     $tempstore->set('islandora_repository_reports_report_type', $form_state->getValue('islandora_repository_reports_report_type'));
     $tempstore->set('islandora_repository_reports_generate_csv', $form_state->getValue('islandora_repository_reports_generate_csv'));
     // Pass the entire form state in so third-party modules that alter the
diff --git a/src/Utils.php b/src/Utils.php
index 5a6ba01..8ceabad 100644
--- a/src/Utils.php
+++ b/src/Utils.php
@@ -57,7 +57,7 @@ class Utils {
    *   The default value of the element.
    */
   public function getFormElementDefault($form_element, $default_value) {
-    if ($tempstore = \Drupal::service('user.private_tempstore')->get('islandora_repository_reports')) {
+    if ($tempstore = \Drupal::service('tempstore.private')->get('islandora_repository_reports')) {
       if ($form_state = $tempstore->get('islandora_repository_reports_report_form_values')) {
         $default_value = $form_state->getValue($form_element);
       }
@@ -78,7 +78,7 @@ class Utils {
    */
   public function tempstoreIsStale($key = 'islandora_repository_reports_report_type', $bb = 60) {
     $tempstore_age = 0;
-    if ($tempstore = \Drupal::service('user.private_tempstore')->get('islandora_repository_reports')) {
+    if ($tempstore = \Drupal::service('tempstore.private')->get('islandora_repository_reports')) {
       if (is_null($tempstore->getMetadata($key))) {
         return TRUE;
       }
@@ -120,7 +120,7 @@ class Utils {
    */
   public function getSelectedContentTypes() {
     $content_types = [];
-    if ($tempstore = \Drupal::service('user.private_tempstore')->get('islandora_repository_reports')) {
+    if ($tempstore = \Drupal::service('tempstore.private')->get('islandora_repository_reports')) {
       if ($form_state = $tempstore->get('islandora_repository_reports_report_form_values')) {
         $content_types = $form_state->getValue('islandora_repository_reports_content_types');
       }
@@ -520,7 +520,7 @@ class Utils {
    *   An array of arrays corresponding to CSV records.
    */
   public function writeCsvFile($report_type, $csv_data) {
-    if ($tempstore = \Drupal::service('user.private_tempstore')->get('islandora_repository_reports')) {
+    if ($tempstore = \Drupal::service('tempstore.private')->get('islandora_repository_reports')) {
       if ($tempstore->get('islandora_repository_reports_generate_csv')) {
         $default_schema = \Drupal::config('system.file')->get('default_scheme');
         $files_path = \Drupal::service('file_system')->realpath($default_schema . "://");
elizoller commented 3 years ago

I should also note that in D9 I was unable to load the Islandora Repository Reports page but when I made these changes, I was able to. I tested several reports and some downloads to CSV which I believe would cover the majority of these cases but I didn't test every report or submodule.

mjordan commented 3 years ago

Thanks very much @elizoller . I haven't been keeping up on how Islandora contrib modules are accommodating API changes like this across Drupal 8 and 9. Maybe maintain different branches?

elizoller commented 3 years ago

most of the changes work in both d8 and d9 so we haven't had to straddle that in islandora (and neither have most drupal contrib modules - i can only think of one example where they had a clear cut between d8 and d9 support).

mjordan commented 3 years ago

OK, thanks. I think for now I'll cut two branches, 8.x-1.x and 9.x-1.x, and maintain both and document this in the README. There hasn't been much activity on this module lately so shouldn't be too bad in the short term. Once Islandora shifts completely to D9 we can let the 8.x branch go stale.

Thanks very much for figuring out this API compatibility issue.

mjordan commented 3 years ago

All tested and works in Drupal 8, so no need for multiple branches. Thanks!