Without a concrete example of what you are trying to achieve, it would be difficult to tell whether v2 structure would help you in your goal.
However I can try and explain some general principles behind v2.
For observers generally, you are correct in that they only allow you to 'add code' rather than override. However in v2 in some limited circumstances, the observer has access to a 'continuation flag'
e.g.
PHP Code:
$continuationFlag = TRUE;
$this->notify('NOTIFY_SOMETHING', $continuationFlag)
if ($continuationFlag)
{
... do some core code
}
From that if the observer sets $continuationFlag to FALSE then core code will be skipped.
Secondly in a number of places v2 introduces the concept of filter chains. These allow contributions to not only add to core code, but change whether some core code runs as well.
One of the main reasons we added filter chains was to allow contributions to interact with customer registration. The idea being that 3rd party software such as CMS, ERP etc could add customers to their own databases.
some example code
PHP Code:
....
$this->customerFilterChain = array();
$this->customerFilterChain[] = 'standard';
$this->notify('NOTIFY_SET_CUSTOMER_FILTER_CHAIN');
...
function validateLogin ($plain, $encrypted)
{
$this->passwordValidated = FALSE;
$this->pwdPlain = $plain;
$this->pwdSecure = $encrypted;
foreach ($this->customerFilterChain as $filterChain)
{
if ($filterChain != '') zcFilterChain::execute('customer', $filterChain, $this)->init()->executeMethod('validateLogin');
}
return $this->passwordValidated;
}
With the above, and using an observer, a contribution could add its own filter class to the filter chain array that ran after the standard login. However it would also be possible for the contribution to remove the 'standard' filter chain completely and substitute its own code.
Currently filter chains are used in v2 for customer login/registration and for the routing subsytem.
For other core code, there are usually other ways (apart from observers) to extend/override core functionality. In part this is done using overrides, both traditional and some new overrides that plugins have available.
As an example I have written a demo plugin that adds a new field to the customer sign up page (a confirm email address field) that does not touch core code at a all, and using similar methods it would be possible to completely redesign the registration page without touching core code.
HTH
Bookmarks