Problem/Motivation
When changing the order of link / string/ string_long types of fields on the manage display (maybe only in combination with Field Group order changes that messes things up a bit), Field Formatter type can get changed to "Soundcloud embed", resulting in the error shown below.
Proposed resolution
It should actually only be possible to choose that Field Formatter when the field type is a media field.
Remaining tasks
Create a patch and review.
Error message
Error: Call to undefined method Drupal\node\Entity\Node::getSource() in Drupal\media_entity_soundcloud\Plugin\Field\FieldFormatter\SoundcloudEmbedFormatter->viewElements() (line 111 of /var/www/html/web/modules/contrib/media_entity_soundcloud/src/Plugin/Field/FieldFormatter/SoundcloudEmbedFormatter.php)
#0 /var/www/html/web/core/lib/Drupal/Core/Field/FormatterBase.php(80): Drupal\media_entity_soundcloud\Plugin\Field\FieldFormatter\SoundcloudEmbedFormatter->viewElements(Object(Drupal\Core\Field\FieldItemList), 'en')
#1 /var/www/html/web/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php(263): Drupal\Core\Field\FormatterBase->view(Object(Drupal\Core\Field\FieldItemList), 'en')
#2 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityViewBuilder.php(321): Drupal\Core\Entity\Entity\EntityViewDisplay->buildMultiple(Array)
#3 /var/www/html/web/core/modules/node/src/NodeViewBuilder.php(22): Drupal\Core\Entity\EntityViewBuilder->buildComponents(Array, Array, Array, 'popup')
#4 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityViewBuilder.php(263): Drupal\node\NodeViewBuilder->buildComponents(Array, Array, Array, 'popup')
#5 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityViewBuilder.php(220): Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array)
#6 [internal function]: Drupal\Core\Entity\EntityViewBuilder->build(Array)
#7 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(378): call_user_func(Array, Array)
#8 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(195): Drupal\Core\Render\Renderer->doRender(Array, true)
#9 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(139): Drupal\Core\Render\Renderer->render(Array, true)
#10 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}()
#11 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(140): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#12 /var/www/html/web/modules/contrib/leaflet/leaflet_views/src/Controller/LeafletAjaxPopupController.php(85): Drupal\Core\Render\Renderer->renderRoot(Array)
#13 [internal function]: Drupal\leaflet_views\Controller\LeafletAjaxPopupController->popupBuild(Object(Drupal\node\Entity\Node), 'popup', 'en')
#14 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#15 /var/www/html/web/core/lib/Drupal/Core/Render/Renderer.php(582): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#16 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#17 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#18 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#19 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#20 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#21 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#22 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(99): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#23 /var/www/html/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(78): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 /var/www/html/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#26 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#27 /var/www/html/web/core/lib/Drupal/Core/DrupalKernel.php(693): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#28 /var/www/html/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#29 {main}
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | formatter_should_only_be_available_for_media-3031830-2.patch | 901 bytes | sergiu stici |
Comments
Comment #2
sergiu stici commentedI made a patch. Please review.
Comment #4
heliogabalI tested the patch, applied cleanly and now I can't select the soundcloud embed field formatters for fields that are not media.
I can't really test for now if everything still works as it should with an actual soundcloud embed, as I don't use it.
But my initial issue is fixed.
Comment #7
jcisio commentedCommitted and pushed. Thank you.