Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Provide search index name callback #10435

Open
wants to merge 6 commits into
base: 5.x
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Search/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Statamic\Search;

use Closure;
use Statamic\Contracts\Search\Searchable;
use Statamic\Support\Arr;
use Statamic\Support\Str;
Expand All @@ -11,6 +12,7 @@ abstract class Index
protected $name;
protected $locale;
protected $config;
protected static ?Closure $nameCallback = null;

abstract public function search($query);

Expand All @@ -31,9 +33,18 @@ public function __construct($name, array $config, ?string $locale = null)

public function name()
{
if (static::$nameCallback) {
return call_user_func(static::$nameCallback, $this->name);
}

return $this->name;
}

public static function resolveNaminglUsing(Closure $callback)
ajnsn marked this conversation as resolved.
Show resolved Hide resolved
{
static::$nameCallback = $callback;
}

public function title()
{
return $this->config['title'] ?? Str::title($this->name);
Expand Down
Loading