Skip to content

Commit

Permalink
Return false in case the url is empty.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonassiewertsen committed Aug 8, 2021
1 parent ef29cb2 commit 8941fc7
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/ExternalLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,74 @@ public function preProcess($data)
{
return preg_replace('/^(http|https):\/\//i', '', $data);
}

<?php

namespace Jonassiewertsen\ExternalLink;

use Statamic\Fields\Fieldtype;

class ExternalLink extends Fieldtype
{
protected $icon = 'earth';

protected $categories = ['text'];

protected $regexPattern = '/^(http|https):\/\//i';

/**
* @return string
*/
public static function title()
{
return 'External Link';
}

/**
* Adding the https:// before saving
*
* @param $data
*
* @return string
*/
public function process($data)
{
if (! $data) {
return;
}

return 'https://' . $data;
}


/**
* Removing the https:// before displaying in field
*
* @param $data
*
* @return mixed
*/
public function preProcess($data)
{
$data = preg_replace($this->regexPattern, '', $data);
}

/**
* Augment the value, which will return false in
* case it only contains the https prefix.
*
* @param $value
*
* @return mixed
*/
public function augment($value)
{
if ($value === 'https://') {
return false;
}

return $value;
}
}

}

0 comments on commit 8941fc7

Please sign in to comment.