From 81a65c03a2c96b7f82b1a04570123ce630674089 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 5 Jun 2024 16:34:03 +1200 Subject: [PATCH] ENH Use class name instead of self --- src/Controllers/LinkFieldController.php | 4 ++-- src/Models/Link.php | 6 +++--- .../LinkFieldControllerTest/TestPhoneLink.php | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Controllers/LinkFieldController.php b/src/Controllers/LinkFieldController.php index 1bf03f76..f540803e 100644 --- a/src/Controllers/LinkFieldController.php +++ b/src/Controllers/LinkFieldController.php @@ -59,7 +59,7 @@ public function getClientConfig(): array 'dataUrl' => $this->Link('data'), 'sortUrl' => $this->Link('sort'), 'saveMethod' => 'post', - 'formNameTemplate' => sprintf(self::FORM_NAME_TEMPLATE, '{id}'), + 'formNameTemplate' => sprintf(LinkFieldController::FORM_NAME_TEMPLATE, '{id}'), ]; return $clientConfig; } @@ -319,7 +319,7 @@ private function createLinkForm(Link $link, string $operation, bool $excludeLink // Create the form $formFactory = Injector::inst()->get(DefaultFormFactory::class); - $name = sprintf(self::FORM_NAME_TEMPLATE, $id); + $name = sprintf(LinkFieldController::FORM_NAME_TEMPLATE, $id); /** @var Form $form */ $form = $formFactory->getForm($this, $name, ['Record' => $link]); $owner = $this->getOwnerFromRequest(); diff --git a/src/Models/Link.php b/src/Models/Link.php index 79729b11..04bd7322 100644 --- a/src/Models/Link.php +++ b/src/Models/Link.php @@ -72,7 +72,7 @@ public function getCMSFields(): FieldList $linkTextField = $fields->dataFieldByName('LinkText'); $linkTextField->setTitle(_t(__CLASS__ . '.LINK_TEXT_TITLE', 'Link text')); $linkTextField->setTitleTip(new Tip(_t( - self::class . '.LINK_TEXT_TEXT_DESCRIPTION', + Link::class . '.LINK_TEXT_TEXT_DESCRIPTION', 'If left blank, an appropriate default will be used on the front-end', ))); @@ -191,7 +191,7 @@ public function onBeforeWrite(): void // Ensure a Sort value is set and that it's one larger than any other Sort value for // this owner relation so that newly created Links on MultiLinkField's are properly sorted if (!$this->Sort) { - $this->Sort = self::get()->filter([ + $this->Sort = Link::get()->filter([ 'OwnerID' => $this->OwnerID, 'OwnerRelation' => $this->OwnerRelation, ])->max('Sort') + 1; @@ -232,7 +232,7 @@ public function forTemplate() { // First look for a subclass of the email template e.g. EmailLink.ss which may be defined // in a project. Fallback to using the generic Link.ss template which this module provides - return $this->renderWith([static::class, self::class]); + return $this->renderWith([static::class, Link::class]); } /** diff --git a/tests/php/Controllers/LinkFieldControllerTest/TestPhoneLink.php b/tests/php/Controllers/LinkFieldControllerTest/TestPhoneLink.php index 23fc6fb3..c740e1e1 100644 --- a/tests/php/Controllers/LinkFieldControllerTest/TestPhoneLink.php +++ b/tests/php/Controllers/LinkFieldControllerTest/TestPhoneLink.php @@ -25,28 +25,28 @@ public function getDescription(): string public function canView($member = null) { - return self::$fail !== 'can-view'; + return TestPhoneLink::$fail !== 'can-view'; } public function canCreate($member = null, $context = []) { - return self::$fail !== 'can-create'; + return TestPhoneLink::$fail !== 'can-create'; } public function canEdit($member = null, $context = []) { - return self::$fail !== 'can-edit'; + return TestPhoneLink::$fail !== 'can-edit'; } public function canDelete($member = null) { - return self::$fail !== 'can-delete'; + return TestPhoneLink::$fail !== 'can-delete'; } public function validate(): ValidationResult { $validationResult = parent::validate(); - if (self::$fail === 'validate') { + if (TestPhoneLink::$fail === 'validate') { $validationResult->addFieldError('Fail', 'Fail was validate'); } return $validationResult;