I have been working on updating my module to work with the latest Views 7.x branch, and have run into an issue.

Basically what is happening is my module is providing a Style plugin that uses the uses fields parameter as FALSE. What happens next is the views module constructs a view query without providing any fields which causes a crash, see the attached views_crash.png image.

After some digging, I think I have come up with a solution to this issue with the patch ( also provided ). Basically what this does is assumes they want all the fields for the base_table if they specify the parameter of "uses fields" as FALSE within their plugin.

I am not sure if this will work for everyone, but for my specific use case ( the MediaFront module ), this works beautifully. See the happy_view.png image attached. :)

I hope this helps.

Travis.

Comments

travist’s picture

FYI... I also just checked in the latest changes I made to the MediaFront module to CVS, if you would like to check it out and see for yourself. The CVS tag is DRUPAL-7--1.

Thanks again for your attention to this.

Travis.

dawehner’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev
Status: Needs review » Needs work
+++ includes/view.inc	Sun Jul 18 22:12:09 CDT 2010
@@ -672,7 +672,9 @@
+    if ( $uses_fields ) {

please try to use drupal code style. Here it should be if ($uses_fields) {

Powered by Dreditor.

And in general more important, you have to write a patch for 6.x-3.x and 6.x-2.x, too. This might change the logic here. Could you explain it more detailed.

travist’s picture

Status: Needs work » Needs review
StatusFileSize
new1.52 KB

Here is the latest patch for Drupal 7.

I don't think that this is even an issue with Drupal 6 since it uses a different database library than Drupal 7. So, I am pretty sure that this is only required for Drupal 7.

Basically the rundown here of what this is doing....

If you provide ANY plugin that specifies that it does not use fields within the plugin declaration, the current implementation will crash since it tries to run a query similar to SELECT FROM {....... The problem here is we are not providing any fields to SELECT. We need to at least say SELECT * FROM {..... if no fields are provided. So, the fix above basically tells the view, that if they do not use fields, to go ahead and grab all fields for the base table in the query.

This works very well for my needs, where I cannot force the user to specify the fields that my widget requires ( a media player ). You see, my media player definitely needs fields within each row to function, but the user would never know which ones since it changes for almost every use case and implementation I can think of. By only returning the fields that they added in the view ( which is what the current implementation of Views for Drupal 7 does ), I have no choice but to declare my widget as one that does not use fields, and then hope that views passes me back ALL fields for the base table. This is what this patch brings to the table.

Let me know if you need any more info.

Thanks for your attention in this matter.

Travis.

dawehner’s picture

Status: Needs review » Needs work

Please write patches for 6.x-3.x, and 6.x-2.x, too

Are you really sure that's what you need?

You definitive need a field to be able to do anything, for example a id, like nid.

If you need all fields i would say that this should be the job of the plugin. It can iterate over each definition and add the field, if there is one.

If * would be used, people using this could slow down the database a lot. Let's asume you have multiple joins, then * would return perhaps 30 fields.

travist’s picture

This issue has unfortunately come up again, and is keeping adoption of MediaFront 7x from happening for those who are using Views 3x.

Here is the related issue queue item in MediaFront that is caused by this problem. http://drupal.org/node/1059868

Here are patches for both Drupal 6 and 7 that fixes this issue.

Thanks,

Travis.

travist’s picture

Status: Needs work » Needs review
travist’s picture

Version: 6.x-3.x-dev » 7.x-3.0-alpha1
dawehner’s picture

Version: 7.x-3.0-alpha1 » 6.x-3.x-dev

Plesae keep the version.

travist’s picture

Here are the latest patches that use '--no-prefix' so it can be applied relatively. There is a patch for both 6.x-3.x and 7.x-3.x.

Thanks,

Travis.

travist’s picture

I just found a MUCH more elegant way to do this which is the same between the Drupal 6 and Drupal 7 versions. It is also much more explanatory on what is going on and what I need to have this fixed.

dawehner’s picture

Doesn't this code in views_plugin_row already secure this?


  function query() {
    if (isset($this->base_table)) {
      if (isset($this->options['relationship']) && isset($this->view->relationship[$this->options['relationship']])) {
        $relationship = $this->view->relationship[$this->options['relationship']];
        $this->field_alias = $this->view->query->add_field($relationship->alias, $this->base_field);
      }
      else {
        $this->field_alias = $this->view->query->add_field($this->base_table, $this->base_field);
      }
    }
  }

You should probably set the base_field in your plugin as row_node_view does it:

class views_plugin_row_node_view extends views_plugin_row {
  // Basic properties that let the row style follow relationships.
  var $base_table = 'node';
  var $base_field = 'nid';
travist’s picture

Well, I think it would, but my widget declares the following...

/**
 * Implementation of hook_views_plugins
 */
function mediafront_views_plugins() {
  $path = drupal_get_path('module', 'mediafront');
  $plugins = array(
    'module' => 'mediafront', // This just tells our themes are elsewhere.
    'style' => array(
      'mediaplayer' => array(
        'title' => t('Media Player'),
        'help' => t('Shows this view as a Media Player.'),
        'handler' => 'mediafront_plugin_style_player',
        'theme' => 'mediafront_player_view',
        'path' => "$path/views",
        'theme path' => "$path/views",
        'uses fields' => FALSE,
        'uses row plugin' => FALSE,
        'uses options' => TRUE,
        'uses grouping' => FALSE,
        'type' => 'normal',
        'even empty' => TRUE,
      )
    )    
  );
  return $plugins;
}

I don't need a row plugin, so I declared 'uses row plugin' as FALSE. My widget is simply a MediaPlayer style where I take the view results and populate a media player playlist from that view. I didn't see the need for a row plugin since I am passing along all the rows to my widget to render.

And as for your second notion, I am not totally sure that would work in a style plugin. I have always assumed that the style plugins really should not have any control over the query, but maybe that would work. Let me know otherwise.

Thanks for your attention to this.

Travis.

dawehner’s picture

Assigned: Unassigned » merlinofchaos

Assign to earl for review/comment about the issue itself.

mustanggb’s picture

Issue summary: View changes
Status: Needs review » Closed (won't fix)