public function ContextCreatorTrait::isValidContext in Commerce Stock 8
Checks that the context returned is valid for $entity.
This is to support UI calls.
Parameters
\Drupal\commerce\PurchasableEntityInterface $entity: The purchasable entity (most likely a product variation entity).
Return value
bool TRUE if valid, FALSE if not.
2 calls to ContextCreatorTrait::isValidContext()
- AbsoluteStockLevelWidget::formElement in modules/
field/ src/ Plugin/ Field/ FieldWidget/ AbsoluteStockLevelWidget.php - Returns the form for a single field widget.
- StockLevelWidgetBase::formElement in modules/
field/ src/ Plugin/ Field/ FieldWidget/ StockLevelWidgetBase.php - Returns the form for a single field widget.
File
- src/
ContextCreatorTrait.php, line 42
Class
- ContextCreatorTrait
- Provides trait to create a commerce context object from a purchasable entity.
Namespace
Drupal\commerce_stockCode
public function isValidContext(PurchasableEntityInterface $entity) {
try {
$this
->getContextDetails($entity);
} catch (\Exception $e) {
return FALSE;
}
return TRUE;
}