statistics_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata)
Implements hook_tokens().
File
- core/modules/statistics/statistics.tokens.inc, line 36
- Builds placeholder replacement tokens for node visitor statistics.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | function statistics_tokens( $type , $tokens , array $data , array $options , BubbleableMetadata $bubbleable_metadata ) { $token_service = \Drupal::token(); $replacements = array (); if ( $type == 'node' & ! empty ( $data [ 'node' ])) { $node = $data [ 'node' ]; foreach ( $tokens as $name => $original ) { if ( $name == 'total-count' ) { $statistics = statistics_get( $node ->id()); $replacements [ $original ] = $statistics [ 'totalcount' ]; } elseif ( $name == 'day-count' ) { $statistics = statistics_get( $node ->id()); $replacements [ $original ] = $statistics [ 'daycount' ]; } elseif ( $name == 'last-view' ) { $statistics = statistics_get( $node ->id()); $replacements [ $original ] = format_date( $statistics [ 'timestamp' ]); } } if ( $created_tokens = $token_service ->findWithPrefix( $tokens , 'last-view' )) { $statistics = statistics_get( $node ->id()); $replacements += $token_service ->generate( 'date' , $created_tokens , array ( 'date' => $statistics [ 'timestamp' ]), $options , $bubbleable_metadata ); } } return $replacements ; } |
Please login to continue.