Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
PageLayoutHook
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 entityOperationAlter
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
12
 displayBuilderProviderInfo
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Drupal\display_builder_page_layout\Hook;
6
7use Drupal\Core\Entity\EntityInterface;
8use Drupal\Core\Hook\Attribute\Hook;
9use Drupal\Core\StringTranslation\TranslatableMarkup;
10use Drupal\display_builder\InstanceInterface;
11use Drupal\display_builder_page_layout\Entity\PageLayout;
12
13/**
14 * Hook implementations for the display_builder_page_layout module.
15 */
16class PageLayoutHook {
17
18  /**
19   * Implements hook_entity_operation_alter().
20   *
21   * @param array $operations
22   *   An associative array of operations.
23   * @param \Drupal\Core\Entity\EntityInterface $entity
24   *   The entity for which the operations are being altered.
25   */
26  #[Hook('entity_operation_alter')]
27  public function entityOperationAlter(array &$operations, EntityInterface $entity): void {
28    if (!$entity instanceof InstanceInterface) {
29      return;
30    }
31    $id = (string) $entity->id();
32
33    if (\str_starts_with($id, PageLayout::getPrefix())) {
34      $operations['build'] = [
35        'title' => new TranslatableMarkup('Build display'),
36        'url' => PageLayout::getUrlFromInstanceId($id),
37        'weight' => -1,
38      ];
39      $operations['edit'] = [
40        'title' => new TranslatableMarkup('Edit page'),
41        'url' => PageLayout::getDisplayUrlFromInstanceId($id),
42        'weight' => 10,
43      ];
44    }
45  }
46
47  /**
48   * Implements hook_display_builder_provider_info().
49   *
50   * @return array
51   *   An associative array of display builder providers.
52   */
53  #[Hook('display_builder_provider_info')]
54  public function displayBuilderProviderInfo(): array {
55    return [
56      'page_layout' => [
57        'label' => new TranslatableMarkup('Page layout'),
58        'class' => PageLayout::class,
59        'prefix' => PageLayout::getPrefix(),
60      ],
61    ];
62  }
63
64}

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.

PageLayoutHook->displayBuilderProviderInfo
57        'label' => new TranslatableMarkup('Page layout'),
58        'class' => PageLayout::class,
59        'prefix' => PageLayout::getPrefix(),
PageLayoutHook->entityOperationAlter
27  public function entityOperationAlter(array &$operations, EntityInterface $entity): void {
28    if (!$entity instanceof InstanceInterface) {
29      return;
31    $id = (string) $entity->id();
32
33    if (\str_starts_with($id, PageLayout::getPrefix())) {
35        'title' => new TranslatableMarkup('Build display'),
36        'url' => PageLayout::getUrlFromInstanceId($id),
37        'weight' => -1,
38      ];
39      $operations['edit'] = [
40        'title' => new TranslatableMarkup('Edit page'),
41        'url' => PageLayout::getDisplayUrlFromInstanceId($id),
42        'weight' => 10,
43      ];
44    }
45  }
45  }