Extension example

$cache$info_parser$module_handler$state] = $this->getMocks();
    $info_parser->parse(Argument::any())->will(function D$args) {
      return Yaml::decode(file_get_contents('vfs://drupal_root/' . $args[0]));
    });

    $test_extension_list = new TestExtension('vfs://drupal_root', 'test_extension', $cache->reveal()$info_parser->reveal()$module_handler->reveal()$state->reveal(), 'testing');

    $extension_discovery = $this->prophesize(ExtensionDiscovery::class);
    $extension_scan_result = [];
    foreach ($extension_names as $extension_name) {
      $extension_scan_result[$extension_name] = new Extension('vfs://drupal_root', 'test_extension', "example/$extension_name/$extension_name.info.yml");
    }
    $extension_discovery->scan('test_extension')->willReturn($extension_scan_result);
    $test_extension_list->setExtensionDiscovery($extension_discovery->reveal());
    return $test_extension_list;
  }

  protected function getMocks() {
    $cache = $this->prophesize(CacheBackendInterface::class);
    $info_parser = $this->prophesize(InfoParserInterface::class);
    $module_handler = $this->prophesize(ModuleHandlerInterface::class);
    $state = $this->prophesize(StateInterface::class);
    
    // is possible, because loadActiveTheme() always loads the Twig theme     // engine. This is desired, because missing or malformed theme configuration     // should not leave the application in a broken state. By falling back to     // default output, the user is able to reconfigure the theme through the UI.     // Lastly, tests are expected to operate with no theme by default, so as to     // only assert the original theme output of modules (unless a test manually     // installs a specific theme).     if (empty($themes) || !$theme_name || !isset($themes[$theme_name])) {
      $theme_name = 'core';
      // /core/core.info.yml does not actually exist, but is required because       // Extension expects a pathname.       $active_theme = $this->getActiveTheme(new Extension($this->root, 'theme', 'core/core.info.yml'));

      // Early-return and do not set state, because the initialized $theme_name       // differs from the original $theme_name.       return $active_theme;
    }

    // Find all our ancestor themes and put them in an array.     $base_themes = [];
    $ancestor = $theme_name;
    while ($ancestor && isset($themes[$ancestor]->base_theme)) {
      $ancestor = $themes[$ancestor]->base_theme;
      

        $this->connection->rollBack();

        try {
            $this->connection->executeStatement('ALTER TABLE `product` ADD COLUMN my_tax_id binary(16) NULL');
        } catch (Exception) {
        }

        $this->connection->beginTransaction();

        $this->getContainer()->get(ProductDefinition::class)->getFields()->addNewField(
            (new ManyToOneAssociationField('myTax', 'my_tax_id', TaxDefinition::class, 'id'))->addFlags(new ApiAware()new Extension())
        );
        $this->getContainer()->get(ProductDefinition::class)->getFields()->addNewField(
            (new FkField('my_tax_id', 'myTaxId', TaxDefinition::class))->addFlags(new ApiAware()new Extension())
        );

        $id = Uuid::randomHex();

        $data = [
            'id' => $id,
            'name' => 'test',
            'productNumber' => $id,
            
public function since(): ?string
    {
        return '6.0.0.0';
    }

    protected function defineFields(): FieldCollection
    {
        return new FieldCollection(
            [
                (new IdField('id', 'id'))->addFlags(new ApiAware()new Required()new PrimaryKey()),
                new FkField('simple_id', 'simpleId', SimpleDefinition::class),
                (new JsonField('extended_json_field', 'extendedJsonField'))->addFlags(new Extension()),

                new OneToOneAssociationField('simpleIdField', 'simple_id', 'id_field', SimpleDefinition::class, false),
            ]
        );
    }
}
$module_handler->loadAll();
    $this->assertTrue($module_handler->isLoaded());
  }

  /** * Confirm we get back the modules set in the constructor. * * @covers ::getModuleList */
  public function testGetModuleList() {
    $this->assertEquals($this->getModuleHandler()->getModuleList()[
      'module_handler_test' => new Extension($this->root, 'module', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test/module_handler_test.info.yml', 'module_handler_test.module'),
    ]);
  }

  /** * Confirm we get back a module from the module list. * * @covers ::getModule */
  public function testGetModuleWithExistingModule() {
    $this->assertEquals($this->getModuleHandler()->getModule('module_handler_test')new Extension($this->root, 'module', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test/module_handler_test.info.yml', 'module_handler_test.module'));
  }

  

#[Package('buyers-experience')] class SeoUrlAssociationField extends OneToManyAssociationField
{
    public function __construct(
        string $propertyName,
        private readonly string $routeName,
        string $localField = 'id'
    ) {
        parent::__construct($propertyName, SeoUrlDefinition::class, 'foreign_key', $localField);
        $this->addFlags(new Extension());
    }

    public function getRouteName(): string
    {
        Feature::triggerDeprecationOrThrow(
            'v6.6.0.0',
            Feature::deprecatedMethodMessage(self::class, __METHOD__, 'v6.6.0.0')
        );

        return $this->routeName;
    }

    

  public function __construct($root, array $module_list, CacheBackendInterface $cache_backend) {
    $this->root = $root;
    $this->moduleList = [];
    foreach ($module_list as $name => $module) {
      $this->moduleList[$name] = new Extension($this->root, $module['type']$module['pathname']$module['filename']);
    }
    $this->cacheBackend = $cache_backend;
  }

  /** * {@inheritdoc} */
  public function load($name) {
    if (isset($this->loadedFiles[$name])) {
      return TRUE;
    }

    
$current_modules = array_fill_keys(array_keys($current_module_filenames), 0);
        $current_modules = module_config_sort(array_merge($current_modules$extension_config->get('module')));
        $module_filenames = [];
        foreach ($current_modules as $name => $weight) {
          if (isset($current_module_filenames[$name])) {
            $module_filenames[$name] = $current_module_filenames[$name];
          }
          else {
            $module_path = \Drupal::service('extension.list.module')->getPath($name);
            $pathname = "$module_path/$name.info.yml";
            $filename = file_exists($module_path . "/$name.module") ? "$name.module" : NULL;
            $module_filenames[$name] = new Extension($this->root, 'module', $pathname$filename);
          }
        }

        // Update the module handler in order to have the correct module list         // for the kernel update.         $this->moduleHandler->setModuleList($module_filenames);

        // Clear the static cache of the "extension.list.module" service to pick         // up the new module, since it merges the installation status of modules         // into its statically cached list.         \Drupal::service('extension.list.module')->reset();

        
foreach ($this->defaultFields() as $field) {
            $fields->add($field);
        }

        foreach ($this->extensions as $extension) {
            $new = new FieldCollection();

            $extension->extendFields($new);

            foreach ($new as $field) {
                $field->addFlags(new Extension());

                if ($field instanceof AssociationField) {
                    $fields->add($field);

                    continue;
                }

                if ($field->is(Runtime::class)) {
                    $fields->add($field);

                    continue;
                }
foreach ($extensions_by_type[$type] as $name => $extension) {
        $files_by_type_and_name[$type][$name] = $extension->getPathname();
      }
      if ($type === 'profile') {
        // Set profile directories for discovery of the other extension types.         $extension_discovery->setProfileDirectories(['my_profile' => 'profiles/my_profile']);
      }
    }

    $this->assertEquals($files_by_type_and_name_expected$files_by_type_and_name);

    $extension_expected = new Extension($root, 'module', 'core/modules/system/system.info.yml', 'system.module');
    $extension_expected->subpath = 'modules/system';
    $extension_expected->origin = 'core';
    $this->assertEquals($extension_expected$extensions_by_type['module']['system'], 'system');

    $extension_expected = new Extension($root, 'theme_engine', 'core/themes/engines/twig/twig.info.yml', 'twig.engine');
    $extension_expected->subpath = 'themes/engines/twig';
    $extension_expected->origin = 'core';
    $this->assertEquals($extension_expected$extensions_by_type['theme_engine']['twig'], 'twig');
  }

  /** * Tests changing extension discovery file cache objects to arrays. * * @covers ::scan * @runInSeparateProcess */

  public function testRebuildThemeData() {
    $this->themeList->expects($this->once())
      ->method('reset')
      ->willReturnSelf();
    $this->themeList->expects($this->once())
      ->method('getList')
      ->willReturn([
        'stark' => new Extension($this->root, 'theme', 'core/themes/stark/stark.info.yml', 'stark.theme'),
      ]);

    $theme_data = $this->themeHandler->rebuildThemeData();
    $this->assertCount(1, $theme_data);
    $info = $theme_data['stark'];

    // Ensure some basic properties.     $this->assertInstanceOf('Drupal\Core\Extension\Extension', $info);
    $this->assertEquals('stark', $info->getName());
    $this->assertEquals('core/themes/stark/stark.info.yml', $info->getPathname());
    $this->assertEquals('core/themes/stark/stark.theme', $info->getExtensionPathname());

  }
    parent::__construct($environment$class_loader, FALSE, $app_root);

    // Prime the module list and corresponding Extension objects.     // @todo Remove System module. Needed because     // \Drupal\Core\Datetime\DateFormatter has a (needless) dependency on the     // 'date_format' entity, so calls to DateFormatter::format() and     // DateFormatter::formatInterval() cause a plugin not found exception.     $this->moduleList = [
      'system' => 0,
    ];
    $this->moduleData = [
      'system' => new Extension($this->root, 'module', 'core/modules/system/system.info.yml', 'system.module'),
    ];
  }

  /** * {@inheritdoc} */
  public function boot() {
    // Ensure that required Settings exist.     if (!Settings::getAll()) {
      new Settings([
        'hash_salt' => 'run-tests',
        

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

    $this->directoryList = [
      'system' => 'core/modules/system',
    ];

    $this->themeHandler = $this->createMock('Drupal\Core\Extension\ThemeHandlerInterface');

    $theme = new Extension($this->root, 'theme', 'core/themes/olivero', 'olivero.info.yml');
    $theme->status = 1;
    $theme->info = ['name' => 'olivero'];
    $this->themeHandler->expects($this->any())
      ->method('listInfo')
      ->willReturn([
        'olivero' => $theme,
      ]);
    $this->themeHandler->expects($this->any())
      ->method('hasUi')
      ->with('olivero')
      ->willReturn(TRUE);
    

        return 'fk_extension_test';
    }

    protected function defineFields(): FieldCollection
    {
        return new FieldCollection([
            (new IdField('id', 'id'))->addFlags(new ApiAware()new PrimaryKey()),
            (new StringField('name', 'name'))->addFlags(new ApiAware()),
            (new FkField('normal_fk', 'normalFk', ProductDefinition::class))->addFlags(new ApiAware()),

            (new FkField('extended_fk', 'extendedFk', ProductDefinition::class))->addFlags(new ApiAware()new Extension()),
        ]);
    }
}
/** * @coversDefaultClass \Drupal\Core\Extension\Extension * @group Extension * @group legacy */
class LegacyExtensionTest extends UnitTestCase {

  /** * @covers ::__call */
  public function testDeprecatedCall() {
    $extension = new Extension($this->root, 'theme', 'core/themes/stark/stark.info.yml', 'stark.theme');
    $file = $extension->getFileInfo();
    $this->expectDeprecation('Drupal\Core\Extension\Extension::__call(\'getCTime\') is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use \Drupal\Core\Extension\Extension::getFileInfo() instead. See https://www.drupal.org/node/3322608');
    $this->assertSame($file->getCTime()$extension->getCTime());
    $this->expectDeprecation('Drupal\Core\Extension\Extension::__call(\'getMTime\') is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use \Drupal\Core\Extension\Extension::getFileInfo() instead. See https://www.drupal.org/node/3322608');
    $this->assertSame($file->getMTime()$extension->getMTime());
  }

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