Description:

I'm using Views Atom Module together with views to render the Atom Feed.

After the configuration of the view i got the following error:

Unsupported operand types in sites/all/modules/views/plugins/views_plugin_row_rss_fields.inc on line 120

if (function_exists('rdf_get_namespaces')) {
      // Merge RDF namespaces in the XML namespaces in case they are used
      // further in the RSS content.
      $xml_rdf_namespaces = array();
      foreach (rdf_get_namespaces() as $prefix => $uri) {
        $xml_rdf_namespaces['xmlns:' . $prefix] = $uri;
      }
      $this->view->style_plugin->namespaces += $xml_rdf_namespaces;
    }

This error occurs because $this->view->style_plugin->namespaces is not set at that point when it runs through.

Solution:

Here is my suggestion:

if (function_exists('rdf_get_namespaces')) {
      // Merge RDF namespaces in the XML namespaces in case they are used
      // further in the RSS content.
      $xml_rdf_namespaces = array();
      foreach (rdf_get_namespaces() as $prefix => $uri) {
        $xml_rdf_namespaces['xmlns:' . $prefix] = $uri;
      }

      //check if namespace array is available
      if (isset($this->view->style_plugin->namespaces) && is_array($this->view->style_plugin->namespaces)) {
        $this->view->style_plugin->namespaces += $xml_rdf_namespaces;
      }
      else {
        $this->view->style_plugin->namespaces = $xml_rdf_namespaces;
      }

Does anyone have a better solution?

Comments

mahalo13’s picture

Status: Active » Needs review
StatusFileSize
new894 bytes

Status: Needs review » Needs work

The last submitted patch, 1: rss_feed_unsupported_namespaces-2172659.patch, failed testing.

mahalo13’s picture

applied new patch

mahalo13’s picture

Status: Needs work » Needs review
StatusFileSize
new870 bytes

Status: Needs review » Needs work

The last submitted patch, 4: rss_feed_unsupported_namespaces-2172659-3.patch, failed testing.

jmdeleon’s picture

StatusFileSize
new657 bytes

I ran into the same error when using the Views Atom module.

The comment in the file views_plugin_row_rss_fields.inc suggests to merge the RDF and XML namespaces, yet the += operator (which is not type safe, hence the error) is used. My patch performs an array_merge rather than an += operator.

Patch submitted was tested on Views 7.x-3.13 release.

jmdeleon’s picture

jmdeleon’s picture

Version: 7.x-3.7 » 7.x-3.13
jmdeleon’s picture

Status: Needs work » Needs review
jmdeleon’s picture

StatusFileSize
new690 bytes

Additional change to my patch in #7 to handle cases where the namespaces property is not set.

jmdeleon’s picture

StatusFileSize
new689 bytes

Fixed typo in patch in #10.

jmdeleon’s picture

Status: Needs review » Closed (won't fix)
Related issues: +#2766325: RSS Namespaces - Unsupported Operand Types when using fields

This issue can be resolved by initializing the namespace array in the Views display plugin for Views Atom itself. A patch to do this is available here: #2766325: RSS Namespaces - Unsupported Operand Types when using fields

Marked as Closed (won't fix), as the fix won't be applied to Views.