I am tring to figure out when sales_order_save_before is dispatched but I do not see it in the source.
What class is responsible for dispatching this event?
The event sales_order_save_before is been dispatched when an entity of Sales Order is been saved.
The class which is reponsible for dispatching sales_order_save_before event is the model of order Magento\Sales\Model\Order. In order to get to the dispatch statement, you need to look for the beforeSave method into inheritance heirarchy of this model. If you do so, you will end up in Magento\Framework\Model\AbstractModel class which contains the save, beforeSave and afterSave methods.
public function beforeSave()
{
if (!$this->getId()) {
$this->isObjectNew(true);
}
$this->_eventManager->dispatch('model_save_before', ['object' => $this]);
$this->_eventManager->dispatch($this->_eventPrefix . '_save_before', $this->_getEventData());
return $this;
}
Just above the return statement in beforeSave method the eventManager is dispatching this event by concating the eventPrefix which is sales_order for Order entity declared in its Model class.
I have found that this event are dispatched in Magento\Framework\Model\AbstractModel.php
/**
* Processing object before save data
*
* @return $this
*/
public function beforeSave()
{
if (!$this->getId()) {
$this->isObjectNew(true);
}
$this->_eventManager->dispatch('model_save_before', ['object' => $this]);
$this->_eventManager->dispatch($this->_eventPrefix . '_save_before', $this->_getEventData());
return $this;
}
As you can see its dynamicly created at this line
$this->_eventManager->dispatch($this->_eventPrefix . '_save_before', $this->_getEventData());