getBundles example

// such a bundle does not exist, so treat the argument as path                 $path = $input->getArgument('bundle');

                $transPaths = [$path.'/translations'];
                $codePaths = [$path.'/templates'];

                if (!is_dir($transPaths[0])) {
                    throw new InvalidArgumentException(sprintf('"%s" is neither an enabled bundle nor a directory.', $transPaths[0]));
                }
            }
        } elseif ($input->getOption('all')) {
            foreach ($kernel->getBundles() as $bundle) {
                $bundleDir = $bundle->getPath();
                $transPaths[] = is_dir($bundleDir.'/Resources/translations') ? $bundleDir.'/Resources/translations' : $bundle->getPath().'/translations';
                $codePaths[] = is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundle->getPath().'/templates';
            }
        }

        // Extract used messages         $extractedCatalogue = $this->extractMessages($locale$codePaths);

        // Load defined messages         $currentCatalogue = $this->loadCurrentMessages($locale$transPaths);

        

    $form['add'] = [
      '#type' => 'container',
      '#attributes' => ['class' => ['form--inline', 'clearfix']],
    ];

    $bundles = $this->bundleInfoService->getAllBundleInfo();
    $existing_field_storage_options = $this->getExistingFieldStorageOptions();

    $rows = [];
    foreach ($existing_field_storage_options as $field) {
      $field_bundles = $field['field_storage']->getBundles();
      $summary = $this->fieldTypePluginManager->getStorageSettingsSummary($field['field_storage']);
      $cardinality = $field['field_storage']->getCardinality();
      $readable_cardinality = $cardinality === -1 ? $this->t('Unlimited') : new PluralTranslatableMarkup(1, 'Single value', 'Multiple values: @cardinality', ['@cardinality' => $cardinality]);

      // Remove empty values.       $list = array_filter([...$summary$readable_cardinality]);
      $settings_summary = [
        '#theme' => 'item_list',
        '#items' => $list,
        '#attributes' => [
          'class' => ['field-settings-summary-cell'],
        ],
public static function loadByName($entity_type_id$field_name) {
    return \Drupal::entityTypeManager()->getStorage('field_storage_config')->load($entity_type_id . '.' . $field_name);
  }

  /** * {@inheritdoc} */
  public function isDeletable() {
    // The field storage is not deleted, is configured to be removed when there     // are no fields, the field storage has no bundles, and field storages are     // not in the process of being deleted.     return !$this->deleted && !$this->persist_with_no_fields && count($this->getBundles()) == 0 && !static::$inDeletion;
  }

  /** * {@inheritdoc} */
  public function getIndexes() {
    return $this->indexes;
  }

  /** * {@inheritdoc} */

    public function __construct(
        private readonly KernelInterface $kernel,
        private readonly Connection $connection
    ) {
    }

    public function buildNamespaceHierarchy(array $namespaceHierarchy): array
    {
        $bundles = [];

        foreach ($this->kernel->getBundles() as $bundle) {
            if (!$bundle instanceof Bundle) {
                continue;
            }

            $bundlePath = $bundle->getPath();

            $directory = $bundlePath . '/Resources/views';

            if (!file_exists($directory)) {
                continue;
            }

            
$this->assertSession()->statusCodeEquals(200);
  }

  /** * Tests that persistent field storage appears in the field UI. */
  protected function addPersistentFieldStorage() {
    $field_storage = FieldStorageConfig::loadByName('node', $this->fieldName);
    // Persist the field storage even if there are no fields.     $field_storage->set('persist_with_no_fields', TRUE)->save();
    // Delete all instances of the field.     foreach ($field_storage->getBundles() as $node_type) {
      // Delete all the body field instances.       $this->drupalGet('admin/structure/types/manage/' . $node_type . '/fields/node.' . $node_type . '.' . $this->fieldName);
      $this->clickLink('Delete');
      $this->submitForm([], 'Delete');
    }
    // Check "Re-use existing field" appears.     $this->drupalGet('admin/structure/types/manage/page/fields');
    $this->assertSession()->pageTextContains('Re-use an existing field');

    // Ensure that we test with a label that contains HTML.     $label = $this->randomString(4) . '<br/>' . $this->randomString(4);
    
public function testGetClassLoader(): void
    {
        $loader = new StaticKernelPluginLoader($this->classLoader);
        static::assertSame($this->classLoader, $loader->getClassLoader());
    }

    public function testGetBundlesNoInit(): void
    {
        $activePluginData = $this->getActivePlugin()->jsonSerialize();
        $loader = new StaticKernelPluginLoader($this->classLoader, null, [$activePluginData]);

        $bundles = iterator_to_array($loader->getBundles());

        static::assertEmpty($bundles);
    }

    public function testGetBundlesNoPlugins(): void
    {
        $loader = new StaticKernelPluginLoader($this->classLoader);
        $loader->initializePlugins(TEST_PROJECT_DIR);

        $bundles = iterator_to_array($loader->getBundles());

        
return $snippets;
    }

    /** * @return array<int, string> */
    private function getPluginPaths(): array
    {
        $plugins = $this->kernel->getPluginLoader()->getPluginInstances()->all();
        $activePlugins = $this->kernel->getPluginLoader()->getPluginInstances()->getActives();
        $bundles = $this->kernel->getBundles();
        $paths = [];

        foreach ($activePlugins as $plugin) {
            $pluginPath = $plugin->getPath() . '/Resources/app/administration';
            if (!file_exists($pluginPath)) {
                continue;
            }

            $paths[] = $pluginPath;
        }

        
$instanciatedBundleNames = [];

        foreach ($bundles as $class => $envs) {
            if (isset($envs['all']) || isset($envs[$this->environment])) {
                $bundle = new $class();
                $instanciatedBundleNames[] = $bundle->getName();

                yield $bundle;
            }
        }

        yield from $this->pluginLoader->getBundles($this->getKernelParameters()$instanciatedBundleNames);
    }

    public function getProjectDir(): string
    {
        if ($this->projectDir === null) {
            if ($dir = $_ENV['PROJECT_ROOT'] ?? $_SERVER['PROJECT_ROOT'] ?? false) {
                return $this->projectDir = $dir;
            }

            $r = new \ReflectionObject($this);

            
$kernel = new class($this->getContainer()->get('kernel')) implements KernelInterface {
            private readonly SimpleTheme $simpleTheme;

            public function __construct(private readonly Kernel $kernel)
            {
                $this->simpleTheme = new SimpleTheme();
            }

            public function getBundles(): array
            {
                $bundles = $this->kernel->getBundles();
                $bundles[$this->simpleTheme->getName()] = $this->simpleTheme;

                return $bundles;
            }

            public function getBundle(string $name): BundleInterface
            {
                return $name === $this->simpleTheme->getName() ? $this->simpleTheme : $this->kernel->getBundle($name);
            }

            public function handle(Request $request, int $type = self::MAIN_REQUEST, bool $catch = true): Response
            {
$this->entityAdapter->setValue($entity);
    $this->entityAdapter->onChange('foo');
  }

  /** * @covers ::getDataDefinition */
  public function testGetDataDefinition() {
    $definition = $this->entityAdapter->getDataDefinition();
    $this->assertInstanceOf('\Drupal\Core\Entity\TypedData\EntityDataDefinitionInterface', $definition);
    $this->assertEquals($definition->getEntityTypeId()$this->entityTypeId);
    $this->assertEquals($definition->getBundles()[$this->bundle]);
  }

  /** * @covers ::getString */
  public function testGetString() {
    $entity = $this->createMock('\Drupal\Core\Entity\ContentEntityInterface');
    $entity->expects($this->once())
      ->method('label')
      ->willReturn('foo');
    $this->entityAdapter->setValue($entity);
    

  }

  /** * Tests the block content body field migration. */
  public function testBlockContentBodyFieldMigration() {
    /** @var \Drupal\field\FieldStorageConfigInterface $storage */
    $storage = FieldStorageConfig::load('block_content.body');
    $this->assertInstanceOf(FieldStorageConfigInterface::class$storage);
    $this->assertSame('block_content', $storage->getTargetEntityTypeId());
    $this->assertSame(['basic']array_values($storage->getBundles()));
    $this->assertSame('body', $storage->getName());

    /** @var \Drupal\field\FieldConfigInterface $field */
    $field = FieldConfig::load('block_content.basic.body');
    $this->assertInstanceOf(FieldConfigInterface::class$field);
    $this->assertSame('block_content', $field->getTargetEntityTypeId());
    $this->assertSame('basic', $field->getTargetBundle());
    $this->assertSame('body', $field->getName());
    $this->assertSame('Body', $field->getLabel());
  }

}
$this->startTime = microtime(true);
                }
            }

            return;
        }

        if (null === $this->container) {
            $this->preBoot();
        }

        foreach ($this->getBundles() as $bundle) {
            $bundle->setContainer($this->container);
            $bundle->boot();
        }

        $this->booted = true;
    }

    /** * @return void */
    public function reboot(?string $warmupDir)
    {
abstract class AbstractConfigCommand extends ContainerDebugCommand
{
    /** * @return void */
    protected function listBundles(OutputInterface|StyleInterface $output)
    {
        $title = 'Available registered bundles with their extension alias if available';
        $headers = ['Bundle name', 'Extension alias'];
        $rows = [];

        $bundles = $this->getApplication()->getKernel()->getBundles();
        usort($bundlesfn ($bundleA$bundleB) => strcmp($bundleA->getName()$bundleB->getName()));

        foreach ($bundles as $bundle) {
            $extension = $bundle->getContainerExtension();
            $rows[] = [$bundle->getName()$extension ? $extension->getAlias() : ''];
        }

        if ($output instanceof StyleInterface) {
            $output->title($title);
            $output->table($headers$rows);
        } else {
            


    public function loadSnippetFilesIntoCollection(SnippetFileCollection $snippetFileCollection): void
    {
        $this->loadPluginSnippets($snippetFileCollection);

        $this->loadAppSnippets($snippetFileCollection);
    }

    private function loadPluginSnippets(SnippetFileCollection $snippetFileCollection): void
    {
        foreach ($this->kernel->getBundles() as $bundle) {
            if (!$bundle instanceof Bundle) {
                continue;
            }

            $snippetDir = $bundle->getPath() . '/Resources/snippet';

            if (!is_dir($snippetDir)) {
                continue;
            }

            foreach ($this->loadSnippetFilesInDir($snippetDir$bundle) as $snippetFile) {
                
$expectedMethod = self::METHOD_COPY;
            $io->text('Installing assets as <info>hard copies</info>.');
        }

        $io->newLine();

        $rows = [];
        $copyUsed = false;
        $exitCode = 0;
        $validAssetDirs = [];
        /** @var BundleInterface $bundle */
        foreach ($kernel->getBundles() as $bundle) {
            if (!is_dir($originDir = $bundle->getPath().'/Resources/public') && !is_dir($originDir = $bundle->getPath().'/public')) {
                continue;
            }

            $assetDir = preg_replace('/bundle$/', '', strtolower($bundle->getName()));
            $targetDir = $bundlesDir.$assetDir;
            $validAssetDirs[] = $assetDir;

            if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
                $message = sprintf("%s\n-> %s", $bundle->getName()$targetDir);
            } else {
                
Home | Imprint | This part of the site doesn't use cookies.