Accessing Custom Fields with GalleryEmbed

pgraber

Joined: 2006-11-26
Posts: 2
Posted: Mon, 2006-11-27 02:35

I'm using Drupal 4.7. Gallery 2 is embedded perfectly.

On my home page, I'm utilzing GalleryEmbed to pull some random images from random albums. I'm seeking to be able to all access the two custom fields each album contains. Have searched and searched for direction on this to no avail.

I'm assuming I work with CustomFieldHelper.class somehow, but am looking for insight.

Thanks.

_PTG

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2006-11-27 12:58

too bad the existing customfield interface (modules/customfield/classes) doesn't include the function fetchFieldValues() which is defined in the helper.
why? because accessing an internal helper is error-prone when you upgrade galery since there's no guarantee that the helper won't be moved / deleted / ...

2 options:
1. see function getImageBlock() from modules/core/classes/GalleryEmbed.class and code the same for the customfield (fetching the block template).
this new function can be in your own code, doesn't have to be in GalleryEmbed.
2. add fetchFieldValues() to the customfield interface and then use

list ($ret, $customFieldInterface) = GalleryCoreApi::newFactoryInstance('CustomFieldInterface_1_0', 'CustomFieldHelper');
if ($ret) {
   die($ret->getAsText());
}
if (!$customFieldInterface) {
    die('customfields are not available (e.g. module not active)');
}
list ($ret, ...) = $customFieldInterface->fetchFieldValues($itemIds);

of course you could access the helper directly, but:
- you'd first have to check if the customfield module is active
- the helper class is not guaranteed to be there.

you can file a feature request to include a getter / fetch method to the customfields interface.

 
pgraber

Joined: 2006-11-26
Posts: 2
Posted: Mon, 2007-08-06 20:40

Valiant -

If I were using the 'Description' field, would it make this easier? Your instructions are a bit over my head.