Module Description:
This is a simple add-on for the context module which includes a new context reaction option called "Hide a Field(s)". If selected it will proceed to hide a selected node field (or multiple fields) when viewing a full node.

Example Use Case:
This module can be helpful if you rely on Drupal's Features module for setting up content types and managing field displays. In order to change the way certain fields display you would need to override or update the Feature. In many cases this is fine, however, in the case where you are leveraging Drupal's multisite functionality, overriding the feature will apply to all sites by default. This module allows different sites to hide certain fields when viewing a node (through context), without having to make a global change to the feature.

Project Page:
https://www.drupal.org/sandbox/plinthify/2688581

git clone command:

git clone --branch 7.x-1.x http://git.drupal.org/sandbox/plinthify/2688581.git context_hide_field
cd context_hide_field

Comments

robdubparker created an issue. See original summary.

robdubparker’s picture

Issue summary: View changes
robdubparker’s picture

Issue summary: View changes
PA robot’s picture

Issue summary: View changes

Fixed the git clone URL in the issue summary for non-maintainer users.

We 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.

pankajsachdeva’s picture

Automated Review

Found some issues on pareview.sh. Follow the link : http://pareview.sh/pareview/httpgitdrupalorgsandboxplinthify2688581git

Manual Review

Individual user account
[Yes: Follows] the guidelines for individual user accounts.
No duplication
[Yes: Does not cause / No: Causes] module duplication and/or fragmentation.
Master Branch
[Yes: Follows] the guidelines for master branch.

But there are some errors found in pareview.sh. Please remove them.

Licensing
[Yes: Follows] the licensing requirements.
3rd party assets/code
[Yes: Follows] the guidelines for 3rd party assets/code.
README.txt/README.md
[No: Does not follow] the guidelines for in-project documentation and/or the README Template.

In README.txt file, a line should be wrap to 80 charaters only.

One more thing, Automated Review on pareview.sh shows that your README.txt file is missing. This is because your module files are in child directory of 'context_hide_field'. Move to the parent directory.

Code long/complex enough for review
[No: Does not follow] the guidelines for project length and complexity.
Secure code
[Yes: Meets the security requirements.]
Coding style & Drupal API usage
Few Suggestions:
  1. In context_hide_field.module file :
    Line 37: use a space between the closing parenthesis and the open bracket
    function context_hide_field_node_view_alter(&$build){
    
    Line 39: Control statements should have one space between the control keyword and opening parenthesis
      if($build['#view_mode'] == 'full'){
    
    Line 39: use a space between the closing parenthesis and the open bracket
      if($build['#view_mode'] == 'full'){
  2. In context_hide_field.context.inc file:
    Line -1: @file block missing (Drupal Docs)
    
    Line 17: Control statements should have one space between the control keyword and opening parenthesis
        foreach(field_info_instances('node') as $k => $v){
    
    Line 17: use a space between the closing parenthesis and the open bracket
        foreach(field_info_instances('node') as $k => $v){
    
    Line 18: Control statements should have one space between the control keyword and opening parenthesis
          foreach($v as $key => $value){
    
    Line 18: use a space between the closing parenthesis and the open bracket
          foreach($v as $key => $value){
    
    Line 40: use a space between the closing parenthesis and the open bracket
      function execute(&$build){
    
    Line 41: Control statements should have one space between the control keyword and opening parenthesis
        foreach($this->get_contexts() as $context){
    
    Line 41: use a space between the closing parenthesis and the open bracket
        foreach($this->get_contexts() as $context){
  3. Implement hook_help() in your module.

Module is working fine.

This review uses the Project Application Review Template.

pankajsachdeva’s picture

Status: Needs review » Needs work
robdubparker’s picture

Issue summary: View changes
robdubparker’s picture

Thanks, @pankajsachdeva

I've made the suggested updates.

robdubparker’s picture

Status: Needs work » Needs review
pankajsachdeva’s picture

Hi robdubparker,

There are still some issues on pareview.sh. Follow link : http://pareview.sh/pareview/httpgitdrupalorgsandboxplinthify2688581git

Please fix all these issues.

pankajsachdeva’s picture

Status: Needs review » Needs work

Thanks for your contribution.I would suggest you to take a review bonus to speed up the process. Please help reviewing and put yourself on the high priority list, then GIT Admins will take a look at your project right away :-)

robdubparker’s picture

Thanks, @pankajsachdeva

I have fixed all code sniffer issues with the exception of one:

15 | ERROR | Public method name "ContextHideFieldReaction::options_form"
| | is not in lowerCamel format

The options_form method name comes from the context module, so I don't think I'm able to fix this one.

Also, thanks for the review bonus recommendation. I will do this as well.

robdubparker’s picture

Status: Needs work » Needs review
romanblanyar’s picture

Hello, I have installed and tested your module. it works well and does not cause errors or failures. But when I choose which fields to hide there for only three tabs: body, image and tags. Will in the future to expand the field that can hide?

robdubparker’s picture

Thanks, @romanblanyar

The options should include any custom fields you have setup within your content types. As an example, add a few extra fields in one of your content types, and you should see them appear as options within the "Hide a Field(s)" reaction. If you are not seeing this, please let me know.

Thanks, again

nico.knaepen’s picture

In the .info file package is set to "custom". It is better to set the package to "Context" because it depends on the context module:
package = "Context"

Try to avoid complex code, some examples:
- A function should never contain more then 20 lines of code
- Each function should only focus on one thing at a time
- Try to avoid indenting too much.

I've rewritten your code a bit to give you some more insights on how you can make your code more readable:

public function options_form($context) {

    $form = array();
    $form['fields'] = array(
      '#type' => 'fieldset',
      '#title' => "Select fields to hide",
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
    );
    $form['fields']['hide'] = array(
      '#type' => 'checkboxes',
      '#title' => t("Hide the following fields for the current node."),
      '#options' => $this->getFieldsHideOptions(),
      '#default_value' => $this->getFieldsHideDefaultValue($context),
    );

    return $form;
  }

  private function getFieldsHideDefaultValue($context) {
    $values = $this->fetch_from_context($context);
    return isset($values['fields']) ? $values['fields']['hide'] : array();    
  }

  private function getFieldsHideOptions() {
    $fields = array();

    foreach (field_info_instances('node') as $v) {
      foreach ($v as $key => $value) {
        $fields[$key] = $value['label'];
      }
    }

    asort($fields);

    return $fields;
  }

  /**
   * Executes the form.
   */
  public function execute(&$build) {
    foreach ($this->get_contexts() as $context) {
      if (isset($context->reactions[$this->plugin]['fields'])) {
        $this->executeByFields(
          $context->reactions[$this->plugin]['fields']['hide'],
          $build
        );
      }
    }
  }

  private function executeByFields($fields, &$build) {
    foreach (array_filter($fields) as $name => $label) {
      if (isset($build[$name])) {
        $build[$name]['#access'] = FALSE;
      }
    }
  }
robdubparker’s picture

Thanks, @nico.knaepen

I've updated the branch with your latest recommendations.

amykhailova’s picture

Automated review

Pareview.sh found some errors. Please take a look here: http://pareview.sh/pareview/httpgitdrupalorgsandboxplinthify2688581git

Manual review

Individual user account
Yes: Follows the guidelines for individual user accounts.

No duplication
Yes: Does not cause duplication and/or fragmentation.

Master Branch
Yes: Follows the guidelines for master branch.

Licensing
Yes: Follows the licensing requirements.

3rd party assets/code
Yes: Follows the guidelines for 3rd party assets/code.

README.txt/README.md
No: Does not follow the guidelines for in-project documentation and/or the README Template.

In README.txt file, a line should be wrap to 80 charaters only.

Code long/complex enough for review
Yes: Follows the guidelines for project length and complexity. The module is short, but longer than 120 lines of code and 5 functions.

Secure code
Yes: Meets the security requirements.

Coding style & Drupal API usage:
Didn't find any issues.

klausi’s picture

@Amy: I think you forgot to change the status. Is this now RTBC after your review or are there application blockers left and this should be "needs work"?

robdubparker’s picture

Thanks, @amykhailova. I've made the updates/fixes to the issues you've outlined.

yogeshmpawar’s picture

Status: Needs review » Reviewed & tested by the community

Hi robdubparker,

Automated Review

Please check the errors in automatic reviews
http://pareview.sh/pareview/httpgitdrupalorgsandboxplinthify2688581git

Manual Review

Individual user account
Yes: Follows the guidelines for individual user accounts.
No duplication
Yes: Does not Causes module duplication and/or fragmentation.
Master Branch
Yes: Follows the guidelines for master branch.
Licensing
Yes: Follows the licensing requirements.
3rd party assets/code
Yes: Follows the guidelines for 3rd party assets/code.
README.txt/README.md
Yes: Follows the guidelines for in-project documentation and/or the README Template.
Code long/complex enough for review
Yes: Follows the guidelines for project length and complexity.
Secure code
Yes: Meets the security requirements.
Coding style & Drupal API usage
[List of identified issues in no particular order. Use (*) and (+) to indicate an issue importance. Replace the text below by the issues themselves:
  1. (*) Nothing
  2. (+) Nothing
  3. Just a recommendation - 1. It would be good, if you implement hook_help in your module.

The starred items (*) are fairly big issues and warrant going back to Needs Work. Items marked with a plus sign (+) are important and should be addressed before a stable project release. The rest of the comments in the code walkthrough are recommendations.

If added, please don't remove the security tag, we keep that for statistics and to show examples of security problems.

This review uses the Project Application Review Template.

This module works for me & there are no more application blockers left. so i am moving this module to RTBC.

dman’s picture

Status: Reviewed & tested by the community » Fixed

Sorry for the well-overdue attention here. We do what we can in the time available, but the backlog does build up.

Based on the review feedback in this issue, I have good confidence that the correct process has been followed. Great constructive advice from @pankajsachdeva and @nico.knaepen has been followed.

The module is still short, but it does one thing well, and in the right way, so it's very worthwhile.
I would work on selling it a little bit more clearly in the project description. I can see what you are saying and why it's useful in a very specific case but it will be pretty hard to find for the next possible user who may be looking to solve their problem. A key factor in module maintainership is attracting and sustaining an audience of users and supporters (testers and helpers) to keep the contribution alive, so making your thing attractive and findable is a good move.

I would consider extending this for entities instead of just nodes - I can imagine cases where this functionality would be highly appropriate for 'user' entities for example.

Visual review (untested) confirms the code is clean enough.

(I got slightly confused when assigning permissions, as your username appears to be either plinthify or robdubparker depending on where I look, but let's try this anyway:)

-----

Thanks for your contribution, robdubparker!

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.

Status: Fixed » Closed (fixed)

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