1

I have a specific node type that I want to show/hide different fields in the page layout for both the node form and when viewing the node.

For various reasons I don't want to have to create a new/separate Node type for each. Not sure how best to achieve this in Drupal 7?

There are actually two content types involved here. 'Open Calls' and 'Projects'

I have an idea submission system built in D7. Users login and browse through available 'Open Calls' for projects.

Each call has a link to 'Apply Now'. This link takes users to the new node creation for a 'Project'.

Each 'Project' has an entity reference field that is required that links the Project to the Open Call. This field is auto populated when they click the Apply Now button.

Ideally, I would be able to specify in the Open Call (rather than the project) what kind of project page layout they see when clicking the Apply Now link.

I want to be able to post Open Calls for slightly different kinds of projects. For example an Open Call for artworks (paintings etc.), or alternatively an Open Call for performances.

Clicking apply now on each of these should take the user to the New Project node creation screen with different fields for artworks / performances. (Some fields will appear on both).

  • Where or how do you plan to set the sub-type? Is it some checkbox? A taxonomy term? – leymannx Oct 16 '18 at 12:12
  • @lymanx See updated description above for a better explanation of how this should work. – Danny Browne Oct 16 '18 at 12:24
  • OK then make use of Form API states via hook_form_alter for the node form, to display certain fields only if a certain select value has been chosen. Use that value then via hook_preprocess_node to set certain other field's access to false. You need to try to come up with something to show us so we can guide you. Otherwise this question is just too broad. – leymannx Oct 16 '18 at 12:29
  • @leymannx sorry... updated now. – Danny Browne Oct 16 '18 at 12:33
3

Take a look at the Conditional Fields module. You could make some fields dependent on one checkbox selection and other fields dependent on a second checkbox selection.

Define dependencies between fields based on their states and values.

Conditional Fields for Drupal 7 is an user interface to the new States API, plus the ability to modify fields appearance and behavior on certain conditions when viewing content.

Description

Conditional Fields allows you to manage sets of dependencies between fields. When a field is “dependent”, it will only be available for editing and displayed if the state of the “dependee” field matches the right condition. When editing a node (or any other entity type that supports fields, like users and categories), the dependent fields are dynamically modified with the States API.

A simple use case would be defining a custom “Article teaser" field that is shown only if a "Has teaser" checkbox is checked, but much more complex options are available.

  • This looks promising. I now have my apply now button (a computed field) passing two arguments in the url to the new project page. Apply now URL is now as follows: /node/add/project?field_open_call=5882&field_project_type=Performance The first param passes and sets the value for the entity reference field mentioned above to link the project to the Open Call. Though currently it does nothing, the second param is intended to control the project page fields displayed. Is Conditional Fields or Form API states the best way for me to achieve this? – Danny Browne Oct 16 '18 at 13:39
0

Use Field Permissions module

The Field Permissions module allows site administrators to set field-level permissions to edit, view and create fields on any entity.

enter image description here

  • Thanks but this won't work. Users should always have permission to edit and view the fields. I simply want to hide them in certain contexts. – Danny Browne Oct 16 '18 at 12:09
  • Is Drupal already aware of and able to react to these contexts? If not you'll probably have to code them yourself – Clive Oct 16 '18 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.