getPlugin example

ViewTestData::createTestViews(static::class['user_test_views']);
  }

  /** * Tests perm access plugin. */
  public function testAccessPerm() {
    $view = Views::getView('test_access_perm');
    $view->setDisplay();

    $access_plugin = $view->display_handler->getPlugin('access');
    $this->assertInstanceOf(Permission::class$access_plugin);
    $this->assertEquals('Permission', $access_plugin->pluginTitle());

    $this->assertFalse($view->display_handler->access($this->webUser));
    $this->assertTrue($view->display_handler->access($this->normalUser));
  }

  /** * Tests access on render caching. */
  public function testRenderCaching() {
    
$view->setRequest($request);
    $request_stack->push($request);
    $renderer->renderRoot($build);

    // Check render array cache tags.     sort($expected_render_array_cache_tags);
    $this->assertEqualsCanonicalizing($expected_render_array_cache_tags$build['#cache']['tags']);

    if ($views_caching_is_enabled) {
      // Check Views render cache item cache tags.       /** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache_plugin */
      $cache_plugin = $view->display_handler->getPlugin('cache');

      // Results cache.
      // Ensure that the views query is built.       $view->build();
      $results_cache_item = \Drupal::cache('data')->get($cache_plugin->generateResultsKey());
      if (is_array($expected_results_cache)) {
        $this->assertNotEmpty($results_cache_item, 'Results cache item found.');
        if ($results_cache_item) {
          $this->assertEqualsCanonicalizing($expected_results_cache$results_cache_item->tags);
        }
      }
protected $plugin_objs = [];

    public function __construct()
    {
        $this->header_width = self::$default_width;
        $this->indent_width = self::$default_indent;
    }

    public function render(Value $o): string
    {
        if ($plugin = $this->getPlugin(self::$plugins$o->hints)) {
            $output = $plugin->render($o);
            if (null !== $output && \strlen($output)) {
                return $output;
            }
        }

        $out = '';

        if (0 == $o->depth) {
            $out .= $this->colorTitle($this->renderTitle($o)).PHP_EOL;
        }

        
class LayoutEntityHelperTraitTest extends UnitTestCase {

  /** * Data provider method for tests that need sections with inline blocks. */
  public static function providerSectionsWithInlineComponents() {
    $prophet = new Prophet();
    $components = [];

    // Ensure a non-derivative component is not returned.     $non_derivative_component = $prophet->prophesize(SectionComponent::class);
    $non_derivative_component->getPlugin()->willReturn($prophet->prophesize(PluginInspectionInterface::class)->reveal());
    $components[] = $non_derivative_component->reveal();

    // Ensure a derivative component with a different base Id is not returned.     $derivative_non_inline_component = $prophet->prophesize(SectionComponent::class);
    $plugin = $prophet->prophesize(DerivativeInspectionInterface::class);
    $plugin->getBaseId()->willReturn('some_other_base_id_which_we_do_not_care_about_but_it_is_nothing_personal');
    $derivative_non_inline_component->getPlugin()->willReturn($plugin);
    $components[] = $derivative_non_inline_component->reveal();

    // Ensure that inline block component is returned.     $inline_component = $prophet->prophesize(SectionComponent::class);
    
$bit = array_pop($bits);
      if (empty($bits)) {
        $bits[] = $bit;
      }
    }

    $route_path = '/' . implode('/', $bits);

    $route = new Route($route_path$defaults);

    // Add access check parameters to the route.     $access_plugin = $this->getPlugin('access');
    if (!isset($access_plugin)) {
      // @todo Do we want to support a default plugin in getPlugin itself?       $access_plugin = Views::pluginManager('access')->createInstance('none');
    }
    $access_plugin->alterRouteDefinition($route);

    // Set the argument map, in order to support named parameters.     $route->setOption('_view_argument_map', $argument_map);
    $route->setOption('_view_display_plugin_id', $this->getPluginId());
    $route->setOption('_view_display_plugin_class', static::class);
    $route->setOption('_view_display_show_admin_links', $this->getOption('show_admin_links'));

    
->setValue($party_time);

    $page->find('css', '[value="Save"]')
      ->click();

    $url = Url::fromRoute('entity.action.collection');
    $this->assertSession()->pageTextContains('The action has been successfully saved.');
    $this->assertSession()->addressEquals($url);

    // Check storage.     $instance = Action::load($id);
    $configuration = $instance->getPlugin()->getConfiguration();
    $this->assertEquals(['party_time' => $party_time]$configuration);

    // Configuration should be shown in edit form.     $this->drupalGet($instance->toUrl('edit-form'));
    $this->assertSession()->checkboxChecked('having_a_party');
    $this->assertSession()->fieldValueEquals('party_time', $party_time);
  }

}
/** * 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>');
    

  public function getEnabledDefinitions(EditorInterface $editor): array {
    $definitions = $this->getDefinitions();
    ksort($definitions);

    $definitions_with_plugins_condition = [];

    foreach ($definitions as $plugin_id => $definition) {
      // Remove definition when plugin has conditions and they are not met.       if ($definition->hasConditions()) {
        $plugin = $this->getPlugin($plugin_id$editor);
        if ($this->isPluginDisabled($plugin$editor)) {
          unset($definitions[$plugin_id]);
        }
        else {
          // The `plugins` condition can only be evaluated at the end of           // gathering enabled definitions. ::isPluginDisabled() did not yet           // evaluate that condition.           if (array_key_exists('plugins', $definition->getConditions())) {
            $definitions_with_plugins_condition[$plugin_id] = $definition;
          }
        }
      }
return reset($build);
  }

  /** * {@inheritdoc} */
  public function viewMultiple(array $entities = []$view_mode = 'full', $langcode = NULL) {
    /** @var \Drupal\block\BlockInterface[] $entities */
    $build = [];
    foreach ($entities as $entity) {
      $entity_id = $entity->id();
      $plugin = $entity->getPlugin();

      $cache_tags = Cache::mergeTags($this->getCacheTags()$entity->getCacheTags());
      $cache_tags = Cache::mergeTags($cache_tags$plugin->getCacheTags());

      // Create the render array for the block as a whole.       // @see template_preprocess_block().       $build[$entity_id] = [
        '#cache' => [
          'keys' => ['entity_view', 'block', $entity->id()],
          'contexts' => Cache::mergeContexts(
            $entity->getCacheContexts(),
            

  public function title(BlockInterface $block) {
    // @todo Wrap "Configure " in <span class="visually-hidden"></span> once     // https://www.drupal.org/node/2359901 is fixed.     return $this->t('Configure @block', ['@block' => $block->getPlugin()->getPluginDefinition()['admin_label']]);
  }

  /** * {@inheritdoc} */
  public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form$form_state);

    // Create link to full block form.     $query = [];
    if ($destination = $this->getRequest()->query->get('destination')) {
      

  protected $uuid;

  /** * {@inheritdoc} */
  public function getQuestion() {
    $label = $this->sectionStorage
      ->getSection($this->delta)
      ->getComponent($this->uuid)
      ->getPlugin()
      ->label();

    return $this->t('Are you sure you want to remove the %label block?', ['%label' => $label]);
  }

  /** * {@inheritdoc} */
  public function getConfirmText() {
    return $this->t('Remove');
  }

  
/** * Tests the tag cache plugin. */
  public function testTagCaching() {
    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = \Drupal::service('renderer');
    $view = Views::getView('test_tag_cache');
    $build = $view->buildRenderable();
    $renderer->renderPlain($build);

    // Saving the view should invalidate the tags.     $cache_plugin = $view->display_handler->getPlugin('cache');
    $this->assertTrue($cache_plugin->cacheGet('results'), 'Results cache found.');
    $this->assertNotEmpty($this->getRenderCache($view), 'Output cache found.');

    $view->storage->save();

    $this->assertFalse($cache_plugin->cacheGet('results'), 'Results cache empty after the view is saved.');
    $this->assertFalse($this->getRenderCache($view), 'Output cache empty after the view is saved.');

    $view->destroy();
    $build = $view->buildRenderable();
    $renderer->renderPlain($build);

    

  protected function doTestMenuBlock() {
    $menu_id = $this->menu->id();
    $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. */
  
$this->executeMigration('search_page');
  }

  /** * Tests Drupal 6 search settings to Drupal 8 search page entity migration. */
  public function testSearchPage() {
    $id = 'node_search';
    /** @var \Drupal\search\Entity\SearchPage $search_page */
    $search_page = SearchPage::load($id);
    $this->assertSame($id$search_page->id());
    $configuration = $search_page->getPlugin()->getConfiguration();
    $this->assertSame([
      'comments' => 5,
      'promote' => 0,
      'recent' => 0,
      'relevance' => 2,
      'sticky' => 8,
      'views' => 1,
    ]$configuration['rankings']);
    $this->assertSame('node', $search_page->getPath());

    // Test that we can re-import using the EntitySearchPage destination.
$build = [
      '#cache' => [
        'tags' => $this->blockListCacheTags,
      ],
    ];
    // Load all region content assigned via blocks.     $cacheable_metadata_list = [];
    foreach ($this->blockRepository->getVisibleBlocksPerRegion($cacheable_metadata_list) as $region => $blocks) {
      /** @var \Drupal\block\BlockInterface[] $blocks */
      foreach ($blocks as $key => $block) {
        $block_plugin = $block->getPlugin();
        if ($block_plugin instanceof MainContentBlockPluginInterface) {
          $block_plugin->setMainContent($this->mainContent);
          $main_content_block_displayed = TRUE;
        }
        elseif ($block_plugin instanceof TitleBlockPluginInterface) {
          $block_plugin->setTitle($this->title);
        }
        elseif ($block_plugin instanceof MessagesBlockPluginInterface) {
          $messages_block_displayed = TRUE;
        }
        $build[$region][$key] = $this->blockViewBuilder->view($block);

        
Home | Imprint | This part of the site doesn't use cookies.