Allows you to add a block to any type of content. This block adds a button that allows us to return to the previous page that we visited on the site or customize the page where we want it to redirect.

We have 2 modes of use:

  • Custom URL: It allows us to add a custom url to the block button so that the user can go where we want, the customization is independent for each type of content. This url will be used also if the user comes from outside the site and the smart mode is activated.
  • Mode Smart: The button of the block will take as url the last one of the site that we have visited, we can activate this option for each type of content, in the case that we come from outside the site, the url custom will be url.

Requirements

None

Project link

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

Git instructions

git clone --branch 8.x-1.x https://git.drupal.org/project/go_back.git

Manual reviews of other projects

https://www.drupal.org/node/2993617#comment-12750718
https://www.drupal.org/node/2994539#comment-12750727
https://www.drupal.org/node/2994325#comment-12750732

CommentFileSizeAuthor
#12 refactor_empty_if-2995491-11.patch752 bytesolegel

Comments

saesa created an issue. See original summary.

saesa’s picture

Status: Active » Needs review
avpaderno’s picture

Issue summary: View changes
saesa’s picture

Priority: Normal » Critical
avpaderno’s picture

Priority: Critical » Normal
kyberman’s picture

Status: Needs review » Needs work

Review of the 8.x-1.x branch (commit c6aeaa3):

  • PAReview result is almost clean, only writing of test is recommended: https://pareview.sh/pareview/https-git.drupal.org-project-go_back.git.
  • Nice README.txt file - please fix only useless "</ul>" and space after dot ("configuration.You").
  • Package inside go_back.info.yml is set to "Custom" - isn't there some better category? If not, I would use "User interface" or "Other" instead.
  • Inside repository, there is branch named "@branch" - probably better to delete as it doesn't contain any commits.
  • File go_back.css contains absolute paths - please fix them to be relative ("../images/back.png")
  • Your hook_theme provides "block__go__back" template - it should be renamed to "block__go_back" (see "system_theme()").
  • Block GoBack.php is having some minor issues:
    • Condition "if ($config[$bundle]['quick_display'] == '1')" is doubled (lines 177 and 178).
    • Also "$urlb = $_SERVER['HTTP_REFERER'];" is doubled (lines 180 and 182).
    • Basically whole code block of lines 185-194 and 198-207 are duplicates without any reason.
    • It would be good to autoformat (few extra newlines).
    • Fix coding standards (usage of double quotes for strings).
    • Add some inline comments into "build()" function.
    • I would also replace comparing like "$var == '1'" by "!empty($var)".
saesa’s picture

Status: Needs work » Needs review
  • PAReview result is almost clean, only writing of test is recommended: https://pareview.sh/pareview/https-git.drupal.org-project-go_back.git.
  • Nice README.txt file - please fix only useless "/ul" tag and space after dot ("configuration.You").
  • Package inside go_back.info.yml is set to "Custom" - isn't there some better category? If not, I would use "User interface" or "Other" instead.
  • Inside repository, there is branch named "@branch" - probably better to delete as it doesn't contain any commits.
  • File go_back.css contains absolute paths - please fix them to be relative ("../images/back.png")
  • Your hook_theme provides "block__go__back" template - it should be renamed to "block__go_back" (see "system_theme()").
  • Block GoBack.php is having some minor issues:
  • Condition "if ($config[$bundle]['quick_display'] == '1')" is doubled (lines 177 and 178).
  • Also "$urlb = $_SERVER['HTTP_REFERER'];" is doubled (lines 180 and 182). if you eliminate one of the two it does not work anymore
  • Basically whole code block of lines 185-194 and 198-207 are duplicates without any reason. I've put the reason in comments in the code, if you see another way that works, I'm happy to hear it
  • It would be good to autoformat (few extra newlines).
  • Fix coding standards (usage of double quotes for strings).
  • Add some inline comments into "build()" function.
  • I would also replace comparing like "$var == '1'" by "!empty($var)". It is a checkbox, it has 0 and 1
olegel’s picture

Review of the 8.x-1.x branch (commit 77b610d):

Module passes Drupal and DrupalPractice coding standards (on my local machine).

1. I noticed in GoBack.php on line 186 if statement with comment inside. It looks like a statement with empty body:

if (strcmp($urlb, '') !== 0) {
            // Check if the url is from our site.
          }

Is it necessary there?

2. Also, code on line 244 would throw an exception if entity type doesn't exist or storage handler couldn't be found. Should those exceptions be caught?
This is from doc comments in EntityTypeManagerInterface.php
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* Thrown if the entity type doesn't exist.
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* Thrown if the storage handler couldn't be loaded.

3. Line 185: I would add check whether $_SERVER['HTTP_REFERER'] exists since you wrote in comments that it could be from another site.
There might be chance HTTP_REFERRER is not set by some domains. (I don't think it breaks code, since it would be just in $_SERVER array).

Thank you for your efforts.

saesa’s picture

Thanks olegel for the review,

  1. Is necessary for it to work, if you find some other way to make it work I'll modify it.
  2. It is assumed that to use this module you have to have a type of content created, I do not believe a site in drupal does not have one created.
  3. That only works when the intelligent mode is activated, that variable will bring the url from where we come if it is inside our site, otherwise it will bring us the normal way

Example:

Smart mode in our site return this:

If we come from page /home smart mode return in our goback block /home not return examle.com/home

olegel’s picture

No problem, saesa.
As I wrote, for me your code looks fine.
About first notice with empty if block: since you code jumps to else block, what if you change it like that:

          if (strcmp($urlb, '') === 0) {
            // Check if the url is from our site.
 // If the url is not from our site, take the url by default.
            if (substr($config[$bundle]['go_back'], 0, 1) == '/') {
              /*
              Transforms the url into a readable URL for Drupal
              and add the interface language.
               */
              $url = Url::fromUri('base:' . $config[$bundle]['go_back'], [
                'language' => $this->languageInt->getLanguage($langcode),
              ]);
              $path = $url->toString();
              $urlb = $path;
            }
          }

It should work in the same way as you current code.

saesa’s picture

How do you restructure the code and that everything works? I think it's fine, if you think there's some way you could patch the module page. Thanks Olegel.

olegel’s picture

StatusFileSize
new752 bytes

Saesa, please check attached patch. As I mentioned, it is not blocker, and in my opinion, module can be pushed to security coverage policy.
Can I myself change issue's status to fixed (and tested)?

saesa’s picture

Thanks for the patch, you can change the status to Reviewed & tested by the community.

olegel’s picture

Status: Needs review » Reviewed & tested by the community
avpaderno’s picture

Status: Reviewed & tested by the community » Needs work
      $form[$content_type]['quick_display'] = [
        '#type' => 'checkbox',
        '#title' => $this->t("Active button in") . ' ' . $content_type,
        '#options' => $content_type,
        '#default_value' => $config[$content_type]['quick_display'],
      ];

String to translate should use placeholders to include the dynamic part of the string. In this way, translators have more context to translate the string, considering that in some language the translation of Active button in could change basing on the next word/phrase.

saesa’s picture

Status: Needs work » Needs review

The dynamic part of the text is the string of the content type, if you translate the content type in the drupal configuration it will already be translated, it is not necessary to translate it again.

avpaderno’s picture

Status: Needs review » Needs work

Placeholders aren't translated.
If you look at Drupal core for similar code, you won't find code that concatenates a translated string to a not translated string. In those cases, a placeholder is used inside the translated string.

saesa’s picture

You mean this?

      $form[$content_type]['quick_display'] = [
        '#type' => 'checkbox',
        '#title' => $this->t("Active button in") . ' ' . $content_type,
        '#options' => $content_type,
        '#default_value' => $config[$content_type]['quick_display'],
        '#attributes' => [
          'placeholder' => $this->t("Active button in") . ' ' . $content_type,
          ],
      ];
avpaderno’s picture

Yes, I mean that and similar code the module is using. Compare it with the following code took from NodeController.php.

return $this->t('Revision of %title from %date', [
  '%title' => $node->label(),
  '%date' => format_date($node->getRevisionCreationTime()),
]);

For more information on the placeholder types, see FormattableMarkup::placeholderFormat().

As side note, even concatenating translated string should be avoided.

// Wrong code.
$header = $this->t('List') . ' ' .  $this->t('of') . ' ' . $this->t('files to delete'); 
saesa’s picture

You mean this? I use the code that you passed as an example.

      $form[$content_type]['quick_display'] = [
        '#type' => 'checkbox',
        '#title' => $this->t("Active button in %content_type", [
          '%content_type' => $content_type,
        ]),
        '#options' => $content_type,
        '#default_value' => $config[$content_type]['quick_display'],
        '#attributes' => [
          'placeholder' => $this->t("Active button in %content_type", [
            '%content_type' => $content_type,
          ]),
        ],
      ];
avpaderno’s picture

The code should be similar to the following one. A checkbox form element doesn't use #options.

$form[$content_type]['quick_display'] = [
  '#type' => 'checkbox',
  '#title' => $this->t("Active button in %content_type", ['%content_type' => $content_type]),
  '#default_value' => $config[$content_type]['quick_display'],
  '#attributes' => [
    'placeholder' => $this->t("Active button in %content_type", ['%content_type' => $content_type]),
  ],
];
saesa’s picture

Status: Needs work » Needs review

I have already fixed the code as you said.

avpaderno’s picture

Status: Needs review » Reviewed & tested by the community
saesa’s picture

When pass to fixed?

visabhishek’s picture

Status: Reviewed & tested by the community » Fixed

Thank you for your contribution!

I am going to update your account so you can opt into security advisory coverage now.

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.

visabhishek’s picture

Adding credits.

Status: Fixed » Closed (fixed)

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