Jump to content

How to get the value of a config field that was added by a hook event


---
 Share

Recommended Posts

I've added a hook after the '"ProcessPageEdit::buildFormContent" event.

I've added a new config option to the language settings:

public function beforeAdminProcessPageEditBuildFormContent (HookEvent $event)
    {
        $editPage = $this->getPage(wire('input')->get('id'));

        if ($editPage->template->name == 'language') { // only add field when editing language page
            $field = wire('modules')->get('InputfieldText');

            $field->attr('name+id', 'locale');
            $field->label = __('Locale');

            $event->return->insertAfter($field, $event->return->getChildByName('title'));
        }
    }

I've also created a field (Setup > Fields > Add new) which I've also named 'locale'.

The field is displayed, but the value isn't saved when I click the save button. How do I make sure the input of the field is saved as well? And how can I access the stored value once it's saved?

Link to comment
Share on other sites

Why do you need a hook for this if you already have a "physical" locale field?

If you need it to be visible only on the Languages field, edit the field Visibility (Input tab, Show this field only if...) and use something like this:

id=1022|1023

Where 1022, 1023, ... are the page IDs of your language pages. Unfortunately using has_parent or parent.id are not working.

Link to comment
Share on other sites

2 minutes ago, tpr said:

Why do you need a hook for this if you already have a "physical" locale field?

If you need it to be visible only on the Languages field, edit the field Visibility (Input tab, Show this field only if...) and use something like this:


id=1022|1023

Where 1022, 1023, ... are the page IDs of your language pages. Unfortunately using has_parent or parent.id are not working.

Well I can't add a field to the languages config page as far as I know.

I want the field to be visible when editing a language page in the admin section:

Screenshot

When I edit "default", "de" etc, that's where I want an additional field and the only way I could find that was working and didn't require editing core files was using a hook. If you know a better way to add a field on that place, please let me know.

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

×
×
  • Create New...