Flippy still uses the old method of loading all available tokens on every content type editing page. This can cause massive memory usage during content type editing on large sites and can result in out of memory errors and memcache chunk errors. Let's use the on-demand JQuery method implemented in Token 7.x-1.2. Here is the sample implementation code provided by Dave Reid in the Token issue queue.
<?php
...
// Show the token browser.
$form['available_tokens'] = array(
'#value' => 'Browse available tokens',
'#theme' => 'token_tree',
'#token_types' => array($instance['entity_type']),
'#weight' => 100,
'#dialog' => TRUE,
);
?>
The '#dialog' => TRUE is enough to use the JQuery modal on systems with the newer (3 years old) version of Token and fall back to the old in-page loading method on sites that don't support it.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | load_tokens_on_demand-2557229-7.patch | 727 bytes | spaghettibolognese |
| #6 | Screen Shot 2015-08-25 at 2.23.12 PM.png | 145.14 KB | jamesrward |
| #5 | load_tokens_on_demand-2557229-5.patch | 806 bytes | jamesrward |
| #4 | load_tokens_on_demand-2557229-4.patch | 374 bytes | jamesrward |
Comments
Comment #2
jamesrward commentedComment #3
jamesrward commentedComment #4
jamesrward commentedHere is a one-line patch that resolves the issue but leaves the interface a little funky as you have to click twice to browse the tokens.
Comment #5
jamesrward commentedAnd here is a version with the interface fixed to avoid the extra click.
Comment #6
jamesrward commentedAnd just to be thorough here are back-to-back runs with and without the patch #5 on our site.
158Mb less peak memory used, 413,256 fewer function calls, and while it shows about 2.5 seconds off of wall time it is actually more like 30 seconds given the extra javascript that runs when PHP is done it's job. I had to click "wait" 3 times in chrome to let it finish.
Comment #7
spaghettibolognese commentedNice patch, makes the UI respond way better. One small change: it's better to use theme_token_tree_link() for this task.
From https://www.drupal.org/documentation/modules/token
Comment #8
alxgl_old commentedThanks a lot @SpaghettiBolognese for your patch ! It works like a charm and allows me to edit content types without crashing my entire website !
Comment #10
rliCommitted to dev. Thanks.