Jump to content

Hooking The View Function


Christian
 Share

Recommended Posts

Hi! Is there anyone here already try to modify the function of View function? I tried to modify it using Inputfield::render when I assign new value, nothing happen.

Also, I tried to use Page::render to have a different button but I cannot get the current editable field value of the page.

Link to comment
Share on other sites

Ok. I already do this. What I do is this:

    public function init() {
        // add before-hook to the inputfield render method
        $this->addHookBefore("Inputfield::render", $this, "getPreviewURLField");

		$this->pages->addHookAfter('Page::render', $this, 'hookFormRendering');

    }

	public function getPreviewURLField(HookEvent $event) {
        $field = $event->object;

        if( $field->name == 'site_preview_url' ) {
        	$this->url = $field->value;
        }
    }

 	public function hookFormRendering(HookEvent $event) {
		// GET PAGE DATA 
		$url = $this->url;
		$page = $event->object; 

		if ( $url ) {
			$event->return = str_replace('<form id="ProcessPageEdit"', '<a href="' . $url . '" target="_blank">Go to site</a><form id="ProcessPageEdit"', $event->return);
		}
	}

I have a follow question. Is this ideal :)

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