mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
API Standardise extension hooks (#11339)
This commit is contained in:
parent
e3508d41d5
commit
e1428f27a2
@ -21,7 +21,7 @@ class DatabaseAdminExtension extends Extension
|
|||||||
* @param bool $testMode
|
* @param bool $testMode
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
public function onAfterBuild(bool $quiet, bool $populate, bool $testMode): void
|
protected function onAfterBuild(bool $quiet, bool $populate, bool $testMode): void
|
||||||
{
|
{
|
||||||
$service = RelationValidationService::singleton();
|
$service = RelationValidationService::singleton();
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ abstract class DataExtension extends Extension
|
|||||||
* @param ValidationResult $validationResult Local validation result
|
* @param ValidationResult $validationResult Local validation result
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
public function validate(ValidationResult $validationResult)
|
protected function updateValidate(ValidationResult $validationResult)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ abstract class DataExtension extends Extension
|
|||||||
*
|
*
|
||||||
* See {@link DataObject::requireDefaultRecords()} for context.
|
* See {@link DataObject::requireDefaultRecords()} for context.
|
||||||
*/
|
*/
|
||||||
public function requireDefaultRecords()
|
protected function onRequireDefaultRecords()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ abstract class DataExtension extends Extension
|
|||||||
*
|
*
|
||||||
* See {@link DataObject::populateDefaults()} for context.
|
* See {@link DataObject::populateDefaults()} for context.
|
||||||
*/
|
*/
|
||||||
public function populateDefaults()
|
protected function onAfterPopulateDefaults()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ abstract class DataExtension extends Extension
|
|||||||
*
|
*
|
||||||
* See {@link DataObject::onAfterBuild()} for context.
|
* See {@link DataObject::onAfterBuild()} for context.
|
||||||
*/
|
*/
|
||||||
public function onAfterBuild()
|
protected function onAfterBuild()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ abstract class DataExtension extends Extension
|
|||||||
* @param Member $member
|
* @param Member $member
|
||||||
* @return bool|null
|
* @return bool|null
|
||||||
*/
|
*/
|
||||||
public function can($member)
|
protected function can($member)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ abstract class DataExtension extends Extension
|
|||||||
* @param Member $member
|
* @param Member $member
|
||||||
* @return bool|null
|
* @return bool|null
|
||||||
*/
|
*/
|
||||||
public function canEdit($member)
|
protected function canEdit($member)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ abstract class DataExtension extends Extension
|
|||||||
* @param Member $member
|
* @param Member $member
|
||||||
* @return bool|null
|
* @return bool|null
|
||||||
*/
|
*/
|
||||||
public function canDelete($member)
|
protected function canDelete($member)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,7 +186,7 @@ abstract class DataExtension extends Extension
|
|||||||
* @param Member $member
|
* @param Member $member
|
||||||
* @return bool|null
|
* @return bool|null
|
||||||
*/
|
*/
|
||||||
public function canCreate($member)
|
protected function canCreate($member)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1228,7 +1228,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
public function validate()
|
public function validate()
|
||||||
{
|
{
|
||||||
$result = ValidationResult::create();
|
$result = ValidationResult::create();
|
||||||
$this->extend('validate', $result);
|
$this->extend('updateValidate', $result);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1311,7 +1311,6 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
* Will traverse the defaults of the current class and all its parent classes.
|
* Will traverse the defaults of the current class and all its parent classes.
|
||||||
* Called by the constructor when creating new records.
|
* Called by the constructor when creating new records.
|
||||||
*
|
*
|
||||||
* @uses DataExtension::populateDefaults()
|
|
||||||
* @return static $this
|
* @return static $this
|
||||||
*/
|
*/
|
||||||
public function populateDefaults()
|
public function populateDefaults()
|
||||||
@ -1348,7 +1347,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->extend('populateDefaults');
|
$this->extend('onAfterPopulateDefaults');
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3542,7 +3541,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->extend('flushCache');
|
$this->extend('onFlushCache');
|
||||||
|
|
||||||
$this->components = [];
|
$this->components = [];
|
||||||
$this->eagerLoadedData = [];
|
$this->eagerLoadedData = [];
|
||||||
@ -3800,7 +3799,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Let any extensions make their own database default data
|
// Let any extensions make their own database default data
|
||||||
$this->extend('requireDefaultRecords', $dummy);
|
$this->extend('onRequireDefaultRecords', $dummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -116,7 +116,7 @@ class Hierarchy extends DataExtension
|
|||||||
*
|
*
|
||||||
* @param ValidationResult $validationResult
|
* @param ValidationResult $validationResult
|
||||||
*/
|
*/
|
||||||
public function validate(ValidationResult $validationResult)
|
protected function updateValidate(ValidationResult $validationResult)
|
||||||
{
|
{
|
||||||
// The object is new, won't be looping.
|
// The object is new, won't be looping.
|
||||||
$owner = $this->owner;
|
$owner = $this->owner;
|
||||||
@ -572,7 +572,7 @@ class Hierarchy extends DataExtension
|
|||||||
* - Children (instance)
|
* - Children (instance)
|
||||||
* - NumChildren (instance)
|
* - NumChildren (instance)
|
||||||
*/
|
*/
|
||||||
public function flushCache()
|
protected function onFlushCache()
|
||||||
{
|
{
|
||||||
$this->owner->_cache_children = null;
|
$this->owner->_cache_children = null;
|
||||||
Hierarchy::$cache_numChildren = [];
|
Hierarchy::$cache_numChildren = [];
|
||||||
|
@ -23,7 +23,7 @@ class InheritedPermissionFlusher extends DataExtension implements Flushable
|
|||||||
*/
|
*/
|
||||||
public static function flush()
|
public static function flush()
|
||||||
{
|
{
|
||||||
singleton(__CLASS__)->flushCache();
|
singleton(__CLASS__)->onFlushCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,7 +77,7 @@ class InheritedPermissionFlusher extends DataExtension implements Flushable
|
|||||||
/**
|
/**
|
||||||
* Flushes all registered MemberCacheFlusher services
|
* Flushes all registered MemberCacheFlusher services
|
||||||
*/
|
*/
|
||||||
public function flushCache()
|
protected function onFlushCache()
|
||||||
{
|
{
|
||||||
$ids = $this->getMemberIDList();
|
$ids = $this->getMemberIDList();
|
||||||
foreach ($this->getServices() as $service) {
|
foreach ($this->getServices() as $service) {
|
||||||
|
@ -452,7 +452,7 @@ class Member extends DataObject
|
|||||||
*/
|
*/
|
||||||
public function beforeMemberLoggedIn()
|
public function beforeMemberLoggedIn()
|
||||||
{
|
{
|
||||||
$this->extend('beforeMemberLoggedIn');
|
$this->extend('onBeforeMemberLoggedIn');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -470,7 +470,7 @@ class Member extends DataObject
|
|||||||
$this->write();
|
$this->write();
|
||||||
|
|
||||||
// Audit logging hook
|
// Audit logging hook
|
||||||
$this->extend('afterMemberLoggedIn');
|
$this->extend('onAfterMemberLoggedIn');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -497,7 +497,7 @@ class Member extends DataObject
|
|||||||
*/
|
*/
|
||||||
public function beforeMemberLoggedOut(HTTPRequest $request = null)
|
public function beforeMemberLoggedOut(HTTPRequest $request = null)
|
||||||
{
|
{
|
||||||
$this->extend('beforeMemberLoggedOut', $request);
|
$this->extend('onBeforeMemberLoggedOut', $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -507,7 +507,7 @@ class Member extends DataObject
|
|||||||
*/
|
*/
|
||||||
public function afterMemberLoggedOut(HTTPRequest $request = null)
|
public function afterMemberLoggedOut(HTTPRequest $request = null)
|
||||||
{
|
{
|
||||||
$this->extend('afterMemberLoggedOut', $request);
|
$this->extend('onAfterMemberLoggedOut', $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1709,7 +1709,7 @@ class Member extends DataObject
|
|||||||
$this->FailedLoginCount = 0;
|
$this->FailedLoginCount = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->extend('registerFailedLogin');
|
$this->extend('onRegisterFailedLogin');
|
||||||
$this->write();
|
$this->write();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ class LostPasswordHandler extends RequestHandler
|
|||||||
/**
|
/**
|
||||||
* Forgot password form handler method.
|
* Forgot password form handler method.
|
||||||
* Called when the user clicks on "I've lost my password".
|
* Called when the user clicks on "I've lost my password".
|
||||||
* Extensions can use the 'forgotPassword' method to veto executing
|
* Extensions can use the 'onForgotPassword' method to veto executing
|
||||||
* the logic, by returning FALSE. In this case, the user will be redirected back
|
* the logic, by returning FALSE. In this case, the user will be redirected back
|
||||||
* to the form without further action. It is recommended to set a message
|
* to the form without further action. It is recommended to set a message
|
||||||
* in the form detailing why the action was denied.
|
* in the form detailing why the action was denied.
|
||||||
@ -168,7 +168,7 @@ class LostPasswordHandler extends RequestHandler
|
|||||||
$member = $this->getMemberFromData($data);
|
$member = $this->getMemberFromData($data);
|
||||||
|
|
||||||
// Allow vetoing forgot password requests
|
// Allow vetoing forgot password requests
|
||||||
$results = $this->extend('forgotPassword', $member);
|
$results = $this->extend('onForgotPassword', $member);
|
||||||
if ($results && is_array($results) && in_array(false, $results ?? [], true)) {
|
if ($results && is_array($results) && in_array(false, $results ?? [], true)) {
|
||||||
return $this->redirectToLostPassword();
|
return $this->redirectToLostPassword();
|
||||||
}
|
}
|
||||||
|
@ -195,18 +195,18 @@ class MemberAuthenticator implements Authenticator
|
|||||||
$attempt->Status = LoginAttempt::SUCCESS;
|
$attempt->Status = LoginAttempt::SUCCESS;
|
||||||
|
|
||||||
// Audit logging hook
|
// Audit logging hook
|
||||||
$member->extend('authenticationSucceeded');
|
$member->extend('onAuthenticationSucceeded');
|
||||||
} else {
|
} else {
|
||||||
// Failed login - we're trying to see if a user exists with this email (disregarding wrong passwords)
|
// Failed login - we're trying to see if a user exists with this email (disregarding wrong passwords)
|
||||||
$attempt->Status = LoginAttempt::FAILURE;
|
$attempt->Status = LoginAttempt::FAILURE;
|
||||||
if ($member) {
|
if ($member) {
|
||||||
// Audit logging hook
|
// Audit logging hook
|
||||||
$attempt->MemberID = $member->ID;
|
$attempt->MemberID = $member->ID;
|
||||||
$member->extend('authenticationFailed', $data, $request);
|
$member->extend('onAuthenticationFailed', $data, $request);
|
||||||
} else {
|
} else {
|
||||||
// Audit logging hook
|
// Audit logging hook
|
||||||
Member::singleton()
|
Member::singleton()
|
||||||
->extend('authenticationFailedUnknownUser', $data, $request);
|
->extend('onAuthenticationFailedUnknownUser', $data, $request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,9 +23,9 @@ use SilverStripe\View\Requirements;
|
|||||||
* Log-in form for the "member" authentication method.
|
* Log-in form for the "member" authentication method.
|
||||||
*
|
*
|
||||||
* Available extension points:
|
* Available extension points:
|
||||||
* - "authenticationFailed": Called when login was not successful.
|
* - "onAuthenticationFailed": Called when login was not successful.
|
||||||
* Arguments: $data containing the form submission
|
* Arguments: $data containing the form submission
|
||||||
* - "forgotPassword": Called before forgot password logic kicks in,
|
* - "onForgotPassword": Called before forgot password logic kicks in,
|
||||||
* allowing extensions to "veto" execution by returning FALSE.
|
* allowing extensions to "veto" execution by returning FALSE.
|
||||||
* Arguments: $member containing the detected Member record
|
* Arguments: $member containing the detected Member record
|
||||||
*/
|
*/
|
||||||
|
@ -8,17 +8,17 @@ use SilverStripe\ORM\DataExtension;
|
|||||||
class Extension1 extends DataExtension implements TestOnly
|
class Extension1 extends DataExtension implements TestOnly
|
||||||
{
|
{
|
||||||
|
|
||||||
public function canOne($member = null)
|
protected function canOne($member = null)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canTwo($member = null)
|
protected function canTwo($member = null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canThree($member = null)
|
protected function canThree($member = null)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,17 +8,17 @@ use SilverStripe\ORM\DataExtension;
|
|||||||
class Extension2 extends DataExtension implements TestOnly
|
class Extension2 extends DataExtension implements TestOnly
|
||||||
{
|
{
|
||||||
|
|
||||||
public function canOne($member = null)
|
protected function canOne($member = null)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canTwo($member = null)
|
protected function canTwo($member = null)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canThree($member = null)
|
protected function canThree($member = null)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,17 +8,17 @@ use SilverStripe\ORM\DataExtension;
|
|||||||
class EditingAllowedDeletingDeniedExtension extends DataExtension implements TestOnly
|
class EditingAllowedDeletingDeniedExtension extends DataExtension implements TestOnly
|
||||||
{
|
{
|
||||||
|
|
||||||
public function canView($member = null)
|
protected function canView($member = null)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canEdit($member = null)
|
protected function canEdit($member = null)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canDelete($member = null)
|
protected function canDelete($member = null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ use SilverStripe\ORM\DataExtension;
|
|||||||
class ViewingAllowedExtension extends DataExtension implements TestOnly
|
class ViewingAllowedExtension extends DataExtension implements TestOnly
|
||||||
{
|
{
|
||||||
|
|
||||||
public function canView($member = null)
|
protected function canView($member = null)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ use SilverStripe\ORM\DataExtension;
|
|||||||
class ViewingDeniedExtension extends DataExtension implements TestOnly
|
class ViewingDeniedExtension extends DataExtension implements TestOnly
|
||||||
{
|
{
|
||||||
|
|
||||||
public function canView($member = null)
|
protected function canView($member = null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user