From 51b178cdb75e1676180620de38608ec59e028c8a Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Fri, 14 Jun 2024 20:33:51 +1200 Subject: [PATCH] ENH Use class name instead of self --- src/Controllers/ElementalAreaController.php | 2 +- src/Extensions/ElementalAreasExtension.php | 4 ++-- src/Extensions/ElementalPageExtension.php | 10 +++++----- src/Forms/EditFormFactory.php | 4 ++-- src/Models/BaseElement.php | 8 ++++---- src/Services/ElementTypeRegistry.php | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Controllers/ElementalAreaController.php b/src/Controllers/ElementalAreaController.php index 283b6b89..7f116020 100644 --- a/src/Controllers/ElementalAreaController.php +++ b/src/Controllers/ElementalAreaController.php @@ -186,7 +186,7 @@ public function formAction(HTTPRequest $request) $formName = $request->param('FormName'); // Get the element ID from the form name - $id = substr($formName ?? '', strlen(sprintf(self::FORM_NAME_TEMPLATE ?? '', ''))); + $id = substr($formName ?? '', strlen(sprintf(ElementalAreaController::FORM_NAME_TEMPLATE ?? '', ''))); $form = $this->getElementForm($id); $field = $form->getRequestHandler()->handleField($request); diff --git a/src/Extensions/ElementalAreasExtension.php b/src/Extensions/ElementalAreasExtension.php index 565e2618..8346a535 100644 --- a/src/Extensions/ElementalAreasExtension.php +++ b/src/Extensions/ElementalAreasExtension.php @@ -182,7 +182,7 @@ public function updateCMSFields(FieldList $fields) } // add an empty holder for content as some module explicitly use insert after content - $globalReplace = !Config::inst()->get(self::class, 'keep_content_fields'); + $globalReplace = !Config::inst()->get(ElementalAreasExtension::class, 'keep_content_fields'); $classOverride = Config::inst()->get(get_class($this->owner), 'elemental_keep_content_field'); if ($globalReplace && !$classOverride || $classOverride === false) { $fields->replaceField('Content', new LiteralField('Content', '')); @@ -241,7 +241,7 @@ public function onBeforeWrite() } } - if (Config::inst()->get(self::class, 'clear_contentfield')) { + if (Config::inst()->get(ElementalAreasExtension::class, 'clear_contentfield')) { $this->owner->Content = ''; } } diff --git a/src/Extensions/ElementalPageExtension.php b/src/Extensions/ElementalPageExtension.php index e775f508..9236bd34 100644 --- a/src/Extensions/ElementalPageExtension.php +++ b/src/Extensions/ElementalPageExtension.php @@ -135,10 +135,10 @@ public function MetaTags(&$tags) private function getEagerLoadedElements(): array { $elements = []; - if (is_null(self::$elementalAreas)) { - self::$elementalAreas = []; + if (is_null(ElementalPageExtension::$elementalAreas)) { + ElementalPageExtension::$elementalAreas = []; foreach (ElementalArea::get()->eagerLoad('Elements') as $elementalArea) { - self::$elementalAreas[$elementalArea->ID] = $elementalArea; + ElementalPageExtension::$elementalAreas[$elementalArea->ID] = $elementalArea; } } foreach ($this->owner->hasOne() as $relation => $class) { @@ -146,8 +146,8 @@ private function getEagerLoadedElements(): array continue; } $elementalAreaID = $this->owner->{"{$relation}ID"}; - if ($elementalAreaID && array_key_exists($elementalAreaID, self::$elementalAreas)) { - $elementalArea = self::$elementalAreas[$elementalAreaID]; + if ($elementalAreaID && array_key_exists($elementalAreaID, ElementalPageExtension::$elementalAreas)) { + $elementalArea = ElementalPageExtension::$elementalAreas[$elementalAreaID]; } else { $elementalArea = $this->owner->$relation(); } diff --git a/src/Forms/EditFormFactory.php b/src/Forms/EditFormFactory.php index c8579af7..d993a256 100644 --- a/src/Forms/EditFormFactory.php +++ b/src/Forms/EditFormFactory.php @@ -26,7 +26,7 @@ class EditFormFactory extends DefaultFormFactory */ const FIELD_NAMESPACE_TEMPLATE = 'PageElements_%d_%s'; - public function getForm(RequestHandler $controller = null, $name = self::DEFAULT_NAME, $context = []) + public function getForm(RequestHandler $controller = null, $name = EditFormFactory::DEFAULT_NAME, $context = []) { $form = parent::getForm($controller, $name, $context); @@ -71,7 +71,7 @@ protected function namespaceFields(FieldList $fields, array $context) // Apply audo-detection of multi-upload before changing the name. $field->setIsMultiUpload($field->getIsMultiUpload()); } - $namespacedName = sprintf(self::FIELD_NAMESPACE_TEMPLATE ?? '', $elementID, $field->getName()); + $namespacedName = sprintf(EditFormFactory::FIELD_NAMESPACE_TEMPLATE ?? '', $elementID, $field->getName()); $field->setName($namespacedName); } } diff --git a/src/Models/BaseElement.php b/src/Models/BaseElement.php index e1078558..356b8cda 100644 --- a/src/Models/BaseElement.php +++ b/src/Models/BaseElement.php @@ -477,7 +477,7 @@ public function getController() return $this->controller; } - $controllerClass = self::config()->controller_class; + $controllerClass = static::config()->controller_class; if (!class_exists($controllerClass ?? '')) { throw new Exception( @@ -751,11 +751,11 @@ public function getAnchor() // ie. If two elemental blocks have the same title, it'll append '-2', '-3' $result = $titleAsURL; $count = 1; - while (isset(self::$used_anchors[$result]) && self::$used_anchors[$result] !== $this->ID) { + while (isset(BaseElement::$used_anchors[$result]) && BaseElement::$used_anchors[$result] !== $this->ID) { ++$count; $result = $titleAsURL . '-' . $count; } - self::$used_anchors[$result] = $this->ID; + BaseElement::$used_anchors[$result] = $this->ID; return $this->anchor = $result; } @@ -1280,7 +1280,7 @@ public function EvenOdd() public static function getGraphQLTypeName(): string { // For GraphQL 3, use the static schema type name - except for BaseElement for which this is inconsistent. - if (class_exists(StaticSchema::class) && static::class !== self::class) { + if (class_exists(StaticSchema::class) && static::class !== BaseElement::class) { return StaticSchema::inst()->typeNameForDataObject(static::class); } return str_replace('\\', '_', static::class); diff --git a/src/Services/ElementTypeRegistry.php b/src/Services/ElementTypeRegistry.php index aabf8590..61be6e3a 100644 --- a/src/Services/ElementTypeRegistry.php +++ b/src/Services/ElementTypeRegistry.php @@ -140,7 +140,7 @@ public static function generate() $registry = static::create(); // Look in a cache (if provided) for type details - if (static::$cache && ($types = static::$cache->get(self::CACHE_KEY))) { + if (static::$cache && ($types = static::$cache->get(ElementTypeRegistry::CACHE_KEY))) { $registry->elementTypes = $types; return $registry; }