Skip to content

Fix $blueprint functions to do what they're expected #111

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,49 @@ public function extension(string $identifier): bool
return str_contains($this->fileRead(base_path('.blueprint/extensions/blueprint/private/db/installed_extensions')), $identifier);
}

/**
* Retrieves a list of installed extensions.
*
* This method reads a file containing a comma-separated list of installed
* extensions, parses it into an array, and returns the result.
*
* @return array An array of installed extensions.
*/
public function extensions(): Array
{
$array = explode(',', $this->fileRead(base_path('.blueprint/extensions/blueprint/private/db/installed_extensions')));
return $array;
}

/**
* Retrieves the configuration for a specified extension.
*
* This method checks if the given extension exists and, if so, reads its
* configuration file in YAML format. The configuration data is then filtered
* to remove any empty or falsy keys.
*
* @param string $extension The name of the extension to retrieve the configuration for.
*
* @return array|null The configuration array for the extension, or null if the extension does not exist.
*/
public function extensionConfig(string $extension): ?array
{
if(!$this->extension($extension)) {
return null;
}
$conf = Yaml::parse($this->fileRead(base_path(".blueprint/extensions/$extension/private/.store/conf.yml")));
$conf = array_filter($conf, fn ($k) => !!$k);
return $conf;
}

/**
* Returns an array containing all installed extensions's identifiers.
*
* @return array An array of installed extensions
*
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
*/
public function extensions(): Collection
public function extensionsConfigs(): Collection
{
$array = explode(',', $this->fileRead(base_path('.blueprint/extensions/blueprint/private/db/installed_extensions')));
$collection = new Collection();
Expand All @@ -247,7 +282,7 @@ public function extensions(): Collection
try {
$conf = Yaml::parse($this->fileRead(base_path(".blueprint/extensions/$extension/private/.store/conf.yml")));

$collection->push(array_filter($conf['info'], fn ($k) => !!$k));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? info is more than enough

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have an idea for an extension that would eventually require more than just the info tab.

But also just to do what it says. The method isn't for getting the info section, it's for getting the config

$collection->push(array_filter($conf, fn ($k) => !!$k));
} catch (\Exception $e) {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ public function collect(): array

'blueprint' => [
'version' => $this->placeholderService->version(),
'extensions' => $this->blueprint->extensions()->toArray(),
'extensions' => array_map(function ($config) {
return $config['info'] ?? null;
}, $this->blueprint->extensionsConfigs()->toArray()),
'flags' => $flags,
'docker' => file_exists('/.dockerenv'),
],
Expand Down
3 changes: 2 additions & 1 deletion resources/views/admin/extensions.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@
</button>
</div>

@foreach($blueprint->extensions() as $extension)
@foreach($blueprint->extensionsConfigs() as $extension)
{{ $extension = $extension['info'] }}
@include("blueprint.admin.entry", [
'EXTENSION_ID' => $extension['identifier'],
'EXTENSION_NAME' => $extension['name'],
Expand Down
3 changes: 2 additions & 1 deletion routes/blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
Route::patch('/config', [Pterodactyl\BlueprintFramework\Controllers\ExtensionConfigurationController::class, 'update']);
});

foreach ($blueprint->extensions() as $extension) {
foreach ($blueprint->extensionsConfigs() as $extension) {
$extension = $extension['info'];
$identifier = $extension['identifier'];
$controllerName = $identifier . 'ExtensionController';

Expand Down