This module can be useful when we need to set up a block, based on a cookie value. This module will automatically create a plugin-based condition in block form.

Project link

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

Git instructions

git clone --branch '2.x' https://git.drupalcode.org/project/cookie_block.git

Comments

gurjinder_pabla created an issue. See original summary.

avpaderno’s picture

Issue summary: View changes
Status: Needs review » Needs work

Thank you for applying!

The 8.x-1.0 branch has a wrong name; it needs to be removed. The other branch names are correct.

gurjinder_pabla’s picture

Thank you for review the code. Branch 8.x-1.0 deleted.

gurjinder_pabla’s picture

Status: Needs work » Needs review
avpaderno’s picture

Status: Needs review » Needs work
  • What follows is a quick review of the project; it doesn't mean to be complete
  • For every point, the review doesn't make a complete list of lines that should be fixed, but an example of what is wrong in the code
  • A review is about code that doesn't follow the coding standards, contains possible security issue, or doesn't correctly use the Drupal API; if a point isn't about that, it makes it clear
    if (!empty($this->configuration['negate'])) {
      return t('The cookie @cookie_id is not @cookie_value.', [
        '@cookie_id' => $this->configuration['cookie_id'],
        '@cookie_value' => $this->configuration['cookie_value'],
      ]);
    }
    return t('The cookie @cookie_id is @cookie_value.', [
      '@cookie_id' => $this->configuration['cookie_id'],
      '@cookie_value' => $this->configuration['cookie_value'],
    ]);

t() should not be used in a class that uses DI. In that case, the class should also use the StringTranslationTrait trait.

    $cookies = \Drupal::request()->cookies;

\Drupal should not be used from a class that uses DI.

avpaderno’s picture

geoanders’s picture

Ran a quick scan. See results below:

FILE: /cookie_block/src/Plugin/Condition/CookieCondition.php
------------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 3 LINES
------------------------------------------------------------------------------------------------------------------------------------------
  83 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
  88 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 103 | WARNING | Unused variable $default_value.
------------------------------------------------------------------------------------------------------------------------------------------

FILE: /cookie_block/src/Plugin/Condition/CookieCondition.php
--------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------
 33 | WARNING | Possible useless method overriding detected
--------------------------------------------------------------------------------------------------
gurjinder_pabla’s picture

Status: Needs work » Needs review

Thanks for review the module, Module update with Drupal coding standards.

avpaderno’s picture

Status: Needs review » Fixed

Thank you for your contribution! I am going to update the project.

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.