getTheme example

'#default_value' => !$entity->isNew() ? $entity->id() : $this->getUniqueMachineName($entity),
      '#machine_name' => [
        'exists' => '\Drupal\block\Entity\Block::load',
        'replace_pattern' => '[^a-z0-9_.]+',
        'source' => ['settings', 'label'],
      ],
      '#required' => TRUE,
      '#disabled' => !$entity->isNew(),
    ];

    // Theme settings.     if ($theme = $entity->getTheme()) {
      $form['theme'] = [
        '#type' => 'value',
        '#value' => $theme,
      ];
    }
    else {
      $theme = $this->config('system.theme')->get('default');
      $theme_options = [];
      foreach ($this->themeHandler->listInfo() as $theme_name => $theme_info) {
        if (!empty($theme_info->status)) {
          $theme_options[$theme_name] = $theme_info->info['name'];
        }
$this->collectInheritanceLess($inheritances['custom'])
        );

        $definitions = array_merge(
            $definitions,
            $this->collectInheritanceCss($inheritances['custom'])
        );

        $discardLess = [];
        for ($i = \count($definitions) - 1; $i >= 0; --$i) {
            $definition = $definitions[$i];
            $theme = $definition->getTheme();

            if (!$theme) {
                continue;
            }

            $themeClassName = \get_class($theme);
            $discardLess = array_merge($discardLess$theme->getDiscardedLessThemes());

            if (\in_array($themeClassName$discardLess)) {
                $definitions[$i]->setFiles([]);
            }
        }
$info['placeholder'] = $this->t('Enter block, theme or category');
    $info['description'] = $this->t('Enter a part of the block, theme or category to filter by.');

    return $info;
  }

  /** * {@inheritdoc} */
  public function buildRow(EntityInterface $entity) {
    $theme = $entity->getTheme();
    $plugin_definition = $entity->getPlugin()->getPluginDefinition();

    $row['label'] = [
      'data' => $entity->label(),
      'class' => 'table-filter-text-source',
    ];

    $row['theme'] = [
      'data' => $this->themes[$theme]->info['name'],
      'class' => 'table-filter-text-source',
    ];

    
$visibility = $block->getVisibility();
    if ($roles) {
      $this->assertSame($rolesarray_values($visibility['user_role']['roles']));
      $this->assertSame('@user.current_user_context:current_user', $visibility['user_role']['context_mapping']['user']);
    }
    if ($pages) {
      $this->assertSame($pages$visibility['request_path']['pages']);
    }

    $this->assertSame($region$block->getRegion());
    $this->assertSame($theme$block->getTheme());
    $this->assertSame($weight$block->getWeight());
    $this->assertSame($status$block->status());

    $config = $this->config('block.block.' . $id);
    $this->assertSame($label$config->get('settings.label'));
    $this->assertSame($label_display$config->get('settings.label_display'));
  }

  /** * Tests the block migration. */
  
/** * Tests \Drupal\Core\Extension\Extension::isExperimental deprecation. */
  public function testLegacyIsExperimental(): void {
    /** @var \Drupal\Core\Extension\ThemeInstallerInterface $theme_installer */
    $theme_installer = \Drupal::service('theme_installer');
    $theme_installer->install(['legacy_experimental_theme_test']);

    /** @var \Drupal\Core\Extension\ThemeHandler $theme_handler */
    $theme_handler = $this->container->get('theme_handler');
    $theme = $theme_handler->getTheme('legacy_experimental_theme_test');
    $this->expectDeprecation('The key-value pair "experimental: true" is deprecated in drupal:10.1.0 and will be removed before drupal:11.0.0. Use the key-value pair "lifecycle: experimental" instead. See https://www.drupal.org/node/3263585');
    $this->assertTrue($theme->isExperimental());
  }

}
/** * Tests the loading of blocks. */
  protected function loadTests() {
    $entity = $this->controller->load('test_block');

    $this->assertInstanceOf(Block::class$entity);

    // Verify several properties of the block.     $this->assertSame('content', $entity->getRegion());
    $this->assertTrue($entity->status());
    $this->assertEquals('stark', $entity->getTheme());
    $this->assertNotEmpty($entity->uuid());
  }

  /** * Tests the deleting of blocks. */
  protected function deleteTests() {
    $entity = $this->controller->load('test_block');

    // Ensure that the storage isn't currently empty.     $config_storage = $this->container->get('config.storage');
    

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

  /** * {@inheritdoc} */
  public function getQuestion() {
    $entity = $this->getEntity();
    $regions = $this->systemRegionList($entity->getTheme(), REGIONS_VISIBLE);
    return $this->t('Are you sure you want to remove the @entity-type %label from the %region region?', [
      '@entity-type' => $entity->getEntityType()->getSingularLabel(),
      '%label' => $entity->label(),
      '%region' => $regions[$entity->getRegion()],
    ]);
  }

  /** * {@inheritdoc} */
  public function getDescription() {
    
$this->moduleHandler->getModule('module_a')->willReturn($module_a);
    $this->moduleHandler->getModuleDirectories()->willReturn(['module_a' => vfsStream::url('root/modules/module_a')]);
    $this->moduleHandler->alter('layout', Argument::type('array'))->shouldBeCalled();

    $this->themeHandler = $this->prophesize(ThemeHandlerInterface::class);

    $this->themeHandler->themeExists('theme_a')->willReturn(TRUE);
    $this->themeHandler->themeExists('core')->willReturn(FALSE);
    $this->themeHandler->themeExists('invalid_provider')->willReturn(FALSE);

    $theme_a = new Extension('vfs://root', 'theme', 'themes/theme_a/theme_a.layouts.yml');
    $this->themeHandler->getTheme('theme_a')->willReturn($theme_a);
    $this->themeHandler->getThemeDirectories()->willReturn(['theme_a' => vfsStream::url('root/themes/theme_a')]);

    $this->cacheBackend = $this->prophesize(CacheBackendInterface::class);

    $namespaces = new \ArrayObject(['Drupal\Core' => vfsStream::url('root/core/lib/Drupal/Core')]);
    $this->layoutPluginManager = new LayoutPluginManager($namespaces$this->cacheBackend->reveal()$this->moduleHandler->reveal()$this->themeHandler->reveal());
  }

  /** * @covers ::getDefinitions * @covers ::providerExists */

  public function assertEntity(string $id, array $visibility, string $region, string $theme, int $weight, array $settings = NULL, bool $status = TRUE): void {
    $block = Block::load($id);
    $this->assertInstanceOf(Block::class$block);
    $this->assertSame($visibility$block->getVisibility());
    $this->assertSame($region$block->getRegion());
    $this->assertSame($theme$block->getTheme());
    $this->assertSame($weight$block->getWeight());
    $this->assertSame($status$block->status());
    if ($settings) {
      $block_settings = $block->get('settings');
      $block_settings['id'] = current(explode(':', $block_settings['id']));
      $this->assertEquals($settings$block_settings);
    }
  }

  /** * Tests the block migration. */

  public function getGroupProviders($group) {
    $providers = [];
    $breakpoints = $this->getBreakpointsByGroup($group);
    foreach ($breakpoints as $breakpoint) {
      $provider = $breakpoint->getProvider();
      $extension = FALSE;
      if ($this->moduleHandler->moduleExists($provider)) {
        $extension = $this->moduleHandler->getModule($provider);
      }
      elseif ($this->themeHandler->themeExists($provider)) {
        $extension = $this->themeHandler->getTheme($provider);
      }
      if ($extension) {
        $providers[$extension->getName()] = $extension->getType();
      }
    }
    return $providers;
  }

  /** * {@inheritdoc} */
  

  private function shouldEnforceSchemas(array $definition): bool {
    $provider_type = $definition['extension_type'] ?? NULL;
    if ($provider_type !== ExtensionType::Theme) {
      return TRUE;
    }
    return $this->themeHandler
      ->getTheme($definition['provider'])
      ?->info['enforce_prop_schemas'] ?? FALSE;
  }

  /** * Finds assets related to the provided metadata file. * * @param string $component_directory * The component directory for the plugin. * @param string $machine_name * The component's machine name. * @param string $file_extension * The file extension to detect. * @param bool $make_relative * TRUE to make the filename relative to the SDC module location. * * @return string|null * Filenames, maybe relative to the sdc module. */
$this->messenger()->addStatus($this->t('@type %info has been created.', $t_args));
    }
    else {
      $logger->info('@type: updated %info.', $context);
      $this->messenger()->addStatus($this->t('@type %info has been updated.', $t_args));
    }

    if ($block->id()) {
      $form_state->setValue('id', $block->id());
      $form_state->set('id', $block->id());
      if ($insert) {
        if (!$theme = $block->getTheme()) {
          $theme = $this->config('system.theme')->get('default');
        }
        $form_state->setRedirect(
          'block.admin_add',
          [
            'plugin_id' => 'block_content:' . $block->uuid(),
            'theme' => $theme,
          ]
        );
      }
      else {
        
$definitions = array_merge(
            $definitions,
            $this->collectInheritanceJavascript($inheritances['custom'])
        );

        $discardJs = [];

        for ($i = \count($definitions) - 1; $i >= 0; --$i) {
            $definition = $definitions[$i];

            $theme = $definition->getTheme();

            // Not all definitions are associated with a specific theme (e.g. plugins)             if ($theme) {
                $themeClassName = \get_class($theme);
                $discardJs = array_merge($discardJs$theme->getDiscardedJavascriptThemes());

                if (\in_array($themeClassName$discardJs)) {
                    $definition->setFiles([]);
                }
            }
        }

        
if (StreamWrapperManager::getScheme($original_path) == 'public') {
          $friendly_path = StreamWrapperManager::getTarget($original_path);
          $element['#default_value'] = $friendly_path;
        }

        // Prepare local file path for description.         if ($original_path && isset($friendly_path)) {
          $local_file = strtr($original_path['public:/' => PublicStream::basePath()]);
        }
        elseif ($theme) {
          $local_file = $this->themeHandler->getTheme($theme)->getPath() . '/' . $default;
        }
        else {
          $local_file = $this->themeManager->getActiveTheme()->getPath() . '/' . $default;
        }

        $element['#description'] = $this->t('Examples: <code>@implicit-public-file</code> (for a file in the public filesystem), <code>@explicit-file</code>, or <code>@local-file</code>.', [
          '@implicit-public-file' => $friendly_path ?? $default,
          '@explicit-file' => StreamWrapperManager::getScheme($original_path) !== FALSE ? $original_path : 'public://' . $default,
          '@local-file' => $local_file,
        ]);
      }
    }
$this->mediaFolderRepository = $this->getContainer()->get('media_folder.repository');
        $this->connection = $this->getContainer()->get(Connection::class);
        $this->context = Context::createDefaultContext();
    }

    public function testItRegistersANewThemeCorrectly(): void
    {
        $bundle = $this->getThemeConfig();

        $this->themeLifecycleService->refreshTheme($bundle$this->context);

        $themeEntity = $this->getTheme($bundle);

        static::assertTrue($themeEntity->isActive());
        static::assertInstanceOf(MediaCollection::class$themeEntity->getMedia());
        static::assertEquals(2, $themeEntity->getMedia()->count());

        $themeDefaultFolderId = $this->getThemeMediaDefaultFolderId();
        foreach ($themeEntity->getMedia() as $media) {
            static::assertEquals($themeDefaultFolderId$media->getMediaFolderId());
        }
    }

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