Skip to content

Commit

Permalink
ENH More standardisation (#223)
Browse files Browse the repository at this point in the history
* ENH Refactoring, new tests, and other standardisation

* MNT Reorder methods to match our coding conventions
  • Loading branch information
GuySartorelli authored Feb 15, 2024
1 parent 58bd7a7 commit c75615f
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 259 deletions.
2 changes: 1 addition & 1 deletion src/Form/AbstractLinkField.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function getTypesProp(): string
$typesList[$key] = [
'key' => $key,
'title' => $type->getMenuTitle(),
'handlerName' => $type->LinkTypeHandlerName(),
'handlerName' => $type->getLinkTypeHandlerName(),
'priority' => $class::config()->get('menu_priority'),
'icon' => $class::config()->get('icon'),
'allowed' => $allowed,
Expand Down
14 changes: 7 additions & 7 deletions src/Models/EmailLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ public function getCMSFields(): FieldList
return parent::getCMSFields();
}

public function getCMSCompositeValidator(): CompositeValidator
{
$validator = parent::getCMSCompositeValidator();
$validator->addValidator(RequiredFields::create(['Email']));
return $validator;
}

public function getDescription(): string
{
return $this->Email ?: '';
Expand All @@ -54,11 +61,4 @@ public function getMenuTitle(): string
{
return _t(__CLASS__ . '.LINKLABEL', 'Link to email address');
}

public function getCMSCompositeValidator(): CompositeValidator
{
$validator = parent::getCMSCompositeValidator();
$validator->addValidator(RequiredFields::create(['Email']));
return $validator;
}
}
14 changes: 7 additions & 7 deletions src/Models/ExternalLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public function getCMSFields(): FieldList
return parent::getCMSFields();
}

public function getCMSCompositeValidator(): CompositeValidator
{
$validator = parent::getCMSCompositeValidator();
$validator->addValidator(RequiredFields::create(['ExternalUrl']));
return $validator;
}

public function getDescription(): string
{
return $this->ExternalUrl ?: '';
Expand All @@ -55,11 +62,4 @@ public function getMenuTitle(): string
{
return _t(__CLASS__ . '.LINKLABEL', 'Link to external URL');
}

public function getCMSCompositeValidator(): CompositeValidator
{
$validator = parent::getCMSCompositeValidator();
$validator->addValidator(RequiredFields::create(['ExternalUrl']));
return $validator;
}
}
28 changes: 14 additions & 14 deletions src/Models/FileLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ public function getCMSFields(): FieldList
return parent::getCMSFields();
}

public function getCMSCompositeValidator(): CompositeValidator
{
$validator = parent::getCMSCompositeValidator();
$validator->addValidator(RequiredFields::create(['File']));
return $validator;
}

public function getDescription(): string
{
$file = $this->File();
Expand All @@ -52,16 +59,6 @@ public function getURL(): string
return $file->exists() ? (string) $file->getURL() : '';
}

public function getDefaultTitle(): string
{
$file = $this->File();
if (!$file->exists()) {
return _t(__CLASS__ . '.MISSING_DEFAULT_TITLE', '(File missing)');
}

return (string) $this->getDescription();
}

/**
* The title that will be displayed in the dropdown
* for selecting the link type to create.
Expand All @@ -71,10 +68,13 @@ public function getMenuTitle(): string
return _t(__CLASS__ . '.LINKLABEL', 'Link to a file');
}

public function getCMSCompositeValidator(): CompositeValidator
protected function getDefaultTitle(): string
{
$validator = parent::getCMSCompositeValidator();
$validator->addValidator(RequiredFields::create(['File']));
return $validator;
$file = $this->File();
if (!$file?->exists()) {
return _t(__CLASS__ . '.MISSING_DEFAULT_TITLE', '(File missing)');
}

return (string) $this->getDescription();
}
}
Loading

0 comments on commit c75615f

Please sign in to comment.