setRoot example

/** * {@inheritdoc} */
  public function loadSubtreeData($id$max_relative_depth = NULL) {
    $tree = [];
    $root = $this->loadFull($id);
    if (!$root) {
      return $tree;
    }
    $parameters = new MenuTreeParameters();
    $parameters->setRoot($id)->onlyEnabledLinks();
    return $this->loadTreeData($root['menu_name']$parameters);
  }

  /** * {@inheritdoc} */
  public function menuNameInUse($menu_name) {
    $query = $this->connection->select($this->table, NULL, $this->options);
    $query->addField($this->table, 'mlid');
    $query->condition('menu_name', $menu_name);
    $query->range(0, 1);
    
/** * Tests permissions provided by YML files. * * @covers ::__construct * @covers ::getPermissions * @covers ::buildPermissionsYaml * @covers ::moduleProvidesPermissions */
  public function testBuildPermissionsYaml() {
    vfsStreamWrapper::register();
    $root = new vfsStreamDirectory('modules');
    vfsStreamWrapper::setRoot($root);

    $this->moduleHandler = $this->createMock('Drupal\Core\Extension\ModuleHandlerInterface');
    $this->moduleHandler->expects($this->once())
      ->method('getModuleDirectories')
      ->willReturn([
        'module_a' => vfsStream::url('modules/module_a'),
        'module_b' => vfsStream::url('modules/module_b'),
        'module_c' => vfsStream::url('modules/module_c'),
      ]);

    $url = vfsStream::url('modules');
    
$tree = $this->linkTree->load('mock', $parameters);

    $count = function Darray $tree) {
      $sum = function D$carry, MenuLinkTreeElement $item) {
        return $carry + $item->count();
      };
      return array_reduce($tree$sum);
    };

    $this->assertEquals(8, $count($tree));
    $parameters = new MenuTreeParameters();
    $parameters->setRoot('test.example2');
    $tree = $this->linkTree->load($instance->getMenuName()$parameters);
    $top_link = reset($tree);
    $this->assertCount(1, $top_link->subtree);
    $child = reset($top_link->subtree);
    $this->assertEquals($links[3]->getPluginId()$child->link->getPluginId());
    $height = $this->linkTree->getSubtreeHeight('test.example2');
    $this->assertEquals(3, $height);
  }

}


    // For menu blocks with start level greater than 1, only show menu items     // from the current active trail. Adjust the root according to the current     // position in the menu in order to determine if we can show the subtree.     if ($level > 1) {
      if (count($parameters->activeTrail) >= $level) {
        // Active trail array is child-first. Reverse it, and pull the new menu         // root based on the parent of the configured start level.         $menu_trail_ids = array_reverse(array_values($parameters->activeTrail));
        $menu_root = $menu_trail_ids[$level - 1];
        $parameters->setRoot($menu_root)->setMinDepth(1);
        if ($depth > 0) {
          $parameters->setMaxDepth(min($level - 1 + $depth - 1, $this->menuTree->maxDepth()));
        }
      }
      else {
        return [];
      }
    }

    $tree = $this->menuTree->load($menu_name$parameters);
    $manipulators = [
      [
$parameters = new MenuTreeParameters();
    $parameters->excludeRoot();
    $this->assertEquals(1, $parameters->minDepth);
  }

  /** * @covers ::serialize * @covers ::unserialize */
  public function testSerialize() {
    $parameters = new MenuTreeParameters();
    $parameters->setRoot(1);
    $parameters->setMinDepth('2');
    $parameters->setMaxDepth('9');
    $parameters->addExpandedParents(['', 'foo']);
    $parameters->setActiveTrail(['', 'bar']);

    $after_serialize = unserialize(serialize($parameters));
    $this->assertSame('1', $after_serialize->root);
    $this->assertSame(2, $after_serialize->minDepth);
    $this->assertSame(9, $after_serialize->maxDepth);
    $this->assertSame(['', 'foo']$after_serialize->expandedParents);
    $this->assertSame(['bar']$after_serialize->activeTrail);
  }
protected function setUp(): void {
    // Ensure that FileCacheFactory has a prefix.     FileCacheFactory::setPrefix('prefix');
  }

  /** * Tests if filename is output for a broken YAML file. */
  public function testFilenameForBrokenYml() {
    vfsStreamWrapper::register();
    $root = new vfsStreamDirectory('modules');
    vfsStreamWrapper::setRoot($root);
    $url = vfsStream::url('modules');

    mkdir($url . '/test_broken');
    file_put_contents($url . '/test_broken/test_broken.test.yml', "broken:\n:");

    $this->expectException(InvalidDataTypeException::class);
    $this->expectExceptionMessage('vfs://modules/test_broken/test_broken.test.yml');

    $directories = ['test_broken' => $url . '/test_broken'];
    $discovery = new YamlDiscovery('test', $directories);
    $discovery->findAll();
  }

  public function getAdminBlock(MenuLinkInterface $instance) {
    $content = [];
    // Only find the children of this link.     $link_id = $instance->getPluginId();
    $parameters = new MenuTreeParameters();
    $parameters->setRoot($link_id)->excludeRoot()->setTopLevelOnly()->onlyEnabledLinks();
    $tree = $this->menuTree->load(NULL, $parameters);
    $manipulators = [
      ['callable' => 'menu.default_tree_manipulators:checkAccess'],
      ['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
    ];
    $tree = $this->menuTree->transform($tree$manipulators);
    foreach ($tree as $key => $element) {
      // Only render accessible links.       if (!$element->access->isAllowed()) {
        // @todo Bubble cacheability metadata of both accessible and         // inaccessible links. Currently made impossible by the way admin

  public function overview($link_id) {
    // Check for status report errors.     if ($this->currentUser()->hasPermission('administer site configuration') && $this->systemManager->checkRequirements()) {
      $this->messenger()->addError($this->t('One or more problems were detected with your Drupal installation. Check the <a href=":status">status report</a> for more information.', [':status' => Url::fromRoute('system.status')->toString()]));
    }
    // Load all menu links below it.     $parameters = new MenuTreeParameters();
    $parameters->setRoot($link_id)->excludeRoot()->setTopLevelOnly()->onlyEnabledLinks();
    $tree = $this->menuLinkTree->load(NULL, $parameters);
    $manipulators = [
      ['callable' => 'menu.default_tree_manipulators:checkAccess'],
      ['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
    ];
    $tree = $this->menuLinkTree->transform($tree$manipulators);
    $tree_access_cacheability = new CacheableMetadata();
    $blocks = [];
    foreach ($tree as $key => $element) {
      $tree_access_cacheability = $tree_access_cacheability->merge(CacheableMetadata::createFromObject($element->access));

      
/** * Make sure AnnotatedClassDiscovery never tries to autoload bad annotations. * * @dataProvider provideBadAnnotations * * @coversNothing */
  public function testAutoloadBadAnnotations($annotation) {
    // Set up a class file in vfsStream.     vfsStreamWrapper::register();
    $root = new vfsStreamDirectory('root');
    vfsStreamWrapper::setRoot($root);

    FileCacheFactory::setPrefix(__CLASS__);

    // Make a directory for discovery.     $url = vfsStream::url('root');
    mkdir($url . '/DrupalTest');

    // Create a class docblock with our annotation.     $php_file = "<?php\nnamespace DrupalTest;\n/**\n";
    $php_file .= " * @$annotation\n";
    $php_file .= " */\nclass TestClass {}";
    
protected function setUp(): void {
    // Ensure that FileCacheFactory has a prefix.     FileCacheFactory::setPrefix('prefix');
  }

  /** * Tests the YAML file discovery. */
  public function testDiscovery() {
    vfsStreamWrapper::register();
    $root = new vfsStreamDirectory('modules');
    vfsStreamWrapper::setRoot($root);
    $url = vfsStream::url('modules');

    mkdir($url . '/test_1');
    file_put_contents($url . '/test_1/test_1.test.yml', 'name: test');
    file_put_contents($url . '/test_1/test_2.test.yml', 'name: test');

    mkdir($url . '/test_2');
    file_put_contents($url . '/test_2/test_3.test.yml', 'name: test');
    // Write an empty YAML file.     file_put_contents($url . '/test_2/test_4.test.yml', '');

    
/** * Returns all top level menu links. * * @return \Drupal\Core\Menu\MenuLinkInterface[] */
  protected function getTopLevelMenuLinks() {
    $menu_tree = \Drupal::menuTree();

    // The system.admin link is normally the parent of all top-level admin links.     $parameters = new MenuTreeParameters();
    $parameters->setRoot('system.admin')->excludeRoot()->setTopLevelOnly()->onlyEnabledLinks();
    $tree = $menu_tree->load(NULL, $parameters);
    $manipulators = [
      ['callable' => 'menu.default_tree_manipulators:checkAccess'],
      ['callable' => 'menu.default_tree_manipulators:flatten'],
    ];
    $tree = $menu_tree->transform($tree$manipulators);

    // Transform the tree to a list of menu links.     $menu_links = [];
    foreach ($tree as $element) {
      $menu_links[] = $element->link;
    }
->setCode(Expression::EXPRESSION_FAILED_ERROR)
            ->assertRaised();
    }

    public function testSucceedingExpressionAtPropertyLevel()
    {
        $constraint = new Expression('value == this.data');

        $object = new Entity();
        $object->data = '1';

        $this->setRoot($object);
        $this->setPropertyPath('data');
        $this->setProperty($object, 'data');

        $this->validator->validate('1', $constraint);

        $this->assertNoViolation();
    }

    public function testFailingExpressionAtPropertyLevel()
    {
        $constraint = new Expression([
            

  public function testGetUpgradeStates($modules_to_enable$files$field_plugins$migrations$source_system_data$expected_7$expected_6) {
    $fieldPluginManager = $this->prophesize(MigrateFieldPluginManagerInterface::class);
    $fieldPluginManager->getDefinitions()->willReturn($field_plugins);
    $moduleHandler = $this->prophesize(ModuleHandlerInterface::class);
    $moduleHandler->getModuleList()->willReturn($modules_to_enable);
    vfsStreamWrapper::register();
    $root = new vfsStreamDirectory('modules');
    vfsStreamWrapper::setRoot($root);
    $url = vfsStream::url('modules');

    foreach ($files as $module => $contents) {
      $path = $url . '/' . $module . '/migrations/state';
      mkdir($path, '0755', TRUE);
      file_put_contents($path . '/' . $module . '.migrate_drupal.yml', $contents);
    }
    $moduleHandler->getModuleDirectories()
      ->willReturn(array_combine(array_keys($files)array_map(function D$module) use ($url) {
        return $url . '/' . $module;
      }array_keys($files))));
    
Home | Imprint | This part of the site doesn't use cookies.