This is a module for Drupal 7.x.

In a standard Drupal installation, if allowed by the site administrator, certain blocks are customizable by the users. For enabling or disabling these blocks, the users must go to their account page. This small module gives the site users the more intuitive ability to disable the blocks within the blocks themselves.

Once enabled, each block that is customizable will get a 'Close' link rendered next to its title. When clicked, the block will disappear. To re-enable the block, the users can visit their account page and enable the block again.

Link to the sandbox: http://drupal.org/sandbox/Timusan/1659156
Link to the GIT repo: http://git.drupal.org/sandbox/Timusan/1659156.git

Other projects I have reviewed:

http://drupal.org/node/1661880#comment-6167378
http://drupal.org/node/1650548#comment-6180460
http://drupal.org/node/1666832#comment-6182492

Comments

j2r’s picture

Status: Needs review » Needs work

Semicolon is missing in block_visibility_switcher.module line number 13.

->condition('bid', $block_id, '=') 

change this to

->condition('bid', $block_id) 

Do not add version in .info file.

block_visibility_switcher.css must end in a single new line character. Similarly in js file.

Timusan’s picture

Hey j2r

Thank you for taking the time to review my module.

Fixed the newlines and removed the version from the info file.

Your comment about the missing semicolon seems strange to me.
In your changed version you just remove the operand from the condition. Furthermore, there should not be a semicolon at the end of that line because it is a concatenation of the object, or am I missing something here?

Cheers
T

Timusan’s picture

Status: Needs work » Needs review
Timusan’s picture

Hey j2r

I apparently misunderstood your comment.
Fixed the missing semicolon on line 13 and removed the default operand from the condition.

Cheers
T

hamburgers’s picture

It looks like you have files other than README.txt in the master branch, you should remove those.

Code sniffer only found one issue that you may want to fix. You have one function "toggle_block()" that should be renamed to include the name of your module.

http://ventral.org/pareview/httpgitdrupalorgsandboxtimusan1659156git

Cool idea and works as advertised.

Timusan’s picture

Hey Hamburgers

Thank you for reviewing.

I cleaned out the master branch, leaving only a general README.txt.
Also prefixed the custom function to comply with naming conventions.

Glad you like the idea ;)

Cheers
T

Timusan’s picture

Issue summary: View changes

Fixed error in Link to GIT repo.

ti2m’s picture

Status: Needs review » Needs work

Hi,
your module conatins only 4 functions and less then 120 lines of code (CSS and tpl files not counted). I don't think it will satisfy condition 2.3 on the project application checklist.

General issues:
- Please test your module after applying changes
- The close button conflicts with the contextual links button (at least in theme seven)

module file:
- Line 1: contains a "G" before the php tag, it gets printed on every page
- Line 40: You didn't update the callback function after the last changes
- I think this isn't a toogle function, you are just disabling the block, never enabeling, therefor you also don't need the switch variable, as it's always 0 anyway
- POST data is not getting sanitized at all, when changing your JS call to &switch=whatever it will write whatever to the DB. Very critical! I'm not 100% sure if Drupal automatically sanitzies data in dynamic queries (propbaly does), but I would wrap an intval() around the POST block_id anyway.
- Line 69: Check if the query was successful at all, otherwise empty entries end up in the DB (for example with JS call 'block_id=whatever')

js file:
- Line 8: dataType describes the data format that's being expected from the server. So far no data is being returned and jQuery detects the format automatically (but of course you can leave it if you really sent JSON data)
- Line 9: The success callback is wrong. You are missing an 's' and the call itself is wrong, it should look like this
success: function(){$(this).parents('div.block').fadeOut()},
What's happening now is that fadeOut() is being called no matter what, which is why it seems to work. You should pass a state back from the callback to the JS success function (e.g. with drupal_json_output) that actually reflects if the call did what it was supposed to, 'success' just tells you that the server didn't throw any errors.
- Line 10: I know you can pass POST data as strings, but I would highly recommend using a map like
data: {block_id: $(this).attr('id'), switch: 0}

Timusan’s picture

Status: Needs work » Needs review

Hello ti2m

First of, thank you reviewing my module. And thank you for the coding suggestions/explanations.

I'm aware that, in case you are logged in as admin, the settings cog tends to overlap the close link.
This is also indeed mostly the case with the Seven theme. However, the current position of the close link seems most natural to me, any suggestions on a better placement are welcome.

My apologies for the errors in the code. The most obvious errors like the leading 'G' and the non-updated callback function, were already fixed, but somehow did not make it into my GIT repo.

The rest of your code suggestions are solid and I updated (and tested!) my code. You will find that the current head in my GIT repo reflects your suggestions.

I also removed the $switch variable. You are correct that it is not a 'switch' but more an 'off' function now. My plans are however to further build out the module, if people where satisfied with the general idea, to create a more switch-like functionality. Or let users choose between a 'switch' or an 'off' mode like now. But the code should reassemble the current functionality. Of course the switch is also removed from the POST.

Cheers
T

Timusan’s picture

Issue summary: View changes

Updated with reviewed projects

Timusan’s picture

Issue summary: View changes

New project reviewed.

Timusan’s picture

Issue tags: +PAreview: review bonus

Added PAReview: review bonus tag as stated in http://drupal.org/node/1410826.

ti2m’s picture

Hi Timusan,

I checked the updates:

  1. pareview shows 3 errors
  2. produce JSON output anyway. Even if the query returns no result the callback itself is still considered to be successful, therefore the block will be hidden and reappear on next refresh. A way would be to exit, but that's not clean (drupal needs to shutdown), so add something like this:
    .module line 69
      $json = array('success' => false);
      if (!empty($result)) {
        .....
        $json['success'] = true;
      }
      return drupal_json_output($json);
    

    .js line 10

    success: function(data, textStatus) {
     if(data.success != undefined && data.success == true){
       block.parents('div.block').fadeOut()
     }
    },
    
  3. Line 58: I would check if $_POST['block_id'] is set at all, intval() will return 0 anyway, but I don't think its a clean solution
  4. Line 54: Load the user after line 70, its not needed before that and you might not need to load it at all if the block_id is wrong
  5. In hook_init, check if the user is authenticated, right now you always add the resources, no matter what
  6. I might even add a specific permission, then you can choose which role should be able to use this
  7. I'm amazed Drupal coding style dosen't say anything about inline variables in strings, but I would call "$my_path/block_visibility_switcher.css" bad practise, but just my opinion
  8. I would make a css sprite for the buttons

Hope this helps

ti2m’s picture

Status: Needs review » Needs work

Sorry, am always forgetting to switch the status.

Timusan’s picture

Hey ti2m

Thanks again for the review :)

Ok, updated the necessary files and pushed to my GIT.
Most of the points I can agree with and are indeed better practice.

Two points I'm a bit two-parted about:

  • I might even add a specific permission, then you can choose which role should be able to use this

    I also considered that, and though it might add more lines of code, the permission is actually handled by Drupal already. If the administers gives user the ability to customize them, its already a way of granting access.

  • I'm amazed Drupal coding style doesn't say anything about inline variables in strings, but I would call "$my_path/block_visibility_switcher.css" bad practice, but just my opinion

    I'm not sure if it is bad practice...now the drupal_get_path only gets called once which is by default a better practice and it is more readable. A third added value is that it stays under the 80 column limit.

Cheers
T

Timusan’s picture

Status: Needs work » Needs review

Same here, haha, also forgetting so set the status all the time :)

klausi’s picture

Status: Needs review » Needs work
Issue tags: -PAreview: review bonus

Review of the 7.x-1.x branch:

  • Drupal Code Sniffer has found some issues with your code (please check the Drupal coding standards).
    
    FILE: ...l/modules/pareview_temp/test_candidate/block_visibility_switcher.module
    --------------------------------------------------------------------------------
    FOUND 1 ERROR(S) AFFECTING 1 LINE(S)
    --------------------------------------------------------------------------------
     64 | ERROR | else must start on a new line
    --------------------------------------------------------------------------------
    FILE: .../modules/pareview_temp/test_candidate/block_visibility_switcher.tpl.php
    --------------------------------------------------------------------------------
    FOUND 0 ERROR(S) AND 1 WARNING(S) AFFECTING 1 LINE(S)
    --------------------------------------------------------------------------------
     4 | WARNING | Line exceeds 80 characters; contains 97 characters
    --------------------------------------------------------------------------------
    

This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. You have to get a review bonus to get a review from me.

manual review:

  1. There is no code to add the toggle link to block titles? How should this module work, or am I missing something?
  2. block_visibility_switcher_toggle_block(): this should only be executed for logged in users. It will probably cause errors when triggered as anomyous user.
  3. It would be nice to have a permission to indicate which role is allowed to use that functionality.

Removing review bonus tag, you can add it again if you have done another 3 reviews of other projects.

Timusan’s picture

Hey Klausi

Thank you for reviewing.

I will try to fix the errors mentioned in PAReview, though I was in the assumption that these where not critical show-stoppers.

As for your manual review

There is no code to add the toggle link to block titles? How should this module work, or am I missing something?

The code that adds the toggle link is set by the block template file included with the module. The template also includes the necessary checks to see if one is logged in or not. Is this considered bad practice?

block_visibility_switcher_toggle_block(): this should only be executed for logged in users. It will probably cause errors when triggered as anomyous user.

In this function I check if block_id was set, but this apparently could also be faked in a POST call. I will add a global $user->uid check.

It would be nice to have a permission to indicate which role is allowed to use that functionality.

As you can read in the comments above your review I was not sure if that would be a good idea. If the site administer already gives your permission to customize your block, that by itself is a permission set. But you want the ability to still switch between Drupal's standard behavior and my module?

Cheers
T

Timusan’s picture

Status: Needs work » Postponed

Hey guys

I'm postponing the project because its currently to busy with work and because I want to implement further functionality as discussed in the above comments. I hope to continue my work on this module in around one or two weeks.

Thanks for the help so far!

Cheers
T

klausi’s picture

Status: Postponed » Closed (won't fix)

Closing due to lack of activity. Feel free to reopen if you are still working on this application.

klausi’s picture

Issue summary: View changes

Added anther project I reviewed.