1

I wrote code that should display the hard-coded value $name in $row to the view field.

    public function execute(ViewExecutable $view) { 
      $name = 'Jackie Chan';
      $index = 0;
      foreach ($data as $name) {
        $data = $data->toArray();
        $row['name'] = $name;
        $row['index'] = $index++;
        $view->result[] = new ResultRow($row);
      }
    }

$row['name'] is a field set in the view.

To what I understand of how my code runs, $name with value Jackie Chan is assigned to $row['name']. Then it creates a new ResultRow object with the $row variable and add it to $view->result. Finally I should be getting the value of $name in the view field UI as result.

I'm getting no results at all. The code is causing the following errors.

Strict warning: Declaration of Drupal\cvr_views\Plugin\views\query\Cvr::execute() should be compatible with Drupal\views\Plugin\views\query\QueryPluginBase::execute(Drupal\views\ViewExecutable $view) in include() (line 17 of /Applications/MAMP/htdocs/query/modules/custom/cvr_views/src/Plugin/views/query/CVR.php) #0 /Applications/MAMP/htdocs/query/core/includes/bootstrap.inc(548): _drupal_error_handler_real(2048, 'Declaration of ...', '/Applications/M...', 17, Array) #1 /Applications/MAMP/htdocs/query/modules/custom/cvr_views/src/Plugin/views/query/CVR.php(17): _drupal_error_handler(2048, 'Declaration of ...', '/Applications/M...', 17, Array) #2 /Applications/MAMP/htdocs/query/vendor/composer/ClassLoader.php(440): include('/Applications/M...') #3 /Applications/MAMP/htdocs/query/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile('/Applications/M...') #4 [internal function]: Composer\Autoload\ClassLoader->loadClass('Drupal\cvr_view...') #5 [internal function]: spl_autoload_call('Drupal\cvr_view...') #6 /Applications/MAMP/htdocs/query/core/lib/Drupal/Component/Plugin/Factory/DefaultFactory.php(96): class_exists('Drupal\cvr_view...') #7 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/Plugin/Factory/ContainerFactory.php(17): Drupal\Component\Plugin\Factory\DefaultFactory::getPluginClass('cvr', Array, 'Drupal\views\Pl...') #8 /Applications/MAMP/htdocs/query/core/lib/Drupal/Component/Plugin/PluginManagerBase.php(84): Drupal\Core\Plugin\Factory\ContainerFactory->createInstance('cvr', Array) #9 /Applications/MAMP/htdocs/query/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php(810): Drupal\Component\Plugin\PluginManagerBase->createInstance('cvr') #10 /Applications/MAMP/htdocs/query/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php(2445): Drupal\views\Plugin\views\display\DisplayPluginBase->getPlugin('query') #11 /Applications/MAMP/htdocs/query/core/modules/views/src/ViewExecutable.php(2099): Drupal\views\Plugin\views\display\DisplayPluginBase->validate() #12 /Applications/MAMP/htdocs/query/core/modules/views_ui/src/ViewFormBase.php(125): Drupal\views\ViewExecutable->validate() #13 /Applications/MAMP/htdocs/query/core/modules/views_ui/src/ViewFormBase.php(49): Drupal\views_ui\ViewFormBase->getDisplayTabs(Object(Drupal\views_ui\ViewUI)) #14 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/Entity/EntityForm.php(134): Drupal\views_ui\ViewFormBase->prepareEntity() #15 /Applications/MAMP/htdocs/query/core/modules/views_ui/src/ViewFormBase.php(26): Drupal\Core\Entity\EntityForm->init(Object(Drupal\Core\Form\FormState)) #16 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/Entity/EntityForm.php(105): Drupal\views_ui\ViewFormBase->init(Object(Drupal\Core\Form\FormState)) #17 /Applications/MAMP/htdocs/query/core/modules/views_ui/src/ViewFormBase.php(41): Drupal\Core\Entity\EntityForm->buildForm(Array, Object(Drupal\Core\Form\FormState)) #18 [internal function]: Drupal\views_ui\ViewFormBase->buildForm(Array, Object(Drupal\Core\Form\FormState), 'page_1') #19 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/Form/FormBuilder.php(514): call_user_func_array(Array, Array) #20 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/Form/FormBuilder.php(271): Drupal\Core\Form\FormBuilder->retrieveForm('view_preview_fo...', Object(Drupal\Core\Form\FormState)) #21 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/Controller/FormController.php(74): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\views_ui\ViewPreviewForm), Object(Drupal\Core\Form\FormState)) #22 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch)) #23 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #24 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/Render/Renderer.php(574): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber{closure}() #25 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #26 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #27 [internal function]: Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber{closure}() #28 /Applications/MAMP/htdocs/query/vendor/symfony/http-kernel/HttpKernel.php(139): call_user_func_array(Object(Closure), Array) #29 /Applications/MAMP/htdocs/query/vendor/symfony/http-kernel/HttpKernel.php(62): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #30 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #31 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #32 /Applications/MAMP/htdocs/query/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #33 /Applications/MAMP/htdocs/query/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #34 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #35 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(50): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #36 /Applications/MAMP/htdocs/query/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #37 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/DrupalKernel.php(652): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #38 /Applications/MAMP/htdocs/query/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #39 {main}.

Recoverable fatal error: Argument 1 passed to Drupal\cvr_views\Plugin\views\query\Cvr::execute() must be an instance of Drupal\cvr_views\Plugin\views\query\ViewExecutable, instance of Drupal\views\ViewExecutable given, called in /Applications/MAMP/htdocs/query/core/modules/views/src/ViewExecutable.php on line 1413 and defined in Drupal\cvr_views\Plugin\views\query\Cvr->execute() (line 19 of /Applications/MAMP/htdocs/query/modules/custom/cvr_views/src/Plugin/views/query/CVR.php) #0 /Applications/MAMP/htdocs/query/core/includes/bootstrap.inc(548): _drupal_error_handler_real(4096, 'Argument 1 pass...', '/Applications/M...', 19, Array) #1 /Applications/MAMP/htdocs/query/modules/custom/cvr_views/src/Plugin/views/query/CVR.php(19): _drupal_error_handler(4096, 'Argument 1 pass...', '/Applications/M...', 19, Array) #2 /Applications/MAMP/htdocs/query/core/modules/views/src/ViewExecutable.php(1413): Drupal\cvr_views\Plugin\views\query\Cvr->execute(Object(Drupal\views\ViewExecutable)) #3 /Applications/MAMP/htdocs/query/core/modules/views/src/ViewExecutable.php(1441): Drupal\views\ViewExecutable->execute(NULL) #4 /Applications/MAMP/htdocs/query/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php(2391): Drupal\views\ViewExecutable->render() #5 /Applications/MAMP/htdocs/query/core/modules/views/src/ViewExecutable.php(1649): Drupal\views\Plugin\views\display\DisplayPluginBase->preview() #6 /Applications/MAMP/htdocs/query/core/modules/views_ui/src/ViewUI.php(602): Drupal\views\ViewExecutable->preview('page_1', Array) #7 /Applications/MAMP/htdocs/query/core/modules/views_ui/src/ViewPreviewForm.php(60): Drupal\views_ui\ViewUI->renderPreview('page_1', Array) #8 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/Entity/EntityForm.php(115): Drupal\views_ui\ViewPreviewForm->form(Array, Object(Drupal\Core\Form\FormState)) #9 /Applications/MAMP/htdocs/query/core/modules/views_ui/src/ViewFormBase.php(41): Drupal\Core\Entity\EntityForm->buildForm(Array, Object(Drupal\Core\Form\FormState)) #10 [internal function]: Drupal\views_ui\ViewFormBase->buildForm(Array, Object(Drupal\Core\Form\FormState), 'page_1') #11 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/Form/FormBuilder.php(514): call_user_func_array(Array, Array) #12 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/Form/FormBuilder.php(364): Drupal\Core\Form\FormBuilder->retrieveForm('view_preview_fo...', Object(Drupal\Core\Form\FormState)) #13 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/Form/FormBuilder.php(621): Drupal\Core\Form\FormBuilder->rebuildForm('view_preview_fo...', Object(Drupal\Core\Form\FormState), Array) #14 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/Form/FormBuilder.php(314): Drupal\Core\Form\FormBuilder->processForm('view_preview_fo...', Array, Object(Drupal\Core\Form\FormState)) #15 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/Controller/FormController.php(74): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\views_ui\ViewPreviewForm), Object(Drupal\Core\Form\FormState)) #16 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch)) #17 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array) #18 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/Render/Renderer.php(574): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber{closure}() #19 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure)) #20 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) #21 [internal function]: Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber{closure}() #22 /Applications/MAMP/htdocs/query/vendor/symfony/http-kernel/HttpKernel.php(139): call_user_func_array(Object(Closure), Array) #23 /Applications/MAMP/htdocs/query/vendor/symfony/http-kernel/HttpKernel.php(62): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1) #24 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #25 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #26 /Applications/MAMP/htdocs/query/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #27 /Applications/MAMP/htdocs/query/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true) #28 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #29 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(50): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #30 /Applications/MAMP/htdocs/query/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #31 /Applications/MAMP/htdocs/query/core/lib/Drupal/Core/DrupalKernel.php(652): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #32 /Applications/MAMP/htdocs/query/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request)) #33 {main}.

  • 1
    Just to doublecheck, you used a use statement at the top of your class to include the ViewExecutable class from Views, right? – Kevin Feb 1 '17 at 16:04
  • Yes, your right. I was able to figure it out too. Same with the ResultRow. Thanks you :D – John Rey Tanquinco Feb 2 '17 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.