Jump to content

Hooking InputfieldText Render Method (multi-language)


update AG
 Share

Recommended Posts

I am trying to hook into text inputfields to add additional markup to it. But it only adds the markup for the default language tab. How can I achieve, that it also adds to the other language tabs?

public function init() {
        if ($this->initSettings()) {
            $this->addHookAfter("InputfieldText::render", $this, "markAllowedFields");
        }

        parent::init();
}

public function markAllowedFields($event) {
        // Get the object the event occurred on, if needed
        $InputfieldText = $event->object;

        $allowedFieldTypes = [
            'FieldtypePageTitle',
            'FieldtypePageTitleLanguage',
            'FieldtypeText',
            'FieldtypeTextarea',
            'FieldtypeTextLanguage',
            'FieldtypeTextareaLanguage',
        ];

        $currentPage = $this->wire('pages')->get($this->wire('input')->get->id);

        $allowedFields = [];

        if($currentPage && $currentPage->id) {
            foreach($currentPage->template->fields as $field) {
                if($field->type->name && in_array($field->type->name, $allowedFieldTypes)) {
                    $allowedFields[] = $field->name;
                }
            }
        }

        $return = $event->return;

        if(in_array($InputfieldText->name, $allowedFields)) {
            $return .= '<div class="gpt-wire-helper-container"><a href="#" class="gpt-wire-helper-link" >Do Something</a></div>';
        }

        $event->return = $return;
}

1930442073_Bildschirmfoto2024-01-03um16_38_44.thumb.png.7627f96a58e9bb08275ad04e8f544a60.png1608333370_Bildschirmfoto2024-01-03um16_38_27.thumb.png.37dad3ec0de90e469fd3a5c96f5b2bce.png
KR
Orkun

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