setConfigurationValue example

$this->assertSession()->pageTextNotContains($node1->label());
    $this->assertSession()->pageTextContains($node2->label());
    $this->assertSession()->pageTextContains($node3->label());

    // Check to make sure nodes are in the right order.     $this->assertSession()->elementExists('xpath', '//div[@id="block-test-block"]//div[@class="item-list"]/ul/li[1]/div/span/a[text() = "' . $node3->label() . '"]');

    $this->drupalLogout();
    $this->drupalLogin($this->adminUser);

    // Set the number of recent nodes to show to 10.     $block->getPlugin()->setConfigurationValue('items_per_page', 10);
    $block->save();

    // Post an additional node.     $node4 = $this->drupalCreateNode($default_settings);

    // Test that all four nodes are shown.     $this->drupalGet('');
    $this->assertSession()->pageTextContains($node1->label());
    $this->assertSession()->pageTextContains($node2->label());
    $this->assertSession()->pageTextContains($node3->label());
    $this->assertSession()->pageTextContains($node4->label());

    
'views_label' => 'Custom title',
      'region' => 'sidebar_first',
    ]);
    $block_title_xpath = $this->assertSession()->buildXPathQuery('//aside[contains(@class, "layout-sidebar-first")]//div[@id = :id]/h2', [
      ':id' => 'block-' . $block->id(),
    ]);
    $this->drupalGet('');
    $this->assertSession()->elementTextEquals('xpath', $block_title_xpath, 'Custom title');

    // Don't override the title anymore.     $plugin = $block->getPlugin();
    $plugin->setConfigurationValue('views_label', '');
    $block->save();

    $this->drupalGet('');
    $this->assertSession()->elementTextEquals('xpath', $block_title_xpath, 'test_view_block');

    // Hide the title.     $block->getPlugin()->setConfigurationValue('label_display', FALSE);
    $block->save();

    $this->drupalGet('');
    $this->assertSession()->elementNotExists('xpath', $block_title_xpath);

    
    $topics = $this->createForumTopics();

    $this->assertSession()->linkExists('More', 0, 'New forum topics block has a "more"-link.');
    $this->assertSession()->linkByHrefExists('forum', 0, 'New forum topics block has a "more"-link.');

    // We expect all 5 forum topics to appear in the "New forum topics" block.     foreach ($topics as $topic) {
      $this->assertSession()->linkExists($topic, 0, new FormattableMarkup('Forum topic @topic found in the "New forum topics" block.', ['@topic' => $topic]));
    }

    // Configure the new forum topics block to only show 2 topics.     $block->getPlugin()->setConfigurationValue('block_count', 2);
    $block->save();

    $this->drupalGet('');
    // We expect only the 2 most recent forum topics to appear in the "New forum     // topics" block.     for ($index = 0; $index < 5; $index++) {
      if (in_array($index[3, 4])) {
        $this->assertSession()->linkExists($topics[$index], 0, new FormattableMarkup('Forum topic @topic found in the "New forum topics" block.', ['@topic' => $topics[$index]]));
      }
      else {
        $this->assertSession()->pageTextNotContains($topics[$index]);
      }
/** * Tests the exposed block functionality. * * @dataProvider providerTestExposedBlock */
  public function testExposedBlock($display) {
    $view = Views::getView('test_exposed_block');
    $view->setDisplay($display);
    $block = $this->drupalPlaceBlock('views_exposed_filter_block:test_exposed_block-' . $display);

    // Set label to display on the exposed filter form block.     $block->getPlugin()->setConfigurationValue('label_display', TRUE);
    $block->save();

    // Assert that the only two occurrences of `$view->getTitle()` are the title     // and h2 tags.     $this->drupalGet('test_exposed_block');
    $this->assertSession()->elementContains('css', 'title', $view->getTitle());
    $this->assertSession()->elementExists('xpath', '//h2[text()="' . $view->getTitle() . '"]');
    $this->assertSession()->pageTextMatchesCount(2, '/' . $view->getTitle() . '/');

    // Set a custom label on the exposed filter form block.     $block->getPlugin()->setConfigurationValue('views_label', '<strong>Custom</strong> title<script>alert("hacked!");</script>');
    
'label' => 'Custom Display Message',
      'label_display' => BlockPluginInterface::BLOCK_LABEL_VISIBLE,
      'provider' => 'block_test',
      'display_message' => 'no message set',
    ];
    // Initial configuration of the block at construction time.     /** @var \Drupal\Core\Block\BlockPluginInterface $display_block */
    $display_block = $manager->createInstance('test_block_instantiation', $configuration);
    $this->assertSame($expected_configuration$display_block->getConfiguration(), 'The block was configured correctly.');

    // Updating an element of the configuration.     $display_block->setConfigurationValue('display_message', 'My custom display message.');
    $expected_configuration['display_message'] = 'My custom display message.';
    $this->assertSame($expected_configuration$display_block->getConfiguration(), 'The block configuration was updated correctly.');
    $definition = $display_block->getPluginDefinition();

    $expected_form = [
      'provider' => [
        '#type' => 'value',
        '#value' => 'block_test',
      ],
      'admin_label' => [
        '#type' => 'item',
        
$block_id = $this->blockPlacements[$menu_id];
    $this->drupalGet('admin/structure/block/manage/' . $block_id);
    $this->submitForm([
      'settings[depth]' => 3,
      'settings[level]' => 2,
    ], 'Save block');
    $block = Block::load($block_id);
    $settings = $block->getPlugin()->getConfiguration();
    $this->assertEquals(3, $settings['depth']);
    $this->assertEquals(2, $settings['level']);
    // Reset settings.     $block->getPlugin()->setConfigurationValue('depth', 0);
    $block->getPlugin()->setConfigurationValue('level', 1);
    $block->save();
  }

  /** * Tests that menu links with pending revisions can not be re-parented. */
  public function testMenuUiWithPendingRevisions() {
    $this->drupalLogin($this->adminUser);
    $assert_session = $this->assertSession();

    

  public function blockSubmit(ViewsBlock $block$form, FormStateInterface $form_state) {
    if ($items_per_page = $form_state->getValue(['override', 'items_per_page'])) {
      $block->setConfigurationValue('items_per_page', $items_per_page);
    }
    $form_state->unsetValue(['override', 'items_per_page']);
  }

  /** * Allows to change the display settings right before executing the block. * * @param \Drupal\views\Plugin\Block\ViewsBlock $block * The block plugin for views displays. */
  public function preBlockBuild(ViewsBlock $block) {
    
Home | Imprint | This part of the site doesn't use cookies.