YamlDiscovery example

$this->controllerResolver = $controller_resolver;
  }

  /** * Gets the YAML discovery. * * @return \Drupal\Core\Discovery\YamlDiscovery * The YAML discovery. */
  protected function getYamlDiscovery() {
    if (!isset($this->yamlDiscovery)) {
      $this->yamlDiscovery = new YamlDiscovery('permissions', $this->moduleHandler->getModuleDirectories());
    }
    return $this->yamlDiscovery;
  }

  /** * {@inheritdoc} */
  public function getPermissions() {
    $all_permissions = $this->buildPermissionsYaml();

    return $this->sortPermissions($all_permissions);
  }
->disableOriginalConstructor()
      ->getMock();
    $property = new \ReflectionProperty('Drupal\Core\Menu\LocalTaskManager', 'moduleHandler');
    $property->setValue($manager$module_handler);
    // Set all the modules as being existent.     $module_handler->expects($this->any())
      ->method('moduleExists')
      ->willReturnCallback(function D$module) use ($module_dirs) {
        return isset($module_dirs[$module]);
      });

    $pluginDiscovery = new YamlDiscovery('links.task', $module_dirs);
    $pluginDiscovery = new ContainerDerivativeDiscoveryDecorator($pluginDiscovery);
    $property = new \ReflectionProperty('Drupal\Core\Menu\LocalTaskManager', 'discovery');
    $property->setValue($manager$pluginDiscovery);

    $method = new \ReflectionMethod('Drupal\Core\Menu\LocalTaskManager', 'alterInfo');
    $method->invoke($manager, 'local_tasks');

    $plugin_stub = $this->createMock('Drupal\Core\Menu\LocalTaskInterface');
    $factory = $this->createMock('Drupal\Component\Plugin\Factory\FactoryInterface');
    $factory->expects($this->any())
      ->method('createInstance')
      
$this->moduleHandler = $module_handler;
    $this->account = $account;
    $this->alterInfo('menu_local_actions');
    $this->setCacheBackend($cache_backend, 'local_action_plugins:' . $language_manager->getCurrentLanguage()->getId()['local_action']);
  }

  /** * {@inheritdoc} */
  protected function getDiscovery() {
    if (!isset($this->discovery)) {
      $yaml_discovery = new YamlDiscovery('links.action', $this->moduleHandler->getModuleDirectories());
      $yaml_discovery->addTranslatableProperty('title', 'title_context');
      $this->discovery = new ContainerDerivativeDiscoveryDecorator($yaml_discovery);
    }
    return $this->discovery;
  }

  /** * {@inheritdoc} */
  public function getTitle(LocalActionInterface $local_action) {
    $controller = [$local_action, 'getTitle'];
    
$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();
  }

}
    $definition['parent'] = (string) $definition['parent'];
    $definition['id'] = $plugin_id;
  }

  /** * Gets the plugin discovery. * * @return \Drupal\Component\Plugin\Discovery\DiscoveryInterface */
  protected function getDiscovery() {
    if (!isset($this->discovery)) {
      $yaml_discovery = new YamlDiscovery('links.menu', $this->moduleHandler->getModuleDirectories());
      $yaml_discovery->addTranslatableProperty('title', 'title_context');
      $yaml_discovery->addTranslatableProperty('description', 'description_context');
      $this->discovery = new ContainerDerivativeDiscoveryDecorator($yaml_discovery);
    }
    return $this->discovery;
  }

  /** * Gets the plugin factory. * * @return \Drupal\Component\Plugin\Factory\FactoryInterface */
// Write an empty YAML file.     file_put_contents($url . '/test_2/test_4.test.yml', '');

    // Set up the directories to search.     $directories = [
      'test_1' => $url . '/test_1',
      'test_2' => $url . '/test_1',
      'test_3' => $url . '/test_2',
      'test_4' => $url . '/test_2',
    ];

    $discovery = new YamlDiscovery('test', $directories);
    $data = $discovery->findAll();

    $this->assertCount(4, $data);
    $this->assertArrayHasKey('test_1', $data);
    $this->assertArrayHasKey('test_2', $data);
    $this->assertArrayHasKey('test_3', $data);
    $this->assertArrayHasKey('test_4', $data);

    foreach (['test_1', 'test_2', 'test_3'] as $key) {
      $this->assertArrayHasKey('name', $data[$key]);
      $this->assertEquals('test', $data[$key]['name']);
    }
$definition['source_module'],
          $definition['destination_module'],
        ]);
      }
    }

    // Get the declared migration state information from .migrate_drupal.yml     // and build an array of source modules and there migration state. The     // destination is not used yet but can be later for validating the     // source/destination pairs with the actual source/destination pairs in the     // migrate plugins.     $system_info = (new YamlDiscovery('migrate_drupal', array_map(function D$value) {
      return $value . '/migrations/state/';
    }, \Drupal::moduleHandler()->getModuleDirectories())))->findAll();

    $declared = [
      MigrationState::FINISHED => [],
      MigrationState::NOT_FINISHED => [],
    ];
    foreach ($system_info as $module => $info) {
      foreach (array_keys($declared) as $state) {
        if (isset($info[$state][$version])) {
          foreach ($info[$state][$version] as $source => $destination) {
            


  /** * Retrieves all defined routes from .routing.yml files. * * @return array * The defined routes, keyed by provider. */
  protected function getRouteDefinitions() {
    // Always instantiate a new YamlDiscovery object so that we always search on     // the up-to-date list of modules.     $discovery = new YamlDiscovery('routing', $this->moduleHandler->getModuleDirectories());
    return $discovery->findAll();
  }

}
$this->themeHandler = $theme_handler;
    $this->setStringTranslation($string_translation);
    $this->alterInfo('breakpoints');
    $this->setCacheBackend($cache_backend, 'breakpoints', ['breakpoints']);
  }

  /** * {@inheritdoc} */
  protected function getDiscovery() {
    if (!isset($this->discovery)) {
      $this->discovery = new YamlDiscovery('breakpoints', $this->moduleHandler->getModuleDirectories() + $this->themeHandler->getThemeDirectories());
      $this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery);
    }
    return $this->discovery;
  }

  /** * {@inheritdoc} */
  public function processDefinition(&$definition$plugin_id) {
    parent::processDefinition($definition$plugin_id);
    // Allow custom groups and therefore more than one group per extension.
$this->account = $account;
    $this->moduleHandler = $module_handler;
    $this->alterInfo('local_tasks');
    $this->setCacheBackend($cache, 'local_task_plugins:' . $language_manager->getCurrentLanguage()->getId()['local_task']);
  }

  /** * {@inheritdoc} */
  protected function getDiscovery() {
    if (!isset($this->discovery)) {
      $yaml_discovery = new YamlDiscovery('links.task', $this->moduleHandler->getModuleDirectories());
      $yaml_discovery->addTranslatableProperty('title', 'title_context');
      $this->discovery = new ContainerDerivativeDiscoveryDecorator($yaml_discovery);
    }
    return $this->discovery;
  }

  /** * {@inheritdoc} */
  public function processDefinition(&$definition$plugin_id) {
    parent::processDefinition($definition$plugin_id);
    
$this->moduleHandler = $module_handler;
    $this->requestStack = $request_stack;
    $this->alterInfo('contextual_links_plugins');
    $this->setCacheBackend($cache_backend, 'contextual_links_plugins:' . $language_manager->getCurrentLanguage()->getId()['contextual_links_plugins']);
  }

  /** * {@inheritdoc} */
  protected function getDiscovery() {
    if (!isset($this->discovery)) {
      $yaml_discovery = new YamlDiscovery('links.contextual', $this->moduleHandler->getModuleDirectories());
      $yaml_discovery->addTranslatableProperty('title', 'title_context');
      $this->discovery = new ContainerDerivativeDiscoveryDecorator($yaml_discovery);
    }
    return $this->discovery;
  }

  /** * {@inheritdoc} */
  public function processDefinition(&$definition$plugin_id) {
    parent::processDefinition($definition$plugin_id);

    

  protected function setUp(): void {
    parent::setUp();

    $base_path = __DIR__ . '/Fixtures';
    // Set up the directories to search.     $directories = [
      'test_1' => $base_path . '/test_1',
      'test_2' => $base_path . '/test_2',
    ];

    $this->discovery = new YamlDiscovery('test', $directories);
  }

  /** * Tests the getDefinitions() method. */
  public function testGetDefinitions() {
    $definitions = $this->discovery->getDefinitions();

    $this->assertIsArray($definitions);
    $this->assertCount(4, $definitions);

    
      // of installed themes.       $directories = [];
      foreach ($this->moduleHandler->getModuleList() as $name => $module) {
        $directories[$name] = $module->getPath();
      }
      foreach ($this->themeHandler->listInfo() as $theme) {
        $directories[$theme->getName()] = $theme->getPath();
      }

      // Check for files named MODULE.config_translation.yml and       // THEME.config_translation.yml in module/theme roots.       $this->discovery = new YamlDiscovery('config_translation', $directories);
      $this->discovery = new InfoHookDecorator($this->discovery, 'config_translation_info');
      $this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery);
    }
    return $this->discovery;
  }

  /** * {@inheritdoc} */
  public function getMappers(RouteCollection $collection = NULL) {
    $mappers = [];
    

  public function testMigrationState() {
    // Install all available modules.     $module_handler = $this->container->get('module_handler');
    $all_modules = $this->coreModuleListDataProvider();
    $modules_enabled = $module_handler->getModuleList();
    $modules_to_enable = array_keys(array_diff_key($all_modules$modules_enabled));
    $this->enableModules($modules_to_enable);

    // Modules with a migrate_drupal.yml file.     $has_state_file = (new YamlDiscovery('migrate_drupal', array_map(function D$value) {
      return $value . '/migrations/state';
    }$module_handler->getModuleDirectories())))->findAll();

    foreach ($this->stateFileRequired as $module) {
      $this->assertArrayHasKey($module$has_state_filesprintf("Module '%s' should have a migrate_drupal.yml file", $module));
    }
    $this->assertSameSize($this->stateFileRequired, $has_state_file);
  }

}
/** * Gets migration state information from *.migrate_drupal.yml. * * @return array * An association array keyed by module of the finished and not_finished * migrations for each module. * */
  protected function getMigrationStates() {
    // Always instantiate a new YamlDiscovery object so that we always search on     // the up-to-date list of modules.     $discovery = new YamlDiscovery('migrate_drupal', array_map(function D$value) {
      return $value . '/migrations/state';
    }$this->moduleHandler->getModuleDirectories()));
    return $discovery->findAll();
  }

  /** * Determines migration state for each source module enabled on the source. * * If there are no migrations for a module and no declared state the state is * set to NOT_FINISHED. When a module does not need any migrations, such as * Overlay, a state of finished is declared in system.migrate_drupal.yml. * * If there are migrations for a module the following happens. If the * destination module is 'core' the state is set to FINISHED. If there are * any occurrences of 'not_finished' in the *.migrate_drupal.yml information * for this source module then the state is set to NOT_FINISHED. And finally, * if there is an occurrence of 'finished' the state is set to FINISHED. * * @param string $version * The legacy drupal version. * @param array $source_system_data * The data from the source site system table. * @param array $migrations * An array of migrations. * * @return array * An associative array of data with keys of state, source modules and a * value which is a comma separated list of destination modules. * Example. * * @code * [ * 'finished' => [ * 'menu' => [ * 'menu_link_content','menu_ui','system' * ] * ], * ] * @endcode */
Home | Imprint | This part of the site doesn't use cookies.