In a node module I have a textarea field with an input filter. In the table for this node type the responding table columns are 'article' for the textarea field and 'article_format' for the number of the used input format. In describing this table to Views I use for the article field:
$data['ak_requisition']['article'] = array(
'title' => t('Article'), // The item it appears as on the UI,
'help' => t('The body of the article'), // The help that appears on the UI,
// Information for displaying a title as a field
'field' => array(
'handler' => 'views_handler_field_markup',
'format' => 'article_format', // The name of the format field
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
When I add the field 'article' to a view I get following PHP error:
PHP Fatal error: Cannot access empty property in /var/www/html/ak/intratest/sites/all/modules/views/handlers/views_handler_field_markup.inc on line 31
I had to modify the original code line:
$format = is_numeric($this->format) ? $this->format : $values->{$this->aliases['format']};
to:
$format = is_numeric($this->format) ? $this->format : $values->{$this->aliases[$this->format]};
the make the handler work. Now the value in the format field 'article_format' is used and the error is gone.
The error occurs only if the format companion field's name is another than the default name 'format'.
Comments
Comment #1
brahms commentedI attach a patch file with the bugfix desribed above.
Comment #2
merlinofchaos commentedHmm. This can't be right.
That should cause it to always use the 'format' key in $this->aliases. See views_handler_field::add_additional_fields()
So I'm not quite sure why this patch works.
Ahh. I see now. add_additional_fields() is not using the key. THis is going to require checking every use of additional_fields to see if an existing field depends upon this wrong behavior. :/
Comment #3
brahms commentedThanks for your quick reply.
It was the first time I looked at View's code and so I don't know much about Views and the Views API :-(
Reading your comment#2 I looked at views_handler_field::add_additional_fields() and again at views_handler_field_markup::render() and views_handler_field_markup::construct(). In views_handler_field_markup::render() for my 'article' field as current object I have:
So it seems to me that
$values->{$this->aliases[$this->additional_fields['format']]}gives back the format value, if $this->format is not numeric. Here is the whole views_handler_field_markup::render() method, I uncommented the original code line which caused the PHP error:Maybe you will have a look if this modification is right?
I attach a new patch file with this modification (the patch has to be applied against the orginal version 6.x-2.0-rc5 of the Views module).
Comment #4
brahms commentedAs this issue still exists in the new views release 6.x-2.2 I attach a new patch file solving the problem for 6.x-2.2
Comment #5
merlinofchaos commentedTry this patch; I'd prefer this, and I think it should work.
Comment #6
brahms commentedI just applied and tested the patch from comment #5 with views 6.x-2.1 and it works fine. As there is no change in
class views_handler_field_markupbetween release 6.x-2.1 and 6.x-2.2 of views module I think it will work in 6.x-2.2 too.Thanks merlinofchaos!
Comment #7
merlinofchaos commentedCommitted. Thanks for the test!