Skip to content
This repository has been archived by the owner on Mar 20, 2022. It is now read-only.

Commit

Permalink
Merge pull request #44 from michaelr0/main
Browse files Browse the repository at this point in the history
Helper functions check + Docblock
  • Loading branch information
edalzell authored May 11, 2021
2 parents 754ebd3 + 4fb4441 commit e2fea28
Showing 1 changed file with 39 additions and 21 deletions.
60 changes: 39 additions & 21 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,47 @@
use Statamic\Tags\Loader as TagLoader;
use Statamic\View\Antlers\Parser;

function modify($value): Modify
{
return Modify::value($value);
if (! function_exists('modify')) {
/**
* Specify a value to start the modification chain.
*
* @param mixed $value
* @return \Statamic\Modifiers\Modify
*/
function modify($value): Modify
{
return Modify::value($value);
}
}

function tag(string $name, array $params = [], array $context = [])
{
if ($pos = strpos($name, ':')) {
$original_method = substr($name, $pos + 1);
$method = Str::camel($original_method);
$name = substr($name, 0, $pos);
} else {
$method = $original_method = 'index';
}
if (! function_exists('tag')) {
/**
* Tags are Antlers expressions giving you the ability to fetch, filter, and display content, enhance and simplify your markup, build forms, and build dynamic functionality.
*
* @param string $name
* @param array $params
* @param array $context
* @return mixed
*/
function tag(string $name, array $params = [], array $context = [])
{
if ($pos = strpos($name, ':')) {
$original_method = substr($name, $pos + 1);
$method = Str::camel($original_method);
$name = substr($name, 0, $pos);
} else {
$method = $original_method = 'index';
}

$tag = app(TagLoader::class)->load($name, [
'parser' => app(Parser::class),
'params' => $params,
'content' => '',
'context' => $context,
'tag' => $name.':'.$original_method,
'tag_method' => $original_method,
]);
$tag = app(TagLoader::class)->load($name, [
'parser' => app(Parser::class),
'params' => $params,
'content' => '',
'context' => $context,
'tag' => $name.':'.$original_method,
'tag_method' => $original_method,
]);

return $tag->$method();
return $tag->$method();
}
}

0 comments on commit e2fea28

Please sign in to comment.