This will depend on #1008166: Actions should be a module, otherwise system module would depend on token module.

system.token.inc and the token sections in system.test could move to the new module.

The only two places in core that actually use token_replace(), rather than implementing hook_token(), are user module (when sending e-mails), and the hopefully soon to be actions module (also when sending e-mails).

It would therefore makes a tonne of sense to move it into a module, add it as a dependency. I want to look at splitting user module into the absolute basics to have users, and another module that deals with account management etc. so that the latter could be disabled on single user sites (and lazy loaded if we can implement module lazy loading).

Comments

Anonymous’s picture

subscribe.

catch’s picture

Issue tags: +Framework Initiative

Tagging.

catch’s picture

Tagging.

sun’s picture

Issue tags: +API clean-up

.

Dave Reid’s picture

Hrm, the token API benefits contrib *greatly* by being available by default in core and not being an optional dependency, so I have to disagree with this for now.

Anonymous’s picture

Why can't contrib modules just do requirements[] = token ?

catch’s picture

Also the decision to make token optional is really a separate one from making it a module in the first place, without refactoring it will have to be required, since both user and system depend on it anyway.

cweagans’s picture

I think token.inc provides great benefit, but I think we should seriously consider making it a module. It's just that much less code that has to be executed on every page load. If I have a contrib module that needs it, it will get turned on automatically for me.

@davereid, is there any major problem with making contrib modules declare 'dependencies[] = token'?

Dave Reid’s picture

Because now http://drupal.org/project/token is screwed out of being the testbed for moving code into core.

sun’s picture

@Dave Reid: Nothing really to worry about, you can keep the project namespace, just simply rename the contained module to token_ui.

Dave Reid’s picture

It's not just a token UI - it's a testing ground for tokens that should have been in core. And hopefully we'll have moved the UI part into core for D8.

cweagans’s picture

Okay, so can we get the rest of token moved into core, add the tokens that should have been available, and then take care of this issue? Would that be acceptable, Dave?

eaton’s picture

I think token.inc provides great benefit, but I think we should seriously consider making it a module. It's just that much less code that has to be executed on every page load. If I have a contrib module that needs it, it will get turned on automatically for me.

Just to put things in perspective, token.inc includes 86 lines of PHP code: everything else is PHPDoc.

The only bulky code lives in the token implementation files scattered across all of the core modules that provide tokens, but that code exists in separate .inc files that are only loaded when required. We'd basically be trading a more complex dependency chain for 86 lines of PHP in an area that has no UI or interaction complexities. Just maintaining a pre-populated list of country names is in iso.inc is, literally, several times larger.

Okay, so can we get the rest of token moved into core, add the tokens that should have been available, and then take care of this issue? Would that be acceptable, Dave?

The problem isn't that a couple tokens got left out. It's that when complex features get added to core, figuring out how to best implement token support for them takes time and architectural (not just development) resources. Unless "full, flexible, extensible token support has been added for all entities, data types, and so on" can be made into a release blocker for new versions of Drupal, there will always need to be some sort of 'token module in contrib.' It shouldn't be a show stopper if moving the .inc to a module is the right decision, but it's not just a matter of getting a couple of 'missed tokens' in.

catch’s picture

Hmm, I think if an include file only depends on the module system (i.e. invokes hooks and alters), but does not depend on system module implementing hooks on its behalf, then it probably makes sense to keep those as includes like you say.

There is a fundamental dependency still on hooks (via the module system's dependency on system module), but if we can resolve that (likely via CMI), then things that only depend on having a module system in place can have a clean dependency chain too.

I had a look to see how much token is represented in system module, since that's usually a good sign that something has gone wrong:
http://api.drupal.org/api/drupal/modules--system--system.module/function...

I really, really hope we can ship Drupal 8 without hook_hook_info() so this doesn't count for the purposes of token.inc and is directly related to module system circular dependencies.

Then there is also system.tokens.inc, but many of the tokens that are in there are implemented on behalf of other stuff that is misplaced, and none of them are needed to have a token replacement API.

So this might be one case we want to mark won't fix.

eaton’s picture

I had a look to see how much token is represented in system module, since that's usually a good sign that something has gone wrong:

Yeah, that strange stuff in hook_hook_info is a direct legacy of the registry related stuff. Originally, token had a several line helper function that looked for .token.inc files in each module's directory, very similar to what Views does. That was made unnecessary by the registry, but then the registry got pulled out and a special token-only mechanism for locating .token.inc files was determined to be too weird.

As has been mentioned in the main framework metathread, the inability to effectively make things 'optionally loaded' without putting them in classes or putting them in modules is the underlying problem. Token is represented in system.module because 'optionally loading things' got pushed off onto yet another hook, and hooks require modules.

Then there is also system.tokens.inc, but many of the tokens that are in there are implemented on behalf of other stuff that is misplaced, and none of them are needed to have a token replacement API.

Yeah; there are a few things like date handling and site information that -- due to the nature of the hook system -- have to live in some module but are not clearly linked to any single module's functionality.

sun’s picture

Status: Active » Postponed

Discussed with @catch in IRC that we first want/need to do a full run-down on all /includes files to come up with a clear idea and rules for what can be or should be an include and what shouldn't. #1224666: [meta] Unofficial Drupal 8 Framework initiative only covers the high-level ideas around that, but for issues like this, we need a low-level consensus.

Thus, marking this particular issue as postponed until that consensus has been reached.

Lars Toomre’s picture

Then there is also system.tokens.inc, but many of the tokens that are in there are implemented on behalf of other stuff that is misplaced, and none of them are needed to have a token replacement API.

This quotes makes me wonder if makes sense to use the namespace tokens (note plural) in core and leave token for development in contrib for further architectural design and development. Then everything needed for tokens can be moved out of the system module and hopefully can reduce some of the frustrating dependencies.

Dave Reid’s picture

The only stuff in system.tokens.inc that is implemented on behalf of other things is the file tokens, which we can move to file.module now.

Xano’s picture

Status: Postponed » Closed (won't fix)
Dave Reid’s picture

Agreed!