Skip to content

Commit

Permalink
Only call createLink() when channel is supported
Browse files Browse the repository at this point in the history
  • Loading branch information
aerni committed Aug 4, 2020
1 parent c7842db commit 5cfde1b
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/SocialLinksTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

class SocialLinksTags extends Tags
{
/**
* The supported channels.
*
* @var array
*/
protected $channels = ['facebook', 'twitter', 'linkedin', 'pinterest', 'whatsapp', 'mail'];

/**
* The handle of the tag.
*
Expand All @@ -25,7 +32,9 @@ class SocialLinksTags extends Tags
*/
public function wildcard($tag)
{
return $this->createLink($tag);
if ($this->isSupportedChannel($tag)) {
return $this->createLink($tag);
}
}

/**
Expand Down Expand Up @@ -62,6 +71,8 @@ public function createLink(string $tag): string
if ($tag === 'mail') {
return "mailto:{$params['mailto']}?&cc={$params['cc']}&bcc={$params['bcc']}&subject={$params['subject']}&body={$params['body']}";
}

return '';
}

/**
Expand All @@ -88,4 +99,19 @@ public function params(): array
];
}

/**
* Check if the channel is supported by this addon.
*
* @param string $channel
* @return bool
*/
protected function isSupportedChannel(string $channel): bool
{
if (in_array($channel, $this->channels)) {
return true;
}

return false;
}

}

0 comments on commit 5cfde1b

Please sign in to comment.