Jump to content

Limit field to a specific page or branch of tree


adrian
 Share

Recommended Posts

Hi everyone!

Just curious if anyone has developed a solution for this. I feel like it has been mentioned somewhere before, but I am not finding anything.

I have a site with a complex, but repetitive tree (hence my various branch restriction modules), and I am finding myself wanting the ability to add a field but only have it available on a specific branch. I obviously don't want a separate template for this one field so I am thinking of creating something to make this possible, but just want to make sure I am not reinventing the wheel. It might be best to just go with a simple hook that is specific to this scenario, but maybe this is also an opportunity to build something that makes it easier to manage these situations through the field's settings. At first thought I am thinking of a new "Branch Restrictions" tab (between Access and Advanced) on the field settings page that lets you limit what pages it will appear on.

Any thoughts?

Link to comment
Share on other sites

Hey @Robin S - obviously I don't know what approach you have taken so far, but I just had another idea for how this could be implemented. Perhaps under the field's Input > Visibility > ShowIf settings, there could be new options: 1) a selector text field, 2) a custom PHP code textarea. This would be a little like the Input > Selectable Pages options for Page fields.

Anyway, I think this could be really powerful - if the currently edited page doesn't match the selector, or the custom php doesn't return true, the field would be hidden completely from the page editor for that page.

What do you think ?

  • Like 2
Link to comment
Share on other sites

Hi Adrian,

My Custom Inputfield Dependencies module is released and the forum thread is here. Not a very precise module name - I struggled with it.

2 hours ago, adrian said:

Perhaps under the field's Input > Visibility > ShowIf settings, there could be new options: 1) a selector text field, 2) a custom PHP code textarea. This would be a little like the Input > Selectable Pages options for Page fields.

You'll see that the effect of my module is similar to what you propose above, but using what is available in the core (and Hanna Code) now. But I think it would be cool to have new features added to the core to allow this directly in field settings like you propose, so if you want to make a Github request I'll gladly add my +1.

Hopefully you can use Custom Inputfield Dependencies for what you had in mind in this thread's original post.

  • Like 1
Link to comment
Share on other sites

I haven't tested your new module yet - I am sure it will work great :)

But back to the thoughts from my last post, I was thinking of hooking into: 

Inputfield::getConfigInputfields

and adding the selector and custom php options there.

Anyway, when I have a minute I'll try your module and also take a look at that hook and see if I can implement it that way as well.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...