Overview

This module adds a button that allows you to return to the previous page that we visited on the site.
This module it's simple. It contains a block plugin, and Javascript file. The block add a button. The Javascript file allow to go back from the current page to previous page.

Project link

https://www.drupal.org/project/go_back_history

Git instructions

git clone --branch 8.x-1.x https://git.drupalcode.org/project/go_back_history.git

PAReview checklist

https://pareview.sh/pareview/https-git.drupal.org-project-go_back_history

Comments

marco.aresu created an issue. See original summary.

marco.aresu’s picture

Issue summary: View changes
marco.aresu’s picture

Issue summary: View changes
marco.aresu’s picture

Issue summary: View changes
ashutosh.mishra’s picture

Issue summary: View changes
ashutosh.mishra’s picture

Thank you for contribution!!!

I am updating the git instructions and also reviewed the compatible with D9.You can add core_version_requirement: ^8 || ^9 in module. info file.

ashutosh.mishra’s picture

Status: Active » Needs work
ashutosh.mishra’s picture

Status: Needs work » Needs review
avpaderno’s picture

ankush_03’s picture

Code Looks Good !

ankushgautam@GGN-199732-C02ZT1F1MD6V contrib % drupal-check go_back_history
2/2 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

[OK] No errors

marco.aresu’s picture

Thanks ashutosh.mishra
I add a patch to include core_version_requirement: ^8 || ^9 in .info file.
I add a patch in dev version.

ashutosh.mishra, sorry but I think that your report is wrong. The file
linked_data_field/tests/src/FunctionalJavascript/LCSubjectAutocompleteWidgetTest.php

doesn't exist in this project. I think the file is in another module.

ashutosh.mishra’s picture

Hi marco.aresu

Sorry, the report was added by mistake . Now Code looks good for me

avpaderno’s picture

shaktik’s picture

Thank you for your contribution!

Review of the 8.x-1.x branch (commit d59bd12):looks good to me.

avpaderno’s picture

Assigned: Unassigned » avpaderno
seonic’s picture

Drupal.behaviors.goBackHistory = {
    attach: function (context, settings) {
      $('.go-back-history-btn').click(function () {
        window.history.back();
      });
    }
  };

This code adds multiple same click events to the each button.
Drupal behaviors calls multiple times and in most cases you should use jQuery.once to prevent multiple code execution on the same element.
You can see examples on the js api overview page:
https://www.drupal.org/docs/8/api/javascript-api/javascript-api-overview

/**
 * Implements hook_page_attachments().
 */
function go_back_history_page_attachments(array &$page) {
  $page['#attached']['library'][] = 'go_back_history/go_back_history';
}

This code adds module library on each page without any checks, even if block does not exists, better to attach it to the block plugin
render array.

go_back_history:
  css:
    theme:
      css/go_back_history.css: {}
  js:
    js/go_back_history.js: {}

If library uses jquery, documentation says that better to add it as dependency.
https://www.drupal.org/node/2216195

avpaderno’s picture

Assigned: avpaderno » Unassigned
Status: Needs review » Needs work
marco.aresu’s picture

Thanks Seonic.
I fixed the following issues:

  1. Add jQuery.once on javascript
  2. Remove hook_page_attachments(). Add library on block plugin
  3. Add jQuery dependencies on libraries file
marco.aresu’s picture

Status: Needs work » Needs review
elavarasan r’s picture

Status: Needs review » Needs work

@marco.aresu,
Please avoid to use DOM element inside the class file.

$content = "<a class='go-back-history-btn'>" . $this->t('Go back') . "</a>";

Instead, create a twig file and place the DOM code inside the file.

For template suggestion, add the below code in .module file.

/**
 * Implements hook_theme().
 */
function go_back_history_theme() {
  return array(
    'go_back_history_block' => array(
      'variables' => array('buttonVal' => NULL),
      'template' => 'block--go--back--history',
     ),
   );
}

Add the below code in the class file.

public function build() { 
  return array(
    '#buttonVal' => $this->t('Go back'),    
  );
}

The twig file "'block--go--back--history.html.twig" will look like below,

{#
/**
 * @file
 * go_back_history custom block.
 */
#}
<a class="go-back-history-btn">{{ buttonVal }}</a>
marco.aresu’s picture

@Elavarasan R

I'm trying your suggestion.
I don't understand how attach libraries.
The libraries are in build block function. If I use hook_theme(), the libraries don't rendered.
Why?

elavarasan r’s picture

Status: Needs work » Needs review

@marco,

Have you tried the below option to attach library and theme file?

public function build() { 
  return [
    '#theme' => 'go_back_history_block',
    '#buttonVal' => $this->t('Go back'),
    '#attached' => [
        'library' => [
          'go_back_history/go_back_history',
        ],
      ],    
  ];
}
elavarasan r’s picture

Status: Needs review » Needs work
marco.aresu’s picture

Thanks @Elavarasan R,

I added your suggestion in dev version.

marco.aresu’s picture

Status: Needs work » Needs review
avpaderno’s picture

avpaderno’s picture

Assigned: Unassigned » avpaderno
Status: Needs review » Fixed

Thank you for your contribution! I am going to update the project to opt it into security coverage.

These are some recommended readings to help with excellent maintainership:

You can find more contributors chatting on the IRC #drupal-contribute channel. So, come hang out and stay involved.
Thank you, also, for your patience with the review process.
Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

I thank all the dedicated reviewers as well.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.