drupal 7 – ¿Cómo accedo a un valor de campo en la variable $ row en una plantilla de tema de vista de campo?

Pregunta:

Estoy anulando una plantilla de campo para una de mis vistas y quiero poder acceder a otro valor de campo desde la variable $ row. La documentación del archivo de plantilla muestra esto:

Al obtener la salida de $ row, se debe usar esta construcción: $ data = $ row -> {$ field-> field_alias}

Mi campo se llama field_calendar_title, pero lo siguiente no funciona como se esperaba:

$row->{$field->field_calendar_title}

Obtuve el siguiente error:

Error fatal: no se puede acceder a la propiedad vacía …

¿El campo "alias" es diferente del nombre del campo en el tipo de contenido?

Salida "limpiada" de var_dump de $ row:

stdClass Object
(
    [node_title] => ...
    [nid] => 568
    [field_data_field_performance_date_delta] => 0
    [field_data_field_performance_date_language] => und
    [field_data_field_performance_date_bundle] => event
    [field_data_field_performance_date_field_performance_date_val] => 2012-03-02 19:00:00
    [field_data_field_performance_date_node_entity_type] => node
    [_field_data] => Array
        (
            [nid] => Array
                (
                    [entity_type] => node
                    [entity] => stdClass Object
                        (
                            [vid] => 878
                            [uid] => 0
                            [title] => ...
                            [log] => 
                            [status] => 1
                            [comment] => 0
                            [promote] => 0
                            [sticky] => 0
                            [nid] => 568
                            [type] => event
                            [language] => und
                            [created] => 1329332968
                            [changed] => 1331836509
                            [tnid] => 0
                            [translate] => 0
                            [revision_timestamp] => 1331836509
                            [revision_uid] => 1
                            [body] => Array
                                (
                                    [und] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [value] => ...
                                                    [summary] => ...
                                                    [safe_summary] => ...
                                                )
                                        )
                                )
                                [field_resident_company] => Array ( [und] => Array ( [0] => Array ( [tid] => 3 ) ) )
                                [field_series] => Array ( [und] => Array ( [0] => Array ( [tid] => 36 ) ) )
                                [field_venue] => Array ( )
                                [field_rotator_image] => Array ( )
                                [field_exclude] => Array ( [und] => Array ( [0] => Array ( [value] => 0 ) ) )
                                [field_performance_image] => Array ( )
                                [field_premiere] => Array ( [und] => Array ( [0] => Array ( [value] => 1330714800 [timezone] => UTC [timezone_db] => UTC [date_type] => datestamp ) ) )
                                [field_closing] => Array ( [und] => Array ( [0] => Array ( [value] => 1330714800 [timezone] => UTC [timezone_db] => UTC [date_type] => datestamp ) ) )
                                [field_exclude_update] => Array ( [und] => Array ( [0] => Array ( [value] => 0 ) ) )
                                [field_performance_date] => Array ( [und] => Array ( [0] => Array ( [value] => 2012-03-02 19:00:00 [timezone] => UTC [timezone_db] => UTC [date_type] => datetime ) ) )
                                [field_performance_id] => Array ( [und] => Array ( [0] => Array ( [value] => 1436 [format] => [safe_value] => 1436 ) ) ) [field_event_status] => Array ( [und] => Array ( [0] => Array ( [value] => open ) ) )
                                [field_calendar_title] => Array ( [und] => Array ( [0] => Array ( [value] => PSYCHIC EXP [format] => [safe_value] => PSYCHIC EXP ) ) )
                                ...
                        )
) 

Respuesta:

Por el aspecto de var_dump , debería poder encontrar el valor de su campo con esto:

$row->_field_data['nid']['entity']->field_calendar_title['und'][0]['value'];

¡Realmente espero que haya una manera mejor que esa!

Leave a Comment

Your email address will not be published.

Scroll to Top

istanbul avukat

-

web tasarım