Notice: Undefined variable: element in media_field_formatter_view() (line 162 of /home/hoslot5/public_html/sites/all/modules/media/includes/media.fields.inc).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dwkitchen’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev

I have had this message too.

Running:
Drupal 7.8 with latest File Entity dev

jonathanmd’s picture

I'm also getting this warning on 7.x-2.x-dev

aatkinson’s picture

Version: 7.x-2.x-dev » 7.x-1.0-rc1

I am also getting this error on any node that has a file type field (without the media widget enabled).
This is with Media 7.x-1.0-rc1 (which uses File Entity 7.x-1.0-rc1).

scoff’s picture

Version: 7.x-1.0-rc1 » 7.x-2.x-dev

Latest media 7.2.x-dev with latest file entity dev — same error.

UPD: The error's gone after node edit/save.

wojtha’s picture

Status: Active » Needs review
FileSize
535 bytes
wojtha’s picture

I've checked the rest of the code and found several other unitialized variables and one bug.

The bug is contained in this hunk:

diff --git a/includes/media.browser.inc b/includes/media.browser.inc
index 2d3bae7..e0b87e7 100644
--- a/includes/media.browser.inc
+++ b/includes/media.browser.inc
@@ -226,11 +226,11 @@ function media_browser_list() {
   }

   if ($url_include_patterns) {
-    $query->condition('f.uri', '%' . db_like($v) . '%', 'LIKE');
+    $query->condition('f.uri', '%' . db_like($url_include_patterns) . '%', 'LIKE');
     // Insert stream related restrictions here.
   }
   if ($url_exclude_patterns) {
-    $query->condition('f.uri', '%' . db_like($v) . '%', 'NOT LIKE');
+    $query->condition('f.uri', '%' . db_like($url_exclude_patterns) . '%', 'NOT LIKE');
   }
wojtha’s picture

Title: Watchdog Notice: Undefined variable: element in media_field_formatter_view() (line 162 of media.fields.inc » Various undefined variables which causes notices and bug in media browser query
idflood’s picture

I've carefully reviewed the patch and it globally all make sense. But I've found 2 possible issues, so here is an alternative version.

function media_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
   if ($display['type'] == 'media_large_icon') {
+    $element = array();

// the $element is returned at the end of the function so it may be better to always return an array
function media_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
+  $element = array();
   if ($display['type'] == 'media_large_icon') {


function theme_media_browser_control_result_limit($variables) {
   ...
+  $per_display = array();

// there is an extract() call at the top of this function and it may set the $per_display
function theme_media_browser_control_result_limit($variables) {
   ...
+  if (! isset($per_display)) {
+    $per_display = array();
+  }
Dave Reid’s picture

Status: Needs review » Fixed

Note the changes to media_menu(), media_library(), media_filter_info(), and media_media_plugin() are actually *not* required as they do not cause PHP notices, so I committed everything else.

http://drupalcode.org/project/media.git/commit/3bf09c1 (7.x-2.x)
http://drupalcode.org/project/media.git/commit/3b27061 (7.x-1.x)

Thanks wojtha and idflood!

Status: Fixed » Closed (fixed)

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

jenni4’s picture

Version: 7.x-2.x-dev » 7.x-1.0-rc2
Status: Closed (fixed) » Active

After 2 days of messing with this, I still cannot for the life of me apply the last patch that was posted for 7.x-1.0-rc2. I keep getting "hunk" errors. Should I just try downloading a dev module and patching that? I thought the patch included a fix for the 1.0-rc2 ver. I'm new to Drupal and this is just one gigantic headache. This error is happening when a user posts to my forum. The post goes through but the error shows up.

TIA..now I'll go take that aspirin

Dave Reid’s picture

Version: 7.x-1.0-rc2 » 7.x-2.x-dev
Status: Active » Closed (fixed)

Because I didn't commit the patch as is since it required a couple of changes. All you need to do is update to 7.x-1.x-dev.

jenni4’s picture

Ok, thanks. Will give that a try.