Module description
The site banner module allows a site builder to display a banner at the top and bottom of a Drupal 7 site. It is fixed (or "sticky") to the top and bottom of the visitor's browser (much like how the administrator's toolbar is fixed to the top of the site administrator's browser) when scrolling through the site's content. It also repeats the top and bottom text on printed copies of a site's content. My clients required the ability to define the sensitivity of their Drupal site's content on the site and on printed copies.
It is intended for site builders who host sensitive content on their Drupal site and need to make visitors aware of the sensitivity of the content the visitors are seeing. This module also integrates with the Context module, so if the sensitivity of the content changes then the banner text would need to change accordingly. For example, the Site banner module will combine multiple active contexts tagged with the same tag together with common prefixes and suffixes.
More information and screenshots are available on my project's sandbox page.
Project sandbox page
https://drupal.org/sandbox/ajosephau/2105389
Git repository link
git clone http://git.drupal.org/sandbox/ajosephau/2105389.git site_banner
http://drupalcode.org/sandbox/ajosephau/2105389.git/shortlog/refs/heads/...
Similar modules
- Development Banner (https://drupal.org/project/dev_banner) is a great module for developers and site builders to switch between test and production sites, but my client had a specific need for a text-only banner at the top and bottom of a page that appears on screen and in print. It also had a fixed image set (dev, stage and test), whereas my clients' administrators needed the ability to write plain text into the site banner.
- Environment indicator (https://drupal.org/project/environment_indicator) is another great module for site builders and developers switching between test and production sites. Once again, my clients had the specific need of having banners at the top and bottom of the screen: this module only displays the banner on the top or bottom, but not both. It would also appear that the banner is only displayed on the top if the user has the toolbar active which an anonymous visitor would not need (or want) to see - but would need to see the banner itself. In addition, the module does not have integration with the Context module (which was a client need): I did not want to add context integration functionality to the Environment indicator module as I felt it would compromise Environment Indicator's wide availability. Furthermore my client wanted a very minimal amount of Javascript as possible which I have tried to do in my module.
Whilst both modules are brilliant in their individual respects, I wanted to avoid scope creep by adding unrelated capability (specifically the rather specific Context integration) to their modules. Hence the new project submission.
Developer background
- I have built and maintained several Drupal sites.
- This is the first Drupal module I have written (hence the project application), but I have treid to stick to the Drupal module development norms by writing some automated tests and running my code through pareview.sh.
- I have foundation skills in the Drupal API, PHP and SQL.
Known issues
Integrating with the Context module means that several issues relating to function names are generated, but because these are hooks into the Context module I can't resolve them. The warning for "string literals passed to t()" is generated as I generate supporting description text to support authoring contexts based on validated input.
FILE: ...pal-7-pareview/pareview_temp/site_banner_context_reaction_functions.inc
--------------------------------------------------------------------------------
FOUND 8 ERROR(S) AND 3 WARNING(S) AFFECTING 11 LINE(S)
--------------------------------------------------------------------------------
17 | ERROR | Public method name
| | "SiteBannerContextReactionChangeBannerText::options_form" is
| | not in lowerCamel format, it must not contain underscores
57 | WARNING | Only string literals should be passed to t() where possible
69 | WARNING | Only string literals should be passed to t() where possible
78 | WARNING | Only string literals should be passed to t() where possible
91 | ERROR | Public method name
| | "SiteBannerContextReactionChangeBannerText::options_form_submit"
| | is not in lowerCamel format, it must not contain underscores
112 | ERROR | Public method name
| | "SiteBannerContextReactionChangeBannerBackgroundColor::options_form"
| | is not in lowerCamel format, it must not contain underscores
120 | ERROR | Public method name
| | "SiteBannerContextReactionChangeBannerBackgroundColor::options_form_validate"
| | is not in lowerCamel format, it must not contain underscores
129 | ERROR | Public method name
| | "SiteBannerContextReactionChangeBannerBackgroundColor::options_form_submit"
| | is not in lowerCamel format, it must not contain underscores
161 | ERROR | Public method name
| | "SiteBannerContextReactionChangeBannerTextColor::options_form"
| | is not in lowerCamel format, it must not contain underscores
169 | ERROR | Public method name
| | "SiteBannerContextReactionChangeBannerTextColor::options_form_validate"
| | is not in lowerCamel format, it must not contain underscores
178 | ERROR | Public method name
| | "SiteBannerContextReactionChangeBannerTextColor::options_form_submit"
| | is not in lowerCamel format, it must not contain underscores
--------------------------------------------------------------------------------Reviews of other projects
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | site_banner-interpolation.patch | 13.33 KB | coredumperror |
| #3 | site_banner.jpg | 200.9 KB | kamleshpatidar |
Comments
Comment #1
PA robot commentedWe are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)
Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).
I'm a robot and this is an automated message from Project Applications Scraper.
Comment #1.0
ajosephau commentedadding link to reviewed projects
Comment #1.1
ajosephau commentedadding another project review
Comment #1.2
ajosephau commentedupdating list of project reviews
Comment #2
ajosephau commentedI reviewed the following project applications and would like to request the PAReview review bonus.
Comment #3
kamleshpatidar commentedNice Module ajosephau,
Download and manually check your source code with coder module found 3 notice for Drupal coding standard, but didn't found any issue with pareview module.
To remove that 3 notices, Go through line number 340,341,342 in file site_banner_context_reaction_functions.inc and kill space between isset and opening parentheses. attached is error message Screenshot for your reference.
Good luck.
Comment #4
oresh commentedI don't quite like the css for page wrapper:
First of all it's template dependent, so if someone changes the template and removes the id it would be broken. And also you're overriding styles that could be different. They would be rewritten by the theme if it has the same weight, but still )
And I probably didn't get the idea with:
Why didn't you drupal_add_css() ? :)
Everything else seems fine, thanks for the module.
Comment #5
saitanay commentedNice module ajosephau.
A couple of suggestions:
1) Add an option in the config page to temporarily turn off the banner without disabling the module.
2) When the module is enabled for the first time, the banner is immediately enabled by default showing the default message. Does not give the admin a chance to configure the message. This will be bad if teh admin is to enable the module on a production site, as the admin will be forced to show the default message to visitors till he configures it. Good to disable the module by default allowing the admin to enable the module when needed.
3) The fields "Custom background color' and "Custom text color" are required on the config form, only if the fields "Banner background color" and "Banner text color" are set to specific options. Using Form API STATES, you can show these fields only when certain options are selected.
Refer to https://api.drupal.org/api/drupal/developer%21topics%21forms_api_referen...
Though may be out of scope of the current project, the following are good to see features:
1) Enabled banner by content type, role, path (similar to block configuration)
2) Add a contextual link on the banner, linking to the config form. This link is shown only to those who have permission to configure the module.
This is a nice utilitarian module. Good to have it.
Best
Tanay
Comment #6
saitanay commentedComment #7
ajosephau commentedHi kamleshpatidar,
Thanks for the review :-) and the guidance - I've added those fixes to the latest version on the Git repo. http://drupalcode.org/sandbox/ajosephau/2105389.git/commit/2e6cac1db56f9...
Thanks,
ajosephau
Comment #8
ajosephau commentedHi oresh,
Firstly, the easy CSS include issue: using drupal_add_css() is a wonderful idea! Thanks for letting us know about it. I've cleaned up most of that section using the drupal core api commands in the latest build http://drupalcode.org/sandbox/ajosephau/2105389.git/commit/2e6cac1db56f9....
And with regards to using the #page-wrapper CSS override: that was one of my biggest challenges (and regrets) with this module - trying to get it to play nicely with the themes. I originally tried to follow the Toolbar (the Drupal core module that adds the administrator's toolbar to the top of the page) module's way of getting banners on the page: I think it adds an offset to the #body section. I found that the bottom banner didn't play nicely with the #body section - especially when the admin's overlay pages were displayed as the overlay would cover the bottom banner. So the only way I was able to get the banners to display correctly:
- with the variety of admin toolbar modules available,
- with the admin overlay pages displayed, and
- with a variety of themes
was to add the offset to the #page-wrapper tag.
My clients and I develop sites either with the standard Drupal core themes or customised AdaptiveTheme themes, and they all seem to have that "page-wrapper" DOM object... so my hunch before publishing this module was that the majority of themes would support the module and if it didn't then there was some guidance in the README.txt file that could help out the site builder/themer customise my module or their theme to work.
I'm more than happy to make any changes to get the banners to integrate better (and avoid hacking on top of the #page-wrapper tag) and I'd appreciate your advice, but sadly I'm out of ideas...
Thanks for your review!
ajosephau
Comment #9
ajosephau commentedHi Tanay,
Firstly thanks for reviewing my module :-). I'm working on some of your suggestions at the moment, but I thought I might put in a comment in the mean time so you know I haven't forgotten about you!
I'll keep on implementing your suggestions and change the status once it's ready to go.
As for your last two suggestions, it might take a little longer to implement so I'll include them in the project page (https://drupal.org/sandbox/ajosephau/2105389).
Thanks again for your review!
ajosephau
Comment #10
ajosephau commentedThe latest build contains an updated administrator interface using the #states imperatives for the module settings and corresponding context settings page. Please see the project page for screenshots.
Latest PAReview.sh results shows clean build http://pareview.sh/pareview/httpgitdrupalorgsandboxajosephau2105389git
Updating project status to review.
Comment #11
coredumperror commentedHello! I went through your code and did a thorough review of the code itself. It looked good throughout, except for one fairly minor issue. It appears that you may not be aware of one of PHP's major advantages, known as variable interpolation. Rather than using this code:
You can get the same effect using this code:
This is significantly more readable, which I personally consider to be an extremely important feature for code. In the attached patch, I found and corrected numerous blocks of code which could be improved by making the change to interpolated strings.
I also ran into a bunch of comments like this one:
// @codingStandardsIgnoreStartI'm not really sure what these are for (though I can make a reasonable guess), but they seem to commonly be near functions which are improperly documented. Like
SiteBannerContextReactionChangeBannerTextColor->options_form_submit(): the doc comment for that function is completely wrong.I'd suggest going through the code that's surrounded by those codingStandardsIngore comments and actually correcting the problems, rather than just marking them as ignored.
Comment #12
klausimanual review:
Removing review bonus tag, you can add it again if you have done another 3 reviews of other projects.
Comment #13
ajosephau commentedHello coredumperror (wish I thought of a good name like that!),
Firstly, thank you very much for time to review my module, especialy for writing the patch! I totally agree about using PHP's variable interpolation instead of concatenating strings on-the-fly. I have incorporated your patch into the Git repo: I hope I got the git attribution correct (let me know if it's not right).
Oh yes, about those
@codingStandardsIgnoreStartblocks: this was an issue I found with integrating with the Context module. Unfortunately now I get the following errors reported by Coder/PAReview.shUnfortunately, in order to integrate with the Context module I need to use those function names which don't pass these checks, so to get a 'clean build' from Coder/PAReview.sh. I added those ignore statements around the entire code block as putting the ignore comments around the comment only meant the review modules threw 'missing comments' errors instead.
For the mean time, I inherit the comments from the parent class' (context_reaction) documentation.
Comment #14
ajosephau commentedHi klausi,
Thank you so much for your in-depth manual review :-). Here are the comments as requested:
4) I re-use a lot of form generation, validation and submission code between the admin page and the context admin page: I understand putting the form building functions makes it a bit harder to read, but I felt it was a lot more maintainable and consistent between both pages.
5 and 6) You are correct - I don't need to have the separate hook_html_head_alter() and hook_page_build() functions - I have merged both functions together and added some supporting comments to explain what has happened. But because I am using the hook_page_build() I still use the drupal_add_css() functions to add the CSS files to the page, because I don't think I have access to the #attached property on the head elements?
8) I agree - originally I wanted to give the admin freedom to put in raw HTML (hence I put the warning on the permission), but indeed you are correct it is an XSS vulnerability. I added the filter_xss_admin() to the colour and text outputs in the hook_page_build() function.
I have also commented out of completeness for the rest of your notes.
1) I originally had to exclude the whole methods from the coding standards because when I put the ignore tags around the comment headers, the reviewing modules complained there was 'blank space' between the comment block and function name. I must admit, I didn't think I would get reviews (and more importantly a full project approval) if I didn't remove all the errors thrown by PAReview.sh/Coder module. So thanks for your comment - I've removed the ignore statements and you'll see the errors in the latest results http://pareview.sh/pareview/httpgitdrupalorgsandboxajosephau2105389git
2) I used the check_plain() command as I got the error from the Coder module saying "Potential problem: drupal_set_message() only accepts filtered text..." - I read that link you suggested, and given that the only substituted text is a URL I used the check_url() command.
3) Agreed - I have added functions to define default banner text and colours, and I have put those as parameters to the variable_get() functions.
7) Agreed - fixed in latest commit.
9) Agreed.
I just need to update my automated test files to work with the fixes in points 5 and 6, but I'll update the status once the commit is ready. Thanks again for your review!
EDIT:
5 & 6) Following the guidance at https://drupal.org/node/542202#stylesheets , I put the CSS file references in the site_banner.info
Comment #15
coredumperror commentedPAReview is really just guidelines. It says right up at the top that many of the reported problems may be false positives. I get the same kinds of errors when I run Date iCal through PAReview, for the same reasons (conforming to a different naming convention), so I just ignore them.
And thanks for the complement on my username. :) I came up with it back in college, when I was dealing with core dumps on a very regular basis during my C classes.
Comment #16
ajosephau commentedOh I understand - I must admit it I developed that misconception from looking at other reviews and assumed I needed to have a clean build before I'd get my module reviewed. I'll add an explanatory note to the issue description too soon for future reviewers (and keep it in mind for other project application reviews I do - I want my PAReview bonus back!).
Comment #16.0
ajosephau commentedchanging heading to suit review bonus instructions
putting headings instead of bold text
Comment #17
ajosephau commentedUpdating status to review after responding to/resolving feedback raised by coredumperror and klausi. Thanks again for the review!
Comment #17.0
ajosephau commentedAdding known issue to issue text
Comment #18
klausiSorry for the delay. Make sure to review more project applications and get a new review bonus and this will get finished faster.
manual review:
But otherwise looks RTBC to me.
Assigning to patrickd as he might have time to take a final look at this.
Comment #19
ajosephau commentedThank you so much klausi for your second review (and your patience!). I totally agree with your feedback, and I think I'm starting to understand how these security functions like check_url(), check_plain(), filter_xss() work, especially with the t() function.
I'm making a commit to the repo soon with your fixes, and I'm hoping to get some free time to do some reviews soon.
Comment #20
ajosephau commentedComment #21
klausino objections for more than a week, so ...
Thanks for your contribution, ajosephau!
I updated your account so you can promote this to a full project and also create new projects as either a sandbox or a "full" project.
Here are some recommended readings to help with excellent maintainership:
You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and stay involved!
Thanks, 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.
Thanks to the dedicated reviewer(s) as well.
Comment #22
ajosephau commentedThank you so much klausi for updating my account, and for all of your guidance (and recent notes too - I've got to get in on this IRC thing!)
And thank you too to kamleshpatidar, oresh, saitanay and coredumperror - you all are the best!