Skip to content

Craft 5: Getting a lot of null variable errors #14

@LinneaHarts

Description

@LinneaHarts

Trying to use this on craft 5 (Craft 5.6.4, MariaDB, PHP 8.2), whenever I drill down to the field usage, I'm getting a null variable error.

e.g.

Twig Runtime Error – Twig\Error\RuntimeError
Impossible to access an attribute ("name") on a null variable.

  1. in /var/www/html/bso/vendor/simplygoodwork/craft-block-usage/src/templates/entries.twigat line 87
    78798081828384858687888990919293949596
    {% for entry in blockEntries.entries %}

                           <tr>
                               <td>{{ entry.id }}</td>
                               <td>
                                   <a href="{{ entry.cpEditUrl() }}">{{ entry.title }}</a>
                               </td>
                               <td>
                                 {{ entry.section.name }}
                               </td>
                               <td>
                                 {{ entry.type.name }}
                               </td>
                           </tr>
    
                       {% endfor %}
                   </tbody>
               </table>
    

OR

Error
Call to a member function getOwner() on null

  1. in /var/www/html/bso/vendor/simplygoodwork/craft-block-usage/src/services/BlockUsageService.phpat line 113
    104105106107108109110111112113114115116117118119120121122 elseif ($field->displayName() == 'Matrix') {

         foreach($field->getEntryTypes() as $entryType)
         {
             $entries = Entry::find()->typeId($entryType->id)->status(null)->collect();
    
             $topLevelEntries = $entries->map(function($entry){
                 try {
                     $owner = $entry->getOwner();
                     while($owner->getOwner()) {
                         $owner = $owner->getOwner();
                     }
    
                     return $owner;
                 } catch(Exception $e) {
                     return $entry;
                 }
             })->unique();
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions