Jump to content

[solved] Get field from inputfield render hook


Robin S
 Share

Recommended Posts

I am hooking an inputfield render() method, and I'm hoping to be able to get the $field object that this inputfield is for. I can see the $field object in Tracy but cannot access that directly in the hook. Is there a trick I'm missing?

More broadly, my objective is to match the inputfield to its field when the inputfield is rendered inside a Repeater. When the inputfield isn't inside a repeater you can easily work out the field because the name attribute of the inputfield is the same as the field name. But when inside a repeater the name attribute has a repeater suffix appended, e.g. "my_field_repeater1125". The integer at the end is a page ID so that can potentially be any length, and I don't want to do something like trim the name from "_repeater" onwards as someone could conceivably use the string "_repeater" in their field name.

Any suggestions?

Link to comment
Share on other sites

Right after posting that I started thinking clearly...

$inputfield = $event->object;
$field = $this->fields->get($inputfield->name);
if(!$field) {
    $name = substr($inputfield->name, 0, strpos($inputfield->name, "_repeater"));
    $field = $this->fields->get($name);
}

 

  • Like 3
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...