Skip to content

[4.5] fix: DEBUG-VIEW comments are not output #8523

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

Merged
merged 2 commits into from
Feb 10, 2024
Merged
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
10 changes: 8 additions & 2 deletions system/Filters/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class Filters
* The processed filters that will
* be used to check against.
*
* This does not include "Required Filters".
*
* @var array<string, array>
*/
protected $filters = [
Expand All @@ -81,6 +83,8 @@ class Filters
* The collection of filters' class names that will
* be used to execute in each position.
*
* This does not include "Required Filters".
*
* @var array<string, array>
*/
protected $filtersClass = [
Expand Down Expand Up @@ -252,7 +256,7 @@ private function runAfter(array $filterClasses): ResponseInterface
}

/**
* Runs required filters for the specified position.
* Runs "Required Filters" for the specified position.
*
* @return RequestInterface|ResponseInterface|string|null
*
Expand Down Expand Up @@ -289,7 +293,7 @@ public function runRequired(string $position = 'before')
}

/**
* Returns required filters for the specified position.
* Returns "Required Filters" for the specified position.
*
* @phpstan-param 'before'|'after' $position
*
Expand Down Expand Up @@ -423,6 +427,7 @@ public function reset(): self

/**
* Returns the processed filters array.
* This does not include "Required Filters".
*/
public function getFilters(): array
{
Expand All @@ -431,6 +436,7 @@ public function getFilters(): array

/**
* Returns the filtersClass array.
* This does not include "Required Filters".
*/
public function getFiltersClass(): array
{
Expand Down
15 changes: 12 additions & 3 deletions system/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,19 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n
$this->renderVars['view']
);

$afterFilters = service('filters')->getFiltersClass()['after'];
// Check if DebugToolbar is enabled.
$filters = Services::filters();
$requiredAfterFilters = $filters->getRequiredFilters('after')[0];
if (in_array('toolbar', $requiredAfterFilters, true)) {
$debugBarEnabled = true;
} else {
$afterFilters = $filters->getFiltersClass()['after'];
$debugBarEnabled = in_array(DebugToolbar::class, $afterFilters, true);
}

if (
($this->debug && (! isset($options['debug']) || $options['debug'] === true))
&& in_array(DebugToolbar::class, $afterFilters, true)
$this->debug && $debugBarEnabled
&& (! isset($options['debug']) || $options['debug'] === true)
) {
$toolbarCollectors = config(Toolbar::class)->collectors;

Expand Down
10 changes: 8 additions & 2 deletions tests/system/Helpers/FormHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,10 @@ public function testValidationShowError(): void

$html = validation_show_error('id');

$this->assertSame('<span class="help-block">The ID field is required.</span>' . "\n", $html);
$this->assertSame('<!-- DEBUG-VIEW START 1 SYSTEMPATH/Validation/Views/single.php -->
<span class="help-block">The ID field is required.</span>

<!-- DEBUG-VIEW ENDED 1 SYSTEMPATH/Validation/Views/single.php -->' . "\n", $html);
}

public function testValidationShowErrorForWildcards(): void
Expand All @@ -1041,7 +1044,10 @@ public function testValidationShowErrorForWildcards(): void

$html = validation_show_error('user.*.name');

$this->assertSame('<span class="help-block">The Name field is required.</span>' . "\n", $html);
$this->assertSame('<!-- DEBUG-VIEW START 1 SYSTEMPATH/Validation/Views/single.php -->
<span class="help-block">The Name field is required.</span>

<!-- DEBUG-VIEW ENDED 1 SYSTEMPATH/Validation/Views/single.php -->' . "\n", $html);
}

public function testFormParseFormAttributesTrue(): void
Expand Down