Merge pull request #11252 from creative-commoners/pulls/6/protect-hooks2

API Set extension hook implementation visibility to protected
This commit is contained in:
Guy Sartorelli 2024-05-21 11:15:44 +12:00 committed by GitHub
commit 1217806f9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 30 additions and 27 deletions

View File

@ -63,7 +63,7 @@ abstract class DataExtension extends Extension
* *
* See {@link DataObject::onBeforeWrite()} for context. * See {@link DataObject::onBeforeWrite()} for context.
*/ */
public function onBeforeWrite() protected function onBeforeWrite()
{ {
} }
@ -72,7 +72,7 @@ abstract class DataExtension extends Extension
* *
* See {@link DataObject::onAfterWrite()} for context. * See {@link DataObject::onAfterWrite()} for context.
*/ */
public function onAfterWrite() protected function onAfterWrite()
{ {
} }
@ -81,7 +81,7 @@ abstract class DataExtension extends Extension
* *
* See {@link DataObject::onBeforeDelete()} for context. * See {@link DataObject::onBeforeDelete()} for context.
*/ */
public function onBeforeDelete() protected function onBeforeDelete()
{ {
} }
@ -90,7 +90,7 @@ abstract class DataExtension extends Extension
* *
* See {@link DataObject::onAfterDelete()} for context. * See {@link DataObject::onAfterDelete()} for context.
*/ */
public function onAfterDelete() protected function onAfterDelete()
{ {
} }

View File

@ -532,7 +532,7 @@ class Group extends DataObject
return $validator; return $validator;
} }
public function onBeforeWrite() protected function onBeforeWrite()
{ {
parent::onBeforeWrite(); parent::onBeforeWrite();
@ -547,7 +547,7 @@ class Group extends DataObject
$this->dedupeCode(); $this->dedupeCode();
} }
public function onBeforeDelete() protected function onBeforeDelete()
{ {
parent::onBeforeDelete(); parent::onBeforeDelete();

View File

@ -733,7 +733,7 @@ class Member extends DataObject
/** /**
* Event handler called before writing to the database. * Event handler called before writing to the database.
*/ */
public function onBeforeWrite() protected function onBeforeWrite()
{ {
// Remove any line-break or space characters accidentally added during a copy-paste operation // Remove any line-break or space characters accidentally added during a copy-paste operation
if ($this->Email) { if ($this->Email) {
@ -818,7 +818,7 @@ class Member extends DataObject
parent::onBeforeWrite(); parent::onBeforeWrite();
} }
public function onAfterWrite() protected function onAfterWrite()
{ {
parent::onAfterWrite(); parent::onAfterWrite();
@ -829,7 +829,7 @@ class Member extends DataObject
} }
} }
public function onAfterDelete() protected function onAfterDelete()
{ {
parent::onAfterDelete(); parent::onAfterDelete();

View File

@ -636,7 +636,7 @@ class Permission extends DataObject implements TemplateGlobalProvider, Resettabl
} }
} }
public function onBeforeWrite() protected function onBeforeWrite()
{ {
parent::onBeforeWrite(); parent::onBeforeWrite();

View File

@ -69,7 +69,7 @@ class PermissionRole extends DataObject
return $fields; return $fields;
} }
public function onAfterDelete() protected function onAfterDelete()
{ {
parent::onAfterDelete(); parent::onAfterDelete();

View File

@ -25,7 +25,7 @@ class ControllerExtension extends Extension implements TestOnly
/** /**
* Called whenever there is an HTTP error * Called whenever there is an HTTP error
*/ */
public function onBeforeHTTPError() protected function onBeforeHTTPError()
{ {
self::$called_error = true; self::$called_error = true;
} }

View File

@ -38,7 +38,7 @@ class ControllerExtension extends Extension
* @param string $name * @param string $name
* @param array $context * @param array $context
*/ */
public function updateFormActions(FieldList &$actions, Controller $controller, $name, $context = []) protected function updateFormActions(FieldList &$actions, Controller $controller, $name, $context = [])
{ {
// Add publish button if record is versioned // Add publish button if record is versioned
if (empty($context['Record'])) { if (empty($context['Record'])) {
@ -59,7 +59,7 @@ class ControllerExtension extends Extension
* @param string $name * @param string $name
* @param array $context * @param array $context
*/ */
public function updateFormFields(FieldList &$fields, Controller $controller, $name, $context = []) protected function updateFormFields(FieldList &$fields, Controller $controller, $name, $context = [])
{ {
// Add preview link // Add preview link
if (empty($context['Record'])) { if (empty($context['Record'])) {

View File

@ -12,7 +12,7 @@ class FieldValidationExtension extends Extension implements TestOnly
protected bool $triggerTestValidationError = false; protected bool $triggerTestValidationError = false;
public function updateValidationResult(bool &$result, Validator $validator) protected function updateValidationResult(bool &$result, Validator $validator)
{ {
if ($this->excludeFromValidation) { if ($this->excludeFromValidation) {
$result = true; $result = true;

View File

@ -8,7 +8,7 @@ use SilverStripe\Dev\TestOnly;
class TestExtension extends Extension implements TestOnly class TestExtension extends Extension implements TestOnly
{ {
public function updateAttributes(&$attrs) protected function updateAttributes(&$attrs)
{ {
$attrs['extended'] = true; $attrs['extended'] = true;
} }

View File

@ -13,7 +13,7 @@ class ArticleExtension extends DataExtension implements TestOnly
'ExtendedField' => 'Varchar' 'ExtendedField' => 'Varchar'
]; ];
public function updateCMSFields(FieldList $fields) protected function updateCMSFields(FieldList $fields)
{ {
$fields->addFieldToTab( $fields->addFieldToTab(
'Root.Main', 'Root.Main',

View File

@ -9,7 +9,7 @@ use SilverStripe\Forms\Tests\GridField\GridFieldTest\StadiumExtension;
class StadiumExtension extends DataExtension implements TestOnly class StadiumExtension extends DataExtension implements TestOnly
{ {
public function updateSearchableFields(&$fields) protected function updateSearchableFields(&$fields)
{ {
$fields['Type']['filter'] = new FulltextFilter(); $fields['Type']['filter'] = new FulltextFilter();
} }

View File

@ -17,7 +17,7 @@ class CMSFieldsBaseExtension extends DataExtension implements TestOnly
'ExtendedFieldRemove' => 'Varchar(255)' 'ExtendedFieldRemove' => 'Varchar(255)'
]; ];
public function updateCMSFields(FieldList $fields) protected function updateCMSFields(FieldList $fields)
{ {
$fields->addFieldToTab('Root.Test', new TextField('ExtendedFieldRemove')); $fields->addFieldToTab('Root.Test', new TextField('ExtendedFieldRemove'));
$fields->addFieldToTab('Root.Test', new TextField('ExtendedFieldKeep')); $fields->addFieldToTab('Root.Test', new TextField('ExtendedFieldKeep'));

View File

@ -24,7 +24,7 @@ class Team_Extension extends DataExtension implements TestOnly
return "extended dynamic field"; return "extended dynamic field";
} }
public function augmentHydrateFields() protected function augmentHydrateFields()
{ {
return [ return [
'CustomHydratedField' => true, 'CustomHydratedField' => true,

View File

@ -7,7 +7,7 @@ use SilverStripe\Dev\TestOnly;
class ExtraKeysExtension extends Extension implements TestOnly class ExtraKeysExtension extends Extension implements TestOnly
{ {
public function cacheKeyComponent(): string protected function cacheKeyComponent(): string
{ {
return 'extra-key'; return 'extra-key';
} }

View File

@ -34,6 +34,7 @@ use SilverStripe\Security\RememberLoginHash;
use SilverStripe\Security\Security; use SilverStripe\Security\Security;
use SilverStripe\Security\Tests\MemberTest\FieldsExtension; use SilverStripe\Security\Tests\MemberTest\FieldsExtension;
use SilverStripe\SessionManager\Models\LoginSession; use SilverStripe\SessionManager\Models\LoginSession;
use ReflectionMethod;
class MemberTest extends FunctionalTest class MemberTest extends FunctionalTest
{ {
@ -1605,7 +1606,9 @@ class MemberTest extends FunctionalTest
$this->assertFalse($fail, 'Missing FirstName'); $this->assertFalse($fail, 'Missing FirstName');
$ext = new MemberTest\ValidatorExtension(); $ext = new MemberTest\ValidatorExtension();
$ext->updateValidator($validator); $method = new ReflectionMethod(MemberTest\ValidatorExtension::class, 'updateValidator');
$method->setAccessible(true);
$method->invokeArgs($ext, [$validator]);
$pass = $validator->php( $pass = $validator->php(
[ [

View File

@ -10,7 +10,7 @@ use SilverStripe\ORM\DataExtension;
*/ */
class AlwaysFailExtension extends DataExtension implements TestOnly class AlwaysFailExtension extends DataExtension implements TestOnly
{ {
public function updatePHP($data, $form) protected function updatePHP($data, $form)
{ {
return false; return false;
} }

View File

@ -11,7 +11,7 @@ use SilverStripe\ORM\ValidationResult;
*/ */
class ExtendedChangePasswordExtension extends DataExtension implements TestOnly class ExtendedChangePasswordExtension extends DataExtension implements TestOnly
{ {
public function onBeforeChangePassword($newPassword, $valid) protected function onBeforeChangePassword($newPassword, $valid)
{ {
$valid->addError('Extension failed to handle Mary changing her password'); $valid->addError('Extension failed to handle Mary changing her password');
} }

View File

@ -9,7 +9,7 @@ use SilverStripe\ORM\DataExtension;
class FieldsExtension extends DataExtension implements TestOnly class FieldsExtension extends DataExtension implements TestOnly
{ {
public function updateCMSFields(FieldList $fields) protected function updateCMSFields(FieldList $fields)
{ {
$fields->addFieldToTab('Root.Main', new TextField('TestMemberField', 'Test')); $fields->addFieldToTab('Root.Main', new TextField('TestMemberField', 'Test'));
} }

View File

@ -10,7 +10,7 @@ use SilverStripe\ORM\DataExtension;
*/ */
class SurnameMustMatchFirstNameExtension extends DataExtension implements TestOnly class SurnameMustMatchFirstNameExtension extends DataExtension implements TestOnly
{ {
public function updatePHP($data, $form) protected function updatePHP($data, $form)
{ {
return $data['FirstName'] == $data['Surname']; return $data['FirstName'] == $data['Surname'];
} }

View File

@ -8,7 +8,7 @@ use SilverStripe\ORM\DataExtension;
class ValidatorExtension extends DataExtension implements TestOnly class ValidatorExtension extends DataExtension implements TestOnly
{ {
public function updateValidator(&$validator) protected function updateValidator($validator)
{ {
$validator->addRequiredField('Surname'); $validator->addRequiredField('Surname');
$validator->removeRequiredField('FirstName'); $validator->removeRequiredField('FirstName');