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

597 Don't render regions up-front to see if they are empty #601

Draft
wants to merge 1 commit into
base: 1.x
Choose a base branch
from
Draft
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
14 changes: 2 additions & 12 deletions localgov_base.theme
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\DeprecationHelper;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\views\ViewExecutable;

/**
Expand Down Expand Up @@ -76,18 +77,7 @@ function localgov_base_preprocess_page(&$variables) {
if (in_array($region, $excluded_regions, TRUE)) {
continue;
}
$copy = $variables['page'][$region];

/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$rendered = DeprecationHelper::backwardsCompatibleCall(
currentVersion: \Drupal::VERSION,
deprecatedVersion: '10.3',
currentCallable: fn() => $renderer->renderInIsolation($copy),
deprecatedCallable: fn() => $renderer->renderPlain($copy),
);

$variables['has_' . $region] = strlen(trim(strip_tags($rendered, '<drupal-render-placeholder><embed><hr><iframe><img><input><link><object><script><source><style><video>'))) > 0;
$variables['has_' . $region] = !empty(Element::children($variables['page'][$region]));
}
$variables['has_sidebars'] = $variables['has_sidebar_first'] || $variables['has_sidebar_second'];

Expand Down