Notice: Undefined variable: base_tables in entity_views_plugins() (line 324 of /home/pavella/d7/sites/all/modules/entity/views/entity.views.inc).

This started happening after I created a feature that included some views, now I get this notice on any/all pages that make use of a view. I'm not sure what other information might be relevant. I was working out of a blank site for the sole purpose of creating a new feature.

Thanks for any insights.

Files: 
CommentFileSizeAuthor
#7 undefined-variable-base-table-fix-1630578-7.patch455 bytescpliakas
PASSED: [[SimpleTest]]: [MySQL] 354 pass(es).
[ View ]

Comments

Had the same error message right after enabling 7.x-1.0-rc3.

Switched to 7.x-1.0-rc2 and the error message is not appearing anymore.

Cheers,

Y

Thanks Yanivs.

The notice doesn't seem to be breaking anything, hopefully it's there's a fix in the next release.

I have the same issue.

It seems to me that the problem lies in the new function entity_views_table_definition(), which replaces the function of EntityDefaultViewsController.views_data() - (as far as I can tell the latter no longer gets called). However, in doing so, entity_views_table_definition() forgets to populate the ['base'] sub-array of its return value. Here is my suggestion for an amendment:

entity/views/entity.views.inc:

function entity_views_table_definition($type, $exclude = TRUE) {
  // As other modules might want to copy these tables as a base for their own
  // Views integration, we statically cache the tables to save some time.
  $tables = &drupal_static(__FUNCTION__, array());
  if (!isset($tables[$type])) {
    // Work-a-round to fix updating, see http://drupal.org/node/1330874.
    // Views data might be rebuilt on update.php before the registry is rebuilt,
    // thus the class cannot be auto-loaded.
    if (!class_exists('EntityFieldHandlerHelper')) {
      module_load_include('inc', 'entity', 'views/handlers/entity_views_field_handler_helper');
    }
    $info = entity_get_info($type);
    $tables[$type]['table'] = array(
      'group' => $info['label'],
      'entity type' => $type,
    );
    // !!! START OF SUGGESTED PATCH !!!
    $tables[$type]['table']['base'] = array(
      'field' => $info['entity keys']['id'],
      'title' => drupal_ucfirst($info['label']),
      // @todo: Support an entity info description key or such?
      'help' => '',
    );
    // !!! END OF SUGGESTED PATCH !!!
    foreach (entity_get_all_property_info($type) as $key => $property) {
      if (!$exclude || empty($property['entity views field'])) {
        entity_views_field_definition($key, $property, $tables[$type]);
      }
    }
  }
  return $tables[$type];
}

There's another issue whereby the base_tables array is not being set before it is used.
Another suggested patch:

entity/views/entity.views.inc:

function entity_views_plugins() {
  // Have views cache the table list for us so it gets
  // cleared at the appropriate times.
  $data = views_cache_get('entity_base_tables', TRUE);
  if (!empty($data->data)) {
    $base_tables = $data->data;
  }
  else {
// !!! START OF SUGGESTED PATCH !!!
$base_tables = array(); // set to empty array before use
// !!! END OF SUGGESTED PATCH !!!
    foreach (views_fetch_data() as $table => $data) {
      if (!empty($data['table']['entity type']) && !empty($data['table']['base'])) {
        $base_tables[] = $table;
      }
    }
    views_cache_set('entity_base_tables', $base_tables, TRUE);
  }

Status:Needs review» Active

Thanks guys!

However, please provide an actual .patch file before setting an issue to "needs review".

Needs Review ["CNR"]
A patch has been created and needs review and testing. The Testing Bot uses this status to trigger an automated review of the patch, and reports the results. Patch Reviewers also use this status to find patches that need to be reviewed and evaluated. With sufficient positive feedback, the patch may be promoted to the status "Reviewed & Tested by the Community" [see next definition]. If a reviewer, either human or Bot, finds a problem with the patch, it will then be marked as "Needs Work". Note that if a patch is not required in order to complete the idea described in the issue, then it is the idea itself that needs review.

Other than that (without actually looking into this): The suggested solution from #4 seems to be the right approach. I understand that the loop might not yield any results in some cases which would cause this error message.

You can learn how to create a patch right here: http://drupal.org/project/entity/git-instructions

Version:7.x-1.0-rc3» 7.x-1.x-dev

Oh and by looking at the current dev tree the code is still the same there so the bug report should be filed against the dev branch instead of the release candidate.

Status:Active» Needs review
StatusFileSize
new455 bytes
PASSED: [[SimpleTest]]: [MySQL] 354 pass(es).
[ View ]

Converted #1630578-4: Notice: Undefined variable: base_tables in entity_views_plugins() (line 324 to a patch because I need this fix immediately. Sorry for commandeering someone else's work, but if this does get into the module please give splig credit for the patch.

Thanks!
Chris

Status:Needs review» Reviewed & tested by the community

Status:Reviewed & tested by the community» Fixed

thanks, committed.

Thanks its fixed.

Status:Fixed» Closed (fixed)

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