I think that making the phone numbertype field in phone-7.x-2.x be based on the hcard types is best in the long term. For reference, those types are defined to be (http://microformats.org/wiki/hcard):
- tel type: VOICE, home, msg, work, pref, fax, cell, video, pager, bbs, modem, car, isdn, pcs
The types are not case-sensitive; voice is capitalized to indicate that it's the default value. Also note that this topic was started by the cck_phone issue #849006: Phone types (home, work, mobile, fax, etc) support.

My thought was that the numbertype value stored in the database should be the hcard type, but we can allow those values to be "translated" into more user-friendly terms (e.g., "Mobile" instead of "Cell", or "Preferred" instead of "Pref") everywhere the value is actually displayed to users. The user-friendly terms would be a setting that can be customized. Also, the settings should allow only a subset of the hcard types to be used on a given site, since several are obscure/confusing.

The main advantage of tying our numbertype to the hcard types is that it will allow us (eventually) to take advantage of the hcard standard. If data imported via feeds/migration/etc. is hcard-compliant we can automatically pull in the numbertype -- otherwise we're very unlikely to be able to import any numbertype information. It will also allow us to make the phone number output hcard-compliant.

I think the hcard list of types is pretty comprehensive, so I don't think we're being overly restrictive by limiting ourselves to those options. The one tweak that might be worthwhile would be also allowing an "other" type (which would then simply be ignored when doing hcard-compliant output).

A secondary advantage is that having a fixed list of possible database values effectively solves problems that could happen if the allowed_values setting for the numbertype field is altered after it already contains data. Any no-longer allowed values can be kept in the database, but are ignored on display.

Assuming any of what I've proposed so far makes sense, there's one more issue related to hcard types. Types in hcard are defined to be multivalued -- so for a single phone number you can specify all of "Work", "Voice", and "Preferred". I doubt that most phone module users will want to enable multivalued types, but I think the module should have the ability to support it. Making the numbertype select box allow multiple values is easy. I'd then envision that the database would allow the numbertype to be set to "work,voice,pref" -- I think that's the simplest option.

Although full hcard support probably isn't important enough to be a priority right now, I think setting up the numbertype field using hcard types from the very beginning will prevent refactoring headaches later.

Comments

cdale’s picture

Whilst I don't mind having hCard support, I actually have need for much more varied custom "types", hence the current custom option.

For example, I have need for the following options, not all of which fit into the hCard list above:

Direct Line
Main Switch
Other number
Fax
Mobile
Home

Now, Fax, Mobile, and home can probably match up with fax, cell and home from the hCard standard. Other number can probably be voice, direct line can *maybe* be work, but then I'd have no where to put main switch.

Whilst I don't mind supporting the hCard standard, I have a very strong need for being able to specify custom labels *outside* of translation. We actually have some other code that makes vcards from data in our database, and both Direct line and Main switch map to the "work" type.

I don't mind hCard being the default, but I need to be able to specify other lists of items. Also, if we're going to support hCard fully, then it would be a complete *must* to allow multiple selections. i.e. my Mobile phone is also my preferred phone.

Personally I don't see the allowed values list needing alteration to be a problem. It can be changed as often as people like. The only time they cannot change something, is when they remove a key, for which there is already data. They can still change the label for this key, and they can also write a query to "fix" up any fields with this key in the database. So I don't see any issues with the allowed values list. But I do have a problem with only allowing a fixed list of number type options. I need to be able to customise this beyond the labels.

cweagans’s picture

How would you feel about having the default behavior a list of hcard compliant types, then sticking a drupal_alter() after that list? That is, hcard will be the default behavior, and if you want to alter it, you have to write some code. Is that a reasonable solution?

cdale’s picture

Yeah. An alter hook will work. That would allow me to provide a custom module that could keep phone working like it is now fundamentally. Let me code something up and post for review. Most of the framework is there, so shouldn't take long.

Question: Are we happy to allow people to deselect a type that is potentially in use, and simply not display a type output for them, or is an actual warning required?

cweagans’s picture

I would much prefer that it's like the field settings...once there's data in the field, you can't change it.

Nephele’s picture

While I don't want to make the available types overly restrictive, allowing the keys to be fully customizable seems more likely to cause problems than help most admins. I'd imagine that some admins who don't know about hcard might think that they should make the keys and the labels the same. Or would want to translate the keys on non-English sites.

So, if doing an alter hook works for you, that sounds like a good option, assuming that we don't think more extensive type options will be a common feature request.

My first guess is that silently ignoring a deselected type makes sense. If an admin deselects "pager" for example, I don't think he's saying that any existing pager numbers are invalid/problematic, but just that he doesn't really care about the fact that they're pagers. On the other hand, this discussion has already reminded me that different sites' requirements can vary widely...

cdale’s picture

As we're Probably going to want to support custom labels, we can just allow them to enter an empty label, which can mean "don't output", or, a formatter setting of some sort I think.

cdale’s picture

Custom labels: Site wide config? Or per field?

Nephele’s picture

@cweagans: My concern with preventing changes once there's data in the field is that I can imagine valid reasons why admins might want to make harmless changes. For example, what if an admin starts by using "Cell" as the label, gets feedback from users, and then wants to change the label to "Mobile"? Or starts by thinking that his users will never need to provide Pager numbers, and then it becomes a requirement six months later?

@cdale: I'd like to see the custom labels as an instance setting for maximum flexibility. I suppose that does mean that if a site has lots of different phone fields, admins might get annoyed by having to make tweaks in a dozen different places instead of one... but how often is that likely to come up?

cdale’s picture

When we talk about the type, we have the key that is stored in the DB, and the label. I think the keys are fixed, and tied to the field data. The labels themselves can be customised in the instance data I think. At least that was my impression.

cweagans’s picture

Sure, those reasons exist. But the common behavior among fields is that allowed values can't be changed if there's data in the field. If they want to change the allowed values, it can be done through custom queries to move the data around (create the new field, insert all the old values into the new field (substituting where needed), then delete the old field). I think going with the hcard spec is the correct path forward here, and if anyone wants to do anything advanced, an alter hook is not difficult to write (and custom labels can be provided by some submodule in the future if it's a common feature request).

Also, if the values are represented as an associative array with the keys being the hcard names and the values being the user-facing text, changing the label is not difficult with the alter hook (and it doesn't require changing the field configuration).

And, of course, this can all be talked about in the documentation.

cdale’s picture

If we're going to make all of that require an alter hook, then we should agree on the default labels. :)

This is the current list that I have.


$values = array(
    'work' => t('Work'),
    'home' => t('Home'),
    'cell' => t('Mobile'),
    'pref' => t('Preferred'),
    'car' => t('Car'),
    'voice' => t('Voice'),
    'fax' => t('Fax'),
    'msg' => t('Answering machine'),
    'bbs' => t('BBS (Bulletin board)'),
    'isdn' => t('ISDN'),
    'modem' => t('Modem'),
    'pager' => t('Pager'),
    'video' => t('Video conferencing'),
    'pcs' => t('Personal comm. services'),
    // Note that other is not actually a hcard type,
    // but it's being used as the text equivalent of NULL.
    '' => t('Other'),
  );

cdale’s picture

On that note, I've committed a initial run at this in a separate branch. You can see the diff at http://drupalcode.org/sandbox/cdale/1925578.git/commitdiff/refs/heads/hc...

Comments thoughts and feedback please. :)

cdale’s picture

I'm having second thoughts about setting the key of "Other" as the empty string. Initially I thought it would be a good default in the event nothing was entered, but now I'm thinking that other should be another key in its own right, with another "empty" option. The number type doesn't really have a concept of required/not required, so perhaps adding in a faux empty option to allow this field to be set to nothing if people choose might be an idea.

Thoughts?

Nephele’s picture

I agree with having "other" as an explicit key -- which can then have a label that is displayed with a phone number, unlike empty values. And then with using the #empty_option property to give some type of '- None -' option.

cdale’s picture

Ok, other as explicit it is. I'm done for today, so if you haven't done it by then, I'll take a look at patching that tomorrow, and possibly merging the hcard branch back into master if we're happy with it. Again, unless you beat me to it. :)

cdale’s picture

Status: Active » Needs review

Only just got back to this now.

I've just merged in the hcard branch, with an actual 'other' option. So that's now in master. I'm not sure if that makes this needs review or fixed? I guess it will be fixed when it's merged into 7.x-2.x.

cweagans’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.