Problem/Motivation

ShippingProfileWidget::formElement() calls $shipment->getOrder()->getStore() with no null check. Any form built on a shipment without an order throws Call to a member function getStore() on null.

Steps to reproduce

  1. Install Views Bulk Operations and Views Bulk Edit.
  2. Create a view of shipments with the "Modify field values" action.
  3. Select any shipments and run the action.
  4. The configure form fatals. The bulk edit form builds the form display on a new, blank shipment, which has no order.

Proposed resolution

Return the empty $element from formElement() when $shipment->getOrder() is NULL. The widget can't render without an order, which it needs for the store's shipping countries and the customer ID.

Remaining tasks

  • Fix it.

User interface changes

None. The shipping profile isn't offered in forms that have no order.

API changes

None.

Data model changes

None.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tonytheferg created an issue. See original summary.

tonytheferg’s picture

Error: Call to a member function getStore() on null in Drupal\commerce_shipping\Plugin\Field\FieldWidget\ShippingProfileWidget->formElement() (line 89 of /code/web/modules/contrib/commerce_shipping/src/Plugin/Field/FieldWidget/ShippingProfileWidget.php).

#0 /code/web/core/lib/Drupal/Core/Field/WidgetBase.php(459): Drupal\commerce_shipping\Plugin\Field\FieldWidget\ShippingProfileWidget->formElement()
#1 /code/web/core/lib/Drupal/Core/Field/WidgetBase.php(219): Drupal\Core\Field\WidgetBase->formSingleElement()
#2 /code/web/core/lib/Drupal/Core/Field/WidgetBase.php(120): Drupal\Core\Field\WidgetBase->formMultipleElements()
#3 /code/web/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php(190): Drupal\Core\Field\WidgetBase->form()
#4 /code/web/modules/contrib/views_bulk_edit/src/Form/BulkEditFormTrait.php(144): Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm()
#5 /code/web/modules/contrib/views_bulk_edit/src/Form/BulkEditFormTrait.php(93): Drupal\views_bulk_edit\Plugin\Action\ModifyEntityValues->getBundleForm()
#6 /code/web/modules/contrib/views_bulk_edit/src/Plugin/Action/ModifyEntityValues.php(156): Drupal\views_bulk_edit\Plugin\Action\ModifyEntityValues->buildBundleForms()
#7 /code/web/modules/contrib/views_bulk_operations/src/Form/ConfigureAction.php(96): Drupal\views_bulk_edit\Plugin\Action\ModifyEntityValues->buildConfigurationForm()
#8 [internal function]: Drupal\views_bulk_operations\Form\ConfigureAction->buildForm()
#9 /code/web/core/lib/Drupal/Core/Form/FormBuilder.php(536): call_user_func_array()
#10 /code/web/core/lib/Drupal/Core/Form/FormBuilder.php(284): Drupal\Core\Form\FormBuilder->retrieveForm()
#11 /code/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm()
#12 [internal function]: Drupal\Core\Controller\FormController->getContentResult()
#13 /code/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#14 /code/web/core/lib/Drupal/Core/Render/Renderer.php(637): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#15 /code/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext()
#16 /code/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#17 /code/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#18 /code/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#19 /code/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle()
#20 /code/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#21 /code/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#22 /code/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle()
#23 /code/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(116): Drupal\big_pipe\StackMiddleware\ContentLength->handle()
#24 /code/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(90): Drupal\page_cache\StackMiddleware\PageCache->pass()
#25 /code/web/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle()
#26 /code/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle()
#27 /code/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#28 /code/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#29 /code/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
#30 /code/web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
#31 /code/web/index.php(19): Drupal\Core\DrupalKernel->handle()
#32 {main}
tonytheferg’s picture

Version: 3.x-dev » 8.x-2.x-dev
tonytheferg’s picture

Version: 8.x-2.x-dev » 3.x-dev

tonytheferg’s picture

Status: Active » Needs review
tonytheferg’s picture

Guessing this would fix this issue as well...

jsacksick’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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