You are here

protected function PageManagerAdminTest::findBlockByLabel in Page Manager 8

Finds a block based on its variant and block label.

Parameters

string $page_variant_id: The ID of the page variant entity.

string $block_label: The label of the block.

Return value

\Drupal\Core\Block\BlockPluginInterface|null Either a block plugin, or NULL.

1 call to PageManagerAdminTest::findBlockByLabel()
PageManagerAdminTest::doTestEditVariant in page_manager_ui/src/Tests/PageManagerAdminTest.php
Tests editing a variant.

File

page_manager_ui/src/Tests/PageManagerAdminTest.php, line 695
Contains \Drupal\page_manager_ui\Tests\PageManagerAdminTest.

Class

PageManagerAdminTest
Tests the admin UI for page entities.

Namespace

Drupal\page_manager_ui\Tests

Code

protected function findBlockByLabel($page_variant_id, $block_label) {

  /** @var \Drupal\page_manager\Entity\PageVariant $page_variant */
  if ($page_variant = PageVariant::load($page_variant_id)) {

    /** @var \Drupal\ctools\Plugin\BlockVariantInterface $variant_plugin */
    $variant_plugin = $page_variant
      ->getVariantPlugin();
    foreach ($variant_plugin
      ->getRegionAssignments() as $blocks) {

      /** @var \Drupal\Core\Block\BlockPluginInterface[] $blocks */
      foreach ($blocks as $block) {
        if ($block
          ->label() == $block_label) {
          return $block;
        }
      }
    }
  }
  return NULL;
}