tedious func definitions and Dataface_Record::getLink()

A place for users and developers of the Xataface to discuss and receive support.

tedious func definitions and Dataface_Record::getLink()

Postby kevinwen » Wed Jan 06, 2010 11:59 am

1. I have a couple of delegate methods doing the same things, which override a slot that dynamically displays html code based on the user role. The signature looks like this:
block__source_attachment_1_delete_link(){
if ($role == 'GUEST') echo "hello world";
else echo "hello $role";
}
block__source_attachment_2_delete_link(){
if ($role == 'GUEST') echo "hello world";
else echo "hello $role";
}
block__source_attachment_3_delete_link(){
if ($role == 'GUEST') echo "hello world";
else echo "hello $role";
}
......
block__source_attachment_10_delete_link(){
if ($role == 'GUEST') echo "hello world";
else echo "hello $role";
}

It looks so tedious. Is there any way to define only 1 function but would call the proper one, just like the implementation in Dataface_Record::getLink()?
if ( method_exists($delegate, $fieldname."__link") ){
$methodname = $fieldname."__link";
$link = $delegate->$methodname($this);
}

2. What does Dataface_Record::getLink() return? An html link? can you give me an example?

3. Do you have documentation about the regular delegate methods, like fieldname__validate(), after_action_edit(), and beforeUpdate(). I don't know how many and what parameters should be passed into these functions.
kevinwen
 
Posts: 109
Joined: Mon Dec 28, 2009 3:44 pm

Re: tedious func definitions and Dataface_Record::getLink()

Postby shannah » Wed Jan 06, 2010 12:05 pm

No perfect solution for the tediousness, but one improvement you could make is to create a single function that does what you want, that is called from all of the different blocks. That way if you want to make changes to the functionality you only need to change it in one place.

As far as documentation goes, there are some examples of these functions smattered over the forum and the wiki, but I don't have links to them right now.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: tedious func definitions and Dataface_Record::getLink()

Postby kevinwen » Wed Jan 06, 2010 2:07 pm

OK, that's a good idea.

What parameters are available for the block__ function? $record, $value, $params, etc?
kevinwen
 
Posts: 109
Joined: Mon Dec 28, 2009 3:44 pm

Re: tedious func definitions and Dataface_Record::getLink()

Postby shannah » Wed Jan 06, 2010 4:06 pm

Block functions take a single associative array as a parameter. The keys that are available in this array depend on the block. A common key that is frequently used is 'record', but not always. You might want to output the keys of this array just to test and see.

e.g.
Code: Select all
function block__myblock($params=array()){
    print_r(array_keys($params));
}


These parameters correspond with the parameters that are passed to the block/slot tag in the template.

e.g.
Code: Select all
{block name="myblock" isbn="18888946740"}


You could access as

Code: Select all
function block__myblock($params=array()){
    echo $params['isbn'];
}
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 18 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved