Created on 11 July 2023, 12 months ago
Updated 12 July 2023, 12 months ago

I set up a test D10 site and installed 4 Alpha4. I made a very simple page using the computed field and everything works fine until I try to go to views to see if I can now use the new computed field there. When I access Views the site crashes with a PHP error:

Error: Call to a member function getType() on null in Drupal\views\Plugin\views\field\EntityField->defineOptions() (line 375 of /var/www/vhosts/website.com/testsite/web/core/modules/views/src/Plugin/views/field/EntityField.php).

Other than that it's working. I can add my plugin if it needs to be seen.

πŸ’¬ Support request
Status

Fixed

Version

4.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States wxman

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

Comments & Activities

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

    My 'buy_amazon.views.inc' file looks like this:

    function buy_amazon_views_data() {
    
      $data['node_field_data']['computed_buy_amazon'] = [
        'title' => t('Buy Amazon'),
        'entity field' => 'computed_buy_amazon',
        'field' => [
          'id' => 'field',
        ],
      ];
    
      return $data;
    }
    
  • πŸ‡¬πŸ‡§United Kingdom joachim

    That looks like the error you get without the core patch -- have you applied that? It's explained in the README.

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

    I'm sorry but I can't find any links to the core patch at https://www.drupal.org/project/drupal/issues/3349739 πŸ“Œ Automatically declare computed base fields to Views Needs work .
    Could you provide a link so I can add it to my composer.json and give it a test?

  • Status changed to Fixed 12 months ago
  • πŸ‡¬πŸ‡§United Kingdom joachim

    Argh I mixed up the issue numbers.

    It's this one: https://www.drupal.org/project/drupal/issues/2981047 πŸ“Œ Allow adding computed bundle fields in Views Fixed

    I'll fix the README.

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

    I'm guessing it's #118 so I added " https://www.drupal.org/files/issues/2023-02-23/2981047-118.patch β†’ " to my composer.json . I ran 'composer update', and 'drush cr', still getting the same error. Isn't that the correct patch for a D10 site? It didn't give me any errors when I ran update, but it also didn't say it was loading the patch.

  • πŸ‡¬πŸ‡§United Kingdom joachim

    The patch says it's for 10.1

    You're better off using the diff from the MR, as that is more recent.

    > It didn't give me any errors when I ran update, but it also didn't say it was loading the patch.

    You mean `composer update` didn't tell you it was deleting Drupal to patch it? Then the patch has not been applied.

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

    Still getting the same PHP error. This is a new 10.1 test site so not much on it but my one test page.
    Here's what I did. I ran 'composer require cweagans/composer-patches:~1.0 --update-with-dependencies'
    Here is the exact lines I added to my composer.json:

            "patches": {
                "drupal/views": {
                    "computed base fields to work in Views": "https://www.drupal.org/files/issues/2023-02-23/2981047-118.patch"
                }
            },
    

    I ran composer update and saw:

    Gathering patches for root package.
    Loading composer repositories with package information
    Updating dependencies
    Nothing to modify in lock file
    Installing dependencies from lock file (including require-dev)
    Nothing to install, update or remove
    Generating autoload files
    49 packages you are using are looking for funding.
    Use the `composer fund` command to find out more!
    No security vulnerability advisories found
    

    Maybe I'm using the wrong patch URL?

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

    I finally think I have it! I changed composer.json to:

            "patches": {
                "drupal/core": {
                    "computed base fields to work in Views": "https://git.drupalcode.org/project/drupal/-/merge_requests/4224.diff"
                }
            },
    

    Not the errors are gone and the field works in Views. If anyone wants to see my simple module for an example please let me know.

  • πŸ‡¬πŸ‡§United Kingdom joachim

    Well that's applying. But like I said, you might be better off trying the diff from the MR instead.

  • πŸ‡¬πŸ‡§United Kingdom joachim

    Sorry -- cross-posted with your comment about applying the diff.

    Glad to hear you got it working!

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

Production build 0.69.0 2024