Hook?

Discuss PivotX 2.0.x here. Non-PivotX related discussions go in The Drain.

Hook?

Postby Gooly » Tue Nov 24, 2009 7:01 pm

In my Pivot backend I found the hook extensions. Years ago, when I was working with Pivot 1.24 I think I saw the term 'Hook' passing by every once in a while, but I didn't take notice of it. However now I want to know more about it and searching on the internet brings me to a Steven Spielberg movie from 1991. Now what has this movie with PivotX to do?
I'm joking of course. But when I think of a hook, I picture some kind of enabler, a hook where you can 'hang' functionalities on. However even this is a very abstract picture. So my question is simple: What is a hook?
That's the trouble with reality,
it's taken far too seriously
User avatar
Gooly
 
Posts: 77
Joined: Thu Nov 19, 2009 5:52 pm
Location: Lat 52° 4' 11.4874" Lon 4° 17' 28.001"

Re: Hook?

Postby Bob » Tue Nov 24, 2009 8:06 pm

That's exactly it. I'm still writing the docs, so i can't refer you to those yet. ;-)

A hook is something you attach your own piece of code to, so it basically allows extensions to stuff, at the place they need to do it.

For example, let's look at the code for the gallery hook, in extensions/gallery/hook_gallery.php

Code: Select all
$this->addHook(
    'in_pivotx_template',
    'entry-keywords-before',
    array('callback' => 'galleryFieldExtension' )
    );


This tells PivotX to add a hook inside the PivotX templates, at 'entry-keywords-before', and to call the function galleryFieldExtension() when it gets there.

If you look a bit lower in that file, you'll see the actual function, with the code it generates, that is inserted in the 'edit page' template when the gallery extension is enabled.
Bob
Lead Developer
 
Posts: 1374
Joined: Tue Nov 20, 2007 11:16 pm

Re: Hook?

Postby Gooly » Wed Nov 25, 2009 7:00 pm

Thanks! It's slowly getting clear now, especially the hook_gallery.php example helped a lot. I needed to study the example twice, but I'm getting the point now :) After activating the gallery hook I have no gallery on my website, but I can create one if I want: an 'enabler'.
That's the trouble with reality,
it's taken far too seriously
User avatar
Gooly
 
Posts: 77
Joined: Thu Nov 19, 2009 5:52 pm
Location: Lat 52° 4' 11.4874" Lon 4° 17' 28.001"


Return to 2.x Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron