Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Delegates doubt
I'm starting to grasp a little bit of the delegation or at least I think so...
the question:
so when I saw a $this->CallDelegate('whatever') in a control I can attach it to my function and get all the references of the control right?
if I attach to a delegate that his "post" that means that everything above is what I will get?
I'm still a bit confused...
for instance this part from the discussion form control:
$this->CallDelegate('PostLoadData');
// If saving a discussion
if ($this->PostBackAction == 'SaveDiscussion') {
$this->Discussion->Clear();
$this->Discussion->GetPropertiesFromForm($this->Context);
// If we are editing a discussion, the following line
// will make sure we save the proper discussion topic & message
$this->Discussion->DiscussionID = $this->EditDiscussionID;
$this->DelegateParameters['SaveDiscussion'] = &$this->Discussion;
$this->CallDelegate('PreSaveDiscussion');
$ResultDiscussion = $dm->SaveDiscussion($this->Discussion);
$this->DelegateParameters['ResultDiscussion'] = &$ResultDiscussion;
$this->CallDelegate('PostSaveDiscussion');
is the PostLoadData or the PostSaveDiscussion that delegate this chunk of code?
0
This discussion has been closed.
Comments
CallDelegate() is rather a call to any function attached to this particular object/delegate pair.
In your function you get the calling object as first parameter and then have access to all its public variables. But not to local ones, which in many places raise difficulties. That's a limitation.
You can't "replace" any processing of the calling object by your own, you can add to, possibly undoing or redoing something. That's a second limitation.
Best way to learn how it works is to see it in action.
For example, I wanted a way to auto-fill a whisper value in a discussion form:
function PreFillWhisperTo(&$DiscussionForm) { // The DiscusisonForm control fills its form fields with values in a discussion object. //Retrieve its reference to that object from its DelegateParameters: $Discussion = &$DiscussionForm->DelegateParameters['Discussion']; // Set the whisper user name to the value passed in the URL query string $Discussion->WhisperUsername = urldecode(ForceIncomingString('WhisperTo', '')); } $Context->AddToDelegate('DiscussionForm', 'DiscussionForm_PreRender', 'PreFillWhisperTo');
Would be glad to help explain if you say what you are trying to accomplish.
Theming does not break the core and is another customization tool beside delegation.
You can also acces all the calling object properties ($callingObject->property). But no access to local variables not added to DelegateParameters.
Given this code snip from DiscussionManager class:
function GetDiscussionList($RowsPerPage, $CurrentPage, $CategoryID) { $CategoryID = ForceInt($CategoryID, 0); $TotalNumberOfRecords = 0; if ($RowsPerPage > 0) { $CurrentPage = ForceInt($CurrentPage, 1); if ($CurrentPage < 1) $CurrentPage == 1; $RowsPerPage = ForceInt($RowsPerPage, 50); $FirstRecord = ($CurrentPage * $RowsPerPage) - $RowsPerPage; } $s = $this->GetDiscussionBuilder(); $this->DelegateParameters["SqlBuilder"] = &$s; $this->CallDelegate('PreGetDiscussionList'); ...
If you attach a function to the 'PreGetDiscussionList' delegate, you get the DiscussionManager object as a parameter. Then you can access this object properties. One of these is the array DelegateParameters. Trough this one you got the SqlBuilder object. But you can't acess $RowsPerPage or $CategoryID because these are local variables of the DiscussionManager object and were not added to the DelegateParameters array.
There are a few case where this is a true limitation to extension writing.
The ultimate tool in this case is to overload the class through the ObjectFactory paradigm.
I did not use this last tool yet because Mark advice to keep it as a last resort.