It would probably make a lot of sense to make content types their own token type. For example, we have the same thing with core in D7 with vocabularies & tokens. Although the kicker may be that node types are not their own entities in D7.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Status: Active » Needs review
FileSize
8.69 KB
Dave Reid’s picture

Dave Reid’s picture

Status: Needs review » Fixed

Committed #2 to CVS!
http://drupal.org/cvs?commit=450512

The [node:type] and [node:type-name] tokens are now deprecated and [node:content-type:machine-name] and [node:content-type] should be used respectively.

fago’s picture

Status: Fixed » Active
+  $info['tokens']['node']['content-type'] = array(
+    'name' => t('Content type'),
+    'description' => t('The content type of the node.'),
+    'type' => 'content-type',
+  );

The token name "node:content-type" duplicates the context of 'node'. We don't have node:content-id, node:content-author and so on either, thus it should be just "node:type".

Then I think the actual token type name 'content-type' is problematic, because it doesn't comply with the providing module's namespace - node. Yes, we really should namespace our data types too. I know core conflicts that with 'vocabulary' and 'term' too, which is in particular odd as this is inconsistent with the entity types being 'taxonomy_term', but it's probably too late to fix that in d7. But at least, let's avoid introducing more such issues.
Thus, as type names need not be human readable, I guess it should be just "node_type".

Dave Reid’s picture

Status: Active » Postponed (maintainer needs more info)

Duplicates it how? We can't easily change it since [node:type] is already provided by core, and it's also the machine name, rather than display name whereas [node:content-type] is the display name (as chained tokens should be) and [node:content-type:machine-name] is well, the machine name. The token module 'disables' the [node:type] and [node:type-name] tokens from the UI, unless you might be using entity_metatags...

Dave Reid’s picture

So maybe I missed what you're trying to say. Should it be renamed to [node:node-type] (for reasons stated above we cannot use [node:type] as the chained token)?

fago’s picture

@duplicate:
'content' duplicates the 'node' context, 'type' would just suffices here. No reason to prepend 'node' or 'content' to each token of it. E.g. we use node:author, not node:content-author.

But I see that it isn't optimal that core already implements [node:type] and returns the machine name, but still it makes sense and the user can get the human readable type name by using [node:type:name]. Also, I don't think it's optimal that it is [node:type] usually, and then suddenly if the token module is enabled, it is [node:content-type]. Let's try to avoid having too much different token-names for the same thing depending on the modules being enabled, as this helps users to remember the names.

@name-space issue:
While the issue above is about the name of the actual token, the name-space issue is about the name of the introduced data-type. As said above, data types should be properly prefixed too and I don't think they should be human readable, thus I guess we should use underscores instead of dashes. In particular we should start making use of the same data type names as in hook_entity_info(), what again means using underscores.

fago’s picture

Status: Postponed (maintainer needs more info) » Active
Dave Reid’s picture

Status: Active » Fixed

'content' duplicates the 'node' context, 'type' would just suffices here. No reason to prepend 'node' or 'content' to each token of it. E.g. we use node:author, not node:content-author.

I don't think you quite get it. Content type is the item. It's the node's content type. The node's author. Not the node's content author. So your example is flawed.

We can't suddenly switch to underscores when the core token API has already set the standard for dashes, sorry. Please file a new issue with a patch if you feel this needs a follow-up as the tokens have already been committed.

fago’s picture

Status: Fixed » Active

>The node's author. Not the node's content author.
Aehm, where's the difference? Content is often used synonymously with 'node', e.g. "content type" means "node type". Having node:node-type duplicates the node context.

>We can't suddenly switch to underscores when the core token API has already set the standard for dashes, sorry.
Where has the core token API used dashes for data-type names?

Dave Reid’s picture

Aehm, where's the difference? Content is often used synonymously with 'node', e.g. "content type" means "node type". Having node:node-type duplicates the node context.

Yes, if you use 'node type' it duplicates the context. But we're using 'content-type' currently. I still don't see a problem with the current implementation.

Where has the core token API used dashes for data-type names?

There are no core token types that are more than one word. I suspect that if I asked eaton that if we did, it would use dashes, since *every single* token in core uses dashes in-between words (and the unfortunate naming of the 'term' token type would probably be 'taxonomy-term' to at least mostly match the corresponding entity type).

fago’s picture

>Yes, if you use 'node type' it duplicates the context. But we're using 'content-type' currently.
? Content is synonymously used to 'node' for the term "content-type". Coming back to the (valid) content author analogy: We don't use [node:content-author] either, we use [node:author] - nor do we prefix any other node-token with 'content'. The same way we should use [node:type].

@dashes:
It's just dumb using the same type names, but going with dashes instead of underscores - have fun converting them for nothing. Though it's still better than completely different type names.

Dave Reid’s picture

Status: Active » Fixed

So again, I've tried to explain the reasoning behind the names here since we can't conflict with existing core tokens, and to give the user a good context from the token name. I'll repeat that please file a new issue with a patch if you feel this needs a follow-up as the tokens have already been committed.

Status: Fixed » Closed (fixed)

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