Problem/Motivation

I open the url /compare/product-comparison and i got the error:

TypeError: Argument 2 passed to Drupal\entity_comparison\Controller\EntityComparisonController::getTargetFields() must be an instance of Drupal\Core\Entity\Entity\EntityViewDisplay, null given, called in /drushproject/web/modules/entity_comparison/src/Controller/EntityComparisonController.php on line 321 in /drushproject/web/modules/entity_comparison/src/Controller/EntityComparisonController.php on line 425 #0 /drushproject/web/modules/entity_comparison/src/Controller/EntityComparisonController.php(321): Drupal\entity_comparison\Controller\EntityComparisonController->getTargetFields(Array, NULL, 'product_compari...')
#1 [internal function]: Drupal\entity_comparison\Controller\EntityComparisonController->compare(NULL)
#2 /drushproject/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#3 /drushproject/web/core/lib/Drupal/Core/Render/Renderer.php(573): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#4 /drushproject/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#5 /drushproject/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#6 /drushproject/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#7 /drushproject/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#8 /drushproject/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#9 /drushproject/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#10 /drushproject/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#11 /drushproject/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#12 /drushproject/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#13 /drushproject/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#14 /drushproject/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#15 /drushproject/web/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#16 /drushproject/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#17 {main}

Steps to reproduce

- create module with node type "testprodukt"
- create function in module with this code

function my_module_install() {
  $entityComparison = EntityComparison::create([
    'label' => 'Comp',
    'id' => 'product_comparison',
    'add_link_text' => 'add',
    'remove_link_text' => 'rem',
    'limit' => 5,
    'entity_type' => 'node',
    'bundle_type' => 'testprodukt',
  ])->save();
}

I think after that is something missing like createViewMode() or updateViewMode() from your test.

Proposed resolution

- No error!
- An empty page or text "no node in your list" would be helpful.

Comments

thomaswalther created an issue. See original summary.

thomaswalther’s picture

So I added a node for this type -->

#1 [internal function]: Drupal\entity_comparison\Controller\EntityComparisonController->compare(NULL)

So I added a node to the compare list -->

TypeError: Argument 2 passed to Drupal\entity_comparison\Controller\EntityComparisonController::getTargetFields() must be an instance of Drupal\Core\Entity\Entity\EntityViewDisplay, null given, called in /mydrushproject/web/modules/entity_comparison/src/Controller/EntityComparisonController.php on line 321 in /mydrushproject/web/modules/entity_comparison/src/Controller/EntityComparisonController.php on line 425 #0 /mydrushproject/web/modules/entity_comparison/src/Controller/EntityComparisonController.php(321): Drupal\entity_comparison\Controller\EntityComparisonController->getTargetFields(Array, NULL, 'product_compari...')
#1 [internal function]: Drupal\entity_comparison\Controller\EntityComparisonController->compare(NULL)

thomaswalther’s picture

Title: No nodes will show error » No nodes or no view will show error
Issue summary: View changes
thomaswalther’s picture

Title: No nodes or no view will show error » No nodes or no fields for view will show error

  • lobodacyril committed a28f899 on 8.x-2.x
    Issue #3202470: No nodes or no fields for view will show error
    
lobodakyrylo’s picture

Status: Active » Fixed

Now it should work.

lobodakyrylo’s picture

Status: Fixed » Closed (fixed)