source: sipes/modules_contrib/cck/includes/content.token.inc @ 6e81fb4

stableversion-3.0
Last change on this file since 6e81fb4 was dafc8d8, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se actualizo el modulo

  • Propiedad mode establecida a 100755
File size: 2.4 KB
Línea 
1<?php
2
3/**
4 * @file
5 * Implementation of hook_content_build_modes
6 * (on behalf of token.module)
7 */
8function token_content_build_modes() {
9  return array(
10    'token' => array(
11      'title' => t('Token'),
12      'build modes' => array(
13        'token' => array(
14          'title' => t('Token'),
15          'views style' => FALSE,
16        ),
17      ),
18    ),
19  );
20}
21
22// Two helper functions that generate appropriate tokens for CCK-added fields.
23function content_token_values($type, $object = NULL, $options = array()) {
24  $tokens = array();
25  if ($type == 'node') {
26    // Prevent against invalid 'nodes' built by broken 3rd party code.
27    if (isset($object->type)) {
28      // Let PHP free the $node object when we are done. Working directly on the
29      // incoming $object causes memory leak issues on long-running scripts such
30      // as migrations. See http://drupal.org/node/736440.
31      $node = drupal_clone($object);
32      $content_type = content_types($node->type);
33      $node->build_mode = 'token';
34      $node->content = array();
35      content_view($node);
36      // The formatted values will only be known after the content has been rendered.
37      drupal_render($node->content);
38      content_alter($node);
39
40      $field_types = _content_field_types();
41      foreach ($content_type['fields'] as $field_name => $field) {
42        $items = isset($node->{$field_name}) ? $node->{$field_name} : array();
43        $function = $field_types[$field['type']]['module'] . '_token_values';
44        if (!empty($items) && function_exists($function)) {
45          $token_values = (array) $function('field', $items, $options);
46          foreach ($token_values as $token => $value) {
47            $tokens[$field_name .'-'. $token] = $value;
48          }
49        }
50      }
51    }
52  }
53  return $tokens;
54}
55
56function content_token_list($type = 'all') {
57  if ($type == 'node' || $type == 'all') {
58    $list = array();
59    $field_types = _content_field_types();
60
61    foreach (content_fields() as $field) {
62      $sub_list = array();
63      $function = $field_types[$field['type']]['module'] . '_token_list';
64      if (function_exists($function)) {
65        $sub_list = $function('field');
66        foreach ($sub_list as $category => $token_list) {
67          foreach ($token_list as $token => $description) {
68            $list['CCK '. $category][$field['field_name'] .'-'. $token] = $description;
69          }
70        }
71      }
72    }
73
74    return $list;
75  }
76}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.