You are here

protected function BlockTestTrait::createFacet in Facets 8

Add a facet trough the UI.

Parameters

string $name: The facet name.

string $id: The facet id.

string $field: The facet field.

string $display_id: The display id.

string $source: Facet source.

bool $allowBlockCreation: Automatically create a block.

62 calls to BlockTestTrait::createFacet()
BreadcrumbIntegrationTest::testBreadcrumbLabel in tests/src/Functional/BreadcrumbIntegrationTest.php
Tests enabling + disabling the breadcrumb label prefix.
BreadcrumbIntegrationTest::testGroupingIntegration in tests/src/Functional/BreadcrumbIntegrationTest.php
Tests Breadcrumb integration with grouping.
FacetsUrlGeneratorTest::testWithAlreadySetFacet in tests/src/Functional/FacetsUrlGeneratorTest.php
Create url with already set facet.
HierarchicalFacetIntegrationTest::setUp in tests/src/Functional/HierarchicalFacetIntegrationTest.php
HierarchicalFacetIntegrationTest::setUp in modules/facets_summary/tests/src/Functional/HierarchicalFacetIntegrationTest.php

... See full list

File

tests/src/Functional/BlockTestTrait.php, line 35

Class

BlockTestTrait
Shared test methods for facet blocks.

Namespace

Drupal\Tests\facets\Functional

Code

protected function createFacet($name, $id, $field = 'type', $display_id = 'page_1', $source = 'views_page__search_api_test_view', $allowBlockCreation = TRUE) {
  $facet_source = "search_api:{$source}__{$display_id}";

  /** @var \Drupal\facets\FacetInterface $facet */
  $facet = Facet::create([
    'id' => $id,
    'name' => $name,
    'weight' => 0,
  ]);
  $facet
    ->setFacetSourceId($facet_source);
  $facet
    ->setFieldIdentifier($field);
  $facet
    ->setUrlAlias($id);
  $facet
    ->setWidget('links', [
    'show_numbers' => TRUE,
  ]);
  $facet
    ->addProcessor([
    'processor_id' => 'url_processor_handler',
    'weights' => [
      'pre_query' => -10,
      'build' => -10,
    ],
    'settings' => [],
  ]);
  $facet
    ->setEmptyBehavior([
    'behavior' => 'none',
  ]);
  $facet
    ->setOnlyVisibleWhenFacetSourceIsVisible(TRUE);
  $facet
    ->save();
  if ($allowBlockCreation) {
    $this->blocks[$id] = $this
      ->createBlock($id);
  }
}