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
Comment #1
j2r commentedSemicolon is missing in block_visibility_switcher.module line number 13.
change this to
Do not add version in .info file.
block_visibility_switcher.css must end in a single new line character. Similarly in js file.
Comment #2
Timusan commentedHey 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
Comment #3
Timusan commentedComment #4
Timusan commentedHey j2r
I apparently misunderstood your comment.
Fixed the missing semicolon on line 13 and removed the default operand from the condition.
Cheers
T
Comment #5
hamburgers commentedIt 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.
Comment #6
Timusan commentedHey 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
Comment #6.0
Timusan commentedFixed error in Link to GIT repo.
Comment #7
ti2m commentedHi,
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}Comment #8
Timusan commentedHello 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
$switchvariable. 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
Comment #8.0
Timusan commentedUpdated with reviewed projects
Comment #8.1
Timusan commentedNew project reviewed.
Comment #9
Timusan commentedAdded PAReview: review bonus tag as stated in http://drupal.org/node/1410826.
Comment #10
ti2m commentedHi Timusan,
I checked the updates:
.module line 69
.js line 10
Hope this helps
Comment #11
ti2m commentedSorry, am always forgetting to switch the status.
Comment #12
Timusan commentedHey 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 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 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
Comment #13
Timusan commentedSame here, haha, also forgetting so set the status all the time :)
Comment #14
klausiReview of the 7.x-1.x branch:
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:
Removing review bonus tag, you can add it again if you have done another 3 reviews of other projects.
Comment #15
Timusan commentedHey 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
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?
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.
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
Comment #16
Timusan commentedHey 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
Comment #17
klausiClosing due to lack of activity. Feel free to reopen if you are still working on this application.
Comment #17.0
klausiAdded anther project I reviewed.