我想访问我为图片创建的字段。我隐藏了该字段,因此它不会出现在常规print render($page['content']);
函数中。
如果我打印$ page变量,我可以看到我的自定义字段。 [field_associated_image]
我见过与views module有关的例子,但这似乎过于复杂,因为我试图实现的目标。
这似乎是一个简单的问题,但我似乎无法在网上找到一个简单的答案。
$ page array
[content] => Array
(
[system_main] => Array
(
[nodes] => Array
(
[2] => Array
(
[#pre_render] => Array
(
[0] => _field_extra_fields_pre_render
)
[#entity_type] => node
[#bundle] => page
[#view_mode] => full
[#theme] => node
[#node] => stdClass Object
(
[vid] => 2
[uid] => 1
[title] => Home
[log] =>
[status] => 1
[comment] => 1
[promote] => 0
[sticky] => 0
[nid] => 2
[type] => page
[language] => und
[created] => 1386864773
[changed] => 1386886093
[tnid] => 0
[translate] => 0
[revision_timestamp] => 1386886093
[revision_uid] => 1
[body] => Array
(
[und] => Array
(
[0] => Array
(
[value] =>
Test
[summary] =>
[format] => filtered_html
[safe_value] =>
Test
[safe_summary] =>
)
)
)
[field_associated_image] => Array
(
[und] => Array
(
[0] => Array
(
[fid] => 5
[alt] =>
[title] =>
[width] => 976
[height] => 438
[uid] => 1
[filename] => home-banner.jpg
[uri] => public://home-banner_0.jpg
[filemime] => image/jpeg
[filesize] => 85851
[status] => 1
[timestamp] => 1386886093
)
)
)
[name] => admin
[picture] => 0
[data] => b:0;
[entity_view_prepared] => 1
)
答案 0 :(得分:1)
您可以尝试创建自定义模块以访问字段
function custom_field_attach_view_alter(&$output, $context) {
$node = $context['entity'];
$instances = _field_invoke_get_instances('node', $node->type, array('default' => TRUE, 'deleted' => FALSE));
foreach ($instances as $field_name => $instance) {
if ($instance['field_name']=="your_field_name") {
$display = field_get_display($instance, 'full', $node);
// Do not add field that is hidden in current display.
if ($display['type'] == 'hidden') {
continue;
}
// Load field settings.
$field = field_info_field($field_name);
$output[$field_name] = array(
'#theme' => 'field',
'#title' => $instance['label'],
'#label_display' => 'hidden',
'#field_type' => $field['type'],
'#field_name' => $field_name,
'#bundle' => $node->type,
'#object' => $node,
'#items' => array(1),
'#entity_type' => 'node',
'#weight' => $display['weight'],
0 => array('#markup' => $text),
);
}
}
}