You are here

protected function JsBase::createBlock in Facets 8

Create and place a facet block in the first sidebar.

Parameters

string $id: Create a block for a facet.

4 calls to JsBase::createBlock()
JsBase::createFacet in tests/src/FunctionalJavascript/JsBase.php
Create a facet.
WidgetJSTest::testCheckboxWidget in tests/src/FunctionalJavascript/WidgetJSTest.php
Tests checkbox widget.
WidgetJSTest::testDropdownWidget in tests/src/FunctionalJavascript/WidgetJSTest.php
Tests dropdown widget.
WidgetJSTest::testLinksShowMoreLess in tests/src/FunctionalJavascript/WidgetJSTest.php
Tests show more / less links.

File

tests/src/FunctionalJavascript/JsBase.php, line 113

Class

JsBase
Tests for the JS that transforms widgets into form elements.

Namespace

Drupal\Tests\facets\FunctionalJavascript

Code

protected function createBlock($id) {
  $config = \Drupal::configFactory();
  $settings = [
    'plugin' => 'facet_block:' . $id,
    'region' => 'sidebar_first',
    'id' => $id . '_block',
    'theme' => $config
      ->get('system.theme')
      ->get('default'),
    'label' => ucfirst($id) . ' block',
    'visibility' => [],
    'weight' => 0,
  ];
  foreach ([
    'region',
    'id',
    'theme',
    'plugin',
    'weight',
    'visibility',
  ] as $key) {
    $values[$key] = $settings[$key];

    // Remove extra values that do not belong in the settings array.
    unset($settings[$key]);
  }
  $values['settings'] = $settings;
  $block = Block::create($values);
  $block
    ->save();
}