Problem/Motivation
I am trying to use a Paragraph block with a Views Reference field inside it (flexible page, allows me to place the listing where I would like within the other components).
I'm using 1.6.0 in a site that has been recently upgraded to Drupal 9.
Steps to reproduce
- Add a paragraph
- Add a View Reference field to the paragraph
- Try to add the paragraph to a content item, error is thrown.
The website encountered an unexpected error. Please try again later.
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "entity.manager". in Drupal\Component\DependencyInjection\Container->get() (line 151 of core/lib/Drupal/Component/DependencyInjection/Container.php).
Drupal::service('entity.manager') (Line: 209)
Drupal\viewsreference\Plugin\Field\FieldWidget\ViewsReferenceSelectWidget->getViewDisplayIds('archive') (Line: 54)
Drupal\viewsreference\Plugin\Field\FieldWidget\ViewsReferenceSelectWidget->fieldElement(Array, Object, 0) (Line: 37)
Drupal\viewsreference\Plugin\Field\FieldWidget\ViewsReferenceSelectWidget->formElement(Object, 0, Array, Array, Object) (Line: 342)
Drupal\Core\Field\WidgetBase->formSingleElement(Object, 0, Array, Array, Object) (Line: 209)
Drupal\Core\Field\WidgetBase->formMultipleElements(Object, Array, Object) (Line: 111)
Drupal\Core\Field\WidgetBase->form(Object, Array, Object) (Line: 178)
Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object, Array, Object) (Line: 782)
Drupal\paragraphs\Plugin\Field\FieldWidget\ParagraphsWidget->formElement(Object, 11, Array, Array, Object) (Line: 342)
Drupal\Core\Field\WidgetBase->formSingleElement(Object, 11, Array, Array, Object) (Line: 1129)
Drupal\paragraphs\Plugin\Field\FieldWidget\ParagraphsWidget->formMultipleElements(Object, Array, Object) (Line: 111)
Drupal\Core\Field\WidgetBase->form(Object, Array, Object, NULL) (Line: 1225)
Drupal\paragraphs\Plugin\Field\FieldWidget\ParagraphsWidget->form(Object, Array, Object) (Line: 178)
Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object, Array, Object) (Line: 121)
Drupal\Core\Entity\ContentEntityForm->form(Array, Object) (Line: 127)
Drupal\node\NodeForm->form(Array, Object) (Line: 55)
Drupal\ibp_backend\Form\IbpNodeForm->form(Array, Object) (Line: 106)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 532)
Drupal\Core\Form\FormBuilder->retrieveForm('node_landing_page_edit_form', Object) (Line: 371)
Drupal\Core\Form\FormBuilder->rebuildForm('node_landing_page_edit_form', Object, Array) (Line: 629)
Drupal\Core\Form\FormBuilder->processForm('node_landing_page_edit_form', Array, Object) (Line: 321)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 705)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Proposed resolution
Error is from ViewsReferenceTrait.php:209
Change `entity.manager` to `entity_type.manager`.
Before:
/**
* Helper to get display ids for a particular View.
*/
protected function getViewDisplayIds($view_id) {
$options = [];
$view_plugins = array_diff($this->getFieldSetting('plugin_types'), ["0"]);
if ($view = \Drupal::service('entity.manager')->getStorage('view')->load($view_id)) {
foreach ($view->get('display') as $display) {
if (in_array($display['display_plugin'], $view_plugins)) {
$options[$display['id']] = $display['display_title'];
}
}
}
return $options;
}
After:
/**
* Helper to get display ids for a particular View.
*/
protected function getViewDisplayIds($view_id) {
$options = [];
$view_plugins = array_diff($this->getFieldSetting('plugin_types'), ["0"]);
if ($view = \Drupal::service('entity_type.manager')->getStorage('view')->load($view_id)) {
foreach ($view->get('display') as $display) {
if (in_array($display['display_plugin'], $view_plugins)) {
$options[$display['id']] = $display['display_title'];
}
}
}
return $options;
}
Remaining tasks
- Review the patch
User interface changes
- None
API changes
- None
Data model changes
- None
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 9.x-1.6.patch | 792 bytes | graham73may |
Comments
Comment #2
graham73may commentedPatch file added for reference, however I will be upgrading to 2.x shortly.
Comment #3
scott_euser commentedHappy with this change - makes the 1x branch work correctly in D9 while 2x is still in beta. Thanks!
Comment #4
avpadernoComment #7
seanbThis is fixed.