Skip to content

Commit

Permalink
Merge pull request #1201 from creative-commoners/pulls/5.2/remove-self
Browse files Browse the repository at this point in the history
ENH Use class name instead of self
  • Loading branch information
GuySartorelli authored Jun 16, 2024
2 parents f9b8249 + 51b178c commit cde308a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Controllers/ElementalAreaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Extensions/ElementalAreasExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', ''));
Expand Down Expand Up @@ -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 = '';
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Extensions/ElementalPageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,19 @@ 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) {
if (!is_a($class, ElementalArea::class, true)) {
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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Forms/EditFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Models/BaseElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Services/ElementTypeRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit cde308a

Please sign in to comment.