getMachineNameSuggestion example


  public function testMachineNameSuggestion() {
    $plugin_definition = [
      'provider' => 'views',
    ];
    $plugin_id = 'views_block:test_view_block-block_1';
    $views_block = ViewsBlock::create($this->container, []$plugin_id$plugin_definition);

    $this->assertEquals('views_block__test_view_block_block_1', $views_block->getMachineNameSuggestion());
  }

  /** * Tests that ViewsBlock::build() produces the right output with title tokens. * * @see \Drupal\views\Plugin\Block::build() */
  public function testBuildWithTitleToken() {
    $view = Views::getView('test_view_block');
    $view->setDisplay();

    
->setConstructorArgs([NULL, $module_handler])
      ->onlyMethods(['readLanguageOverrides'])
      ->getMock();

    $config = [];
    $definition = [
      'admin_label' => $label,
      'provider' => 'block_test',
    ];
    $block_base = new TestBlockInstantiation($config, 'test_block_instantiation', $definition);
    $block_base->setTransliteration($transliteration);
    $this->assertEquals($expected$block_base->getMachineNameSuggestion());
  }

  /** * Provides data for testGetMachineNameSuggestion(). */
  public function providerTestGetMachineNameSuggestion() {
    return [
      ['Admin label', 'adminlabel'],
      ['über åwesome', 'uberawesome'],
    ];
  }

}
    unset($actual_form['visibility']$actual_form['visibility_tabs']);
    $this->assertEquals($expected_form$actual_form, 'Only the expected form elements were present.');

    $expected_build = [
      '#children' => 'My custom display message.',
    ];
    // Ensure the build array is proper.     $this->assertSame($expected_build$display_block->build(), 'The plugin returned the appropriate build array.');

    // Ensure the machine name suggestion is correct. In truth, this is actually     // testing BlockBase's implementation, not the interface itself.     $this->assertSame('displaymessage', $display_block->getMachineNameSuggestion(), 'The plugin returned the expected machine name suggestion.');
  }

}
/** * Generates a unique machine name for a block. * * @param \Drupal\block\BlockInterface $block * The block entity. * * @return string * Returns the unique name. */
  public function getUniqueMachineName(BlockInterface $block) {
    $suggestion = $block->getPlugin()->getMachineNameSuggestion();
    if ($block->getTheme()) {
      $suggestion = $block->getTheme() . '_' . $suggestion;
    }

    // Get all the blocks which starts with the suggested machine name.     $query = $this->storage->getQuery();
    $query->condition('id', $suggestion, 'CONTAINS');
    $block_ids = $query->execute();

    $block_ids = array_map(function D$block_id) {
      $parts = explode('.', $block_id);
      
Home | Imprint | This part of the site doesn't use cookies.