Undefined property notices when enabling module

Created on 20 March 2023, over 1 year ago
Updated 30 December 2023, 6 months ago

Been using the module for a long time. Recently am porting the site over to use Backdrop CMS (fork of D7) since I don't want to convert it to use Drupal 8.

I enabled the module from within admin/modules and got a ton of error messages as it attempted to rebuild the sort data. Hmm, actually looks like the same 2 errors a zillion times (1,274 times each to be exact).

Notice: Undefined property: File::$name in views_natural_sort_views_natural_sort_queue_rebuild_data() (line 146 of /var/www/html/backdrop1/modules/contrib/views_natural_sort/views_natural_sort.module).
Notice: Undefined property: File::$mime in views_natural_sort_views_natural_sort_queue_rebuild_data() (line 146 of /var/www/html/backdrop1/modules/contrib/views_natural_sort/views_natural_sort.module).
Help?

The maintainer of the module tried it on a fresh D7 install and found the same error messages though with a different line number:
Undefined property: stdClass::$mime in views_natural_sort_views_natural_sort_queue_rebuild_data() (line 232 of /app/sites/all/modules/views_natural_sort/views_natural_sort.module).

What I am wondering is whether this module is still being maintained for D7, or if you can give me any pointers on what the Undefined property notice means so I can try to track it down.

The issue over at Backdrop is at: https://github.com/keiserjb/views_natural_sort/issues/2

πŸ› Bug report
Status

Needs review

Version

2.8

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @leeksoup
  • πŸ‡ΊπŸ‡ΈUnited States generalredneck

    Ok, Give me the week please. I still "kinda" maintain the D7 version as I just mostly get in maintenance fixes like this one.

    As for pointers... the first thing I would do is do as you say... pick up lando, install the Drupal 7 recipe, install this module, put a conditional breakpoint at line 232 https://git.drupalcode.org/project/views_natural_sort/-/blob/7.x-2.x/vie...

    looking for "$field_name='mime'" and see what entity comes up. You should be able to repeat this process by running cache clear and hitting the "Reindex button" on admin/structure/views/settings/views_natural_sort.

    I gave it about 15 minutes this morning looking for a quick work around for you and the best I've got at the moment is to implement hook_views_natural_sort_get_entry_types_alter and unset mime fields if you need an immediate fix.
    https://git.drupalcode.org/project/views_natural_sort/-/blob/7.x-2.x/vie...

    I didn't know the fork was being maintained over there. I seem to remember vaguely someone asked to port it.

  • πŸ‡ΊπŸ‡ΈUnited States keiserjb

    I'll take a look at those tips. Yes, I've been messing around with this in Backdrop. Since we are talking about it I'll probably move it over to Backdrop Contrib and out of my personal GitHub but it's not ready for release.

  • πŸ‡ΊπŸ‡ΈUnited States keiserjb

    When it gets to the last step of the indexing the 'content' index of the array for the mime is null. I changed the line to set it to an empty string if it wasn't set. Don't know if this is correct, but the undefined index is gone and the titles are in the correct order.

    'content' => (isset($entity->$field_name) ? $entity->$field_name : ""),

  • Status changed to Needs review about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States generalredneck

    @keiserjb, @leeksoup,

    This is a patch against the Drupal version obviously... but here's the short of the explanation. In the modules I'm using drupal core's function "entity_get_info". The challenge here is that while this lists all the properties, it doesn't necessarily line up 1 for 1 with the objects that get pulled back from "entity_load". That said the Entity API β†’ module (which Views Natural Sort relies on) supports using those property short hand names in entity wrappers because it does the magic of doing the translation from the module defined entity properties in hook_entity_info() to what the objects require to be pulled from and written to the database.

    In Backdrop, you MAY have to rewrite the dependency to work with Entity Plus.

  • πŸ‡ΊπŸ‡ΈUnited States keiserjb

    Installed the patch in Drupal 7 and the undefined property is gone. Thank you!

  • πŸ‡ΊπŸ‡ΈUnited States keiserjb

    #6 might not play nice with the Rules module.

    EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. in EntityBackdropWrapper->set() (line 761 of /app/modules/contrib/entity_plus/includes/entity_plus.wrapper.inc).

  • Status changed to Needs work about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States generalredneck

    @keiserjb,
    Sorry I couldn't meet up at Midcamp contrib day, That said I'm going to take a second look at this. just to recap some of the stuff we talked about in slack and in person:

    keiserjb
    I don't think the patch you made plays nicely with the Rules module. I happened to have it on in the Backdrop site I'm using Views Natural Sort on. Indexed it and got EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. in EntityBackdropWrapper->set() (line 761 of /app/modules/contrib/entity_plus/includes/entity_plus.wrapper.inc).
    Then for fun I tried it on D7. Got the same. EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. Value at rules_config(): 1. in EntityDrupalWrapper->set() (line 765 of /app/sites/all/modules/entity/includes/entity.wrapper.inc).

    This seems to be a known issue with EntityMetadataWrappers. see a related issue #2143171: Entity Metadata Wrapper support broken for named, exportable entities. β†’ . This is going to happen on some entities like rules maybe?

    A work around may be to implement something like #3189631: Not all records provide an integer for eid: Fatal error β†’ for D7.

    Looking into this further.

  • Status changed to Needs review about 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 7.x + Environment: PHP 5.3 & MySQL 5.5
    last update about 1 year ago
    10 pass
  • πŸ‡ΊπŸ‡ΈUnited States generalredneck

    Give this a shot. I think I've got it worked out.

  • πŸ‡ΊπŸ‡ΈUnited States keiserjb

    When I turn on rules I still get a notice.

    Notice: Undefined property: RulesReactionRule::$plugin in views_natural_sort_views_natural_sort_queue_rebuild_data() (line 233 of /app/sites/all/modules/views_natural_sort/views_natural_sort.module).

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 7.x + Environment: PHP 5.3 & MySQL 5.5
    last update 12 months ago
    10 pass
  • πŸ‡ΊπŸ‡ΈUnited States generalredneck

    This appears to work and passed all tests for me. let me know if you have a different experiance

  • πŸ‡ΊπŸ‡ΈUnited States keiserjb

    Looks like this works. I finally tried it.

Production build 0.69.0 2024