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

brahms’s picture

Status: Active » Needs review
StatusFileSize
new572 bytes

I attach a patch file with the bugfix desribed above.

merlinofchaos’s picture

Status: Needs review » Needs work

Hmm. This can't be right.

    if (!is_numeric($this->format)) {
      $this->additional_fields['format'] = $this->format;
    }

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. :/

brahms’s picture

StatusFileSize
new593 bytes

Thanks 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:

In the array this->additional_fields
With array key = 'format' the name of the table column which stores the format of the 'article' field: "article_format"
In the array this->aliases
With array key = 'article_format' the alias of the format field: "ak_requisition_article_format"
In the $values object
The property ak_requisition_article_format from the query result with the value of the format which has to be applied to render the field 'article

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:

  function render($values) {
    $value = $values->{$this->field_alias};
    //$format = is_numeric($this->format) ? $this->format : $values->{$this->aliases['format']};
    $format = is_numeric($this->format) ? $this->format : $values->{$this->aliases[$this->additional_fields['format']]};
    return check_markup($value, $format, FALSE);
  }

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).

brahms’s picture

Version: 6.x-2.0-rc5 » 6.x-2.2
Status: Needs work » Needs review
StatusFileSize
new593 bytes

As 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

merlinofchaos’s picture

StatusFileSize
new1 KB

Try this patch; I'd prefer this, and I think it should work.

brahms’s picture

Status: Needs review » Reviewed & tested by the community

I 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_markup between 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!

merlinofchaos’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thanks for the test!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.