WebHare community

DescribeWHFSRegisterSlot in internal whlib

I noticed that DescribeWHFSRegisterSlot is in an internal lib. Is there a public way to get information about a register slot?

It would be nice for constructions like this:

OBJECT site := OpenSite(LookupInWHFSRegister("module:slot"));
IF(NOT ObjectExists(site))
  RECORD slotinfo := DescribeWHFSRegisterSlot("module:slot");
  STRING sitename := Tokenize(slotinfo.initialvalue, "::")[1];
  OBJECT siteroot := OpenWHFSRootObject()->EnsureFolder([ name := sitename ]);
  site := CreateSiteFromFolder(siteroot->id);

This way you don’t have to repeat the site name in code.

Maybe /system/lib/whfs.whlib can export DescribeWHFSRegisterSlot as well?

Which site would it return? The one from initialvalue, fallback, or the actual current value ?

Uhm, all of them? :slight_smile:

<registerslot name="gesprekkenapp_site" title="Carmel College Gesprekkenapp site" initialvalue="site::Gesprekkenapp" type="site" />

I expect these attributes returned by DescribeWHFSRegisterSlot. So, to answer the question: in this case I need the initialvalue.

For the “actual current value”, we use LookupInWHFSRegister right?

Didn’t even know that fallback existed, but I can imagine DescribeWHFSRegisterSlot returns that as well. Which it does.

And maybe making DescribeWHFSRegisterSlot public isn’t the way to go, but it would still be nice to get that initialvalue some way.

I’m not sure why you wouldn’t just create a registerslot that points to the site…

The whole point of registerslots is to avoid hardcoding a site name so that a site can be renamed without immediately breaking all references to it.

Initialvalue is there so that if you did hardcode the site name earlier, you have a transition path to using a register slot. Otherwise you’d have to create a startup script to set the initial value for the register slot during the module push where you switch from a hardcoded value to a register slot.

So basically: registerslot avoids having to hardcode a path, and initialvalue gives the initial value to move away from a hardcoded path. So that’s why we wouldn’t ever want to expose the initialvalue - registerslot is supposed to allow you to change that path.

If you’re going to use a hardcoded value, why use registerslot at all ? You could just put it in a registrykey or straight into a variable.

(note that similarly, there’s no API to access the initialvalue of a registrykey - we’d expect you to use the current value. and registerslots aren’t much more than a registry for pointing to whfs objects)

Hmm I’m afraid I haven’t made my intentions clear…

Without the ability to get the initialvalue from the register slot, I have to code like this:

<registerslot name="name"
              title="My site"
              type="site" />


OBJECT site := OpenSite(LookupInWHFSRegister("module:slot"));
IF(NOT ObjectExists(site))
  OBJECT siteroot := OpenWHFSRootObject()->EnsureFolder([ name := "sitename" ]);
  site := CreateSiteFromFolder(siteroot->id);

So I have the name of the site in initialvalue AND as a hardcoded string in EnsureFolder, because I can’t get it from anywhere besides the moduledefinition (eg DescribeWHFSRegisterSlot).

My thinking was: if I set the name already in registerslot, why can’t I get that name from there, removing the need to save the site name in a string, global string, registry key or whatever.

ah okay. it’s about startup code. that makes more sense.

If you throw in a PR with a bit of documentation about the function, I think we can apply it. Just be sure to throw in the topic/public/loadlib keys:

/** @short Look up a WHFS register entry
    @param slotfullname Name of the slot
    @return Id of the file/folder in the slot
    @topic sitedev/whfs
    @loadlib mod::system/lib/whfs.whlib