Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 21
n/a
0 / 0
n/a
0 / 0
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
FullPageBuilderPageVariant
0.00% covered (danger)
0.00%
0 / 18
n/a
0 / 0
n/a
0 / 0
0.00% covered (danger)
0.00%
0 / 3
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
n/a
0 / 0
n/a
0 / 0
0.00% covered (danger)
0.00%
0 / 1
2
 create
0.00% covered (danger)
0.00%
0 / 7
n/a
0 / 0
n/a
0 / 0
0.00% covered (danger)
0.00%
0 / 1
2
 build
0.00% covered (danger)
0.00%
0 / 8
n/a
0 / 0
n/a
0 / 0
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Drupal\display_builder_page_layout\Plugin\DisplayVariant;
6
7use Drupal\Core\Display\Attribute\PageDisplayVariant;
8use Drupal\Core\Extension\ExtensionList;
9use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
10use Drupal\Core\Render\Plugin\DisplayVariant\SimplePageVariant;
11use Drupal\Core\StringTranslation\TranslatableMarkup;
12use Drupal\Core\Theme\Registry;
13use Symfony\Component\DependencyInjection\ContainerInterface;
14
15/**
16 * A variant for pages managed by Display Builder Page Layout.
17 */
18#[PageDisplayVariant(
19  id: 'display_builder_full',
20  admin_label: new TranslatableMarkup('Full page Display Builder')
21)]
22class FullPageBuilderPageVariant extends SimplePageVariant implements ContainerFactoryPluginInterface {
23
24  /**
25   * The theme registry.
26   */
27  protected Registry $themeRegistry;
28
29  /**
30   * The list of modules.
31   */
32  protected ExtensionList $modules;
33
34  public function __construct(
35    array $configuration,
36    $plugin_id,
37    $plugin_definition,
38    Registry $theme_registry,
39    ExtensionList $modules,
40  ) {
41    parent::__construct($configuration, $plugin_id, $plugin_definition);
42    $this->themeRegistry = $theme_registry;
43    $this->modules = $modules;
44  }
45
46  /**
47   * {@inheritdoc}
48   */
49  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): static {
50    return new static(
51      $configuration,
52      $plugin_id,
53      $plugin_definition,
54      $container->get('theme.registry'),
55      $container->get('extension.list.module'),
56    );
57  }
58
59  /**
60   * {@inheritdoc}
61   *
62   * @see \Drupal\display_builder_page_layout\Hook\PageLayoutHook
63   */
64  public function build() {
65    $build = parent::build();
66    $build['#page_variant'] = 'display_builder_full';
67
68    // We alter the registry here instead of implementing
69    // hook_theme_registry_alter in order keep the alteration specific to each
70    // page.
71    $theme_registry = $this->themeRegistry->get();
72    $template_uri = $this->modules->getPath('display_builder_page_layout') . '/templates';
73    $runtime = $this->themeRegistry->getRuntime();
74    $theme_registry['page']['path'] = $template_uri;
75    $runtime->set('page', $theme_registry['page']);
76
77    return $build;
78  }
79
80}

Branches

Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once. Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement always has an else as part of its logical flow even if you didn't write one.