Unverified Commit 272495e8 authored by Alex Pott's avatar Alex Pott
Browse files

task: #3560844 Update starterkit and GenerateThemeTests to handle OOP hooks

By: nicxvan
By: cmlara
(cherry picked from commit 23ddf6a9)
parent 09ebcac3
Loading
Loading
Loading
Loading
Loading
+5 −6
Changes for core/tests/Drupal/BuildTests/Command/GenerateThemeTest.php: 5 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -121,14 +121,14 @@ public function test(): void {
    // Ensure that a new theme cannot be generated when the destination
    // directory already exists.
    $theme_path_absolute = $this->getWorkspaceDirectory() . "/$theme_path_relative";
    $this->assertFileExists($theme_path_absolute . '/test_custom_theme.theme');
    unlink($theme_path_absolute . '/test_custom_theme.theme');
    $this->assertFileExists($theme_path_absolute . '/src/Hook/TestCustomThemeHooks.php');
    unlink($theme_path_absolute . '/src/Hook/TestCustomThemeHooks.php');
    $process = $this->generateThemeFromStarterkit();
    $result = $process->run();
    $this->assertStringContainsString('Theme could not be generated because the destination directory', $process->getErrorOutput());
    $this->assertStringContainsString($theme_path_relative, $process->getErrorOutput());
    $this->assertSame(1, $result);
    $this->assertFileDoesNotExist($theme_path_absolute . '/test_custom_theme.theme');
    $this->assertFileDoesNotExist($theme_path_absolute . '/src/Hook/TestCustomThemeHooks.php');
  }

  /**
@@ -171,8 +171,8 @@ public function testGeneratingFromAnotherTheme(): void {
    $this->assertSame(0, $exit_code);

    // Confirm new .theme file.
    $dot_theme_file = $this->getWorkspaceDirectory() . '/themes/generated_from_another_theme/generated_from_another_theme.theme';
    $this->assertStringContainsString('function generated_from_another_theme_preprocess_image_widget(array &$variables): void {', file_get_contents($dot_theme_file));
    $dot_theme_file = $this->getWorkspaceDirectory() . '/themes/generated_from_another_theme/src/Hook/GeneratedFromAnotherThemeHooks.php';
    $this->assertStringContainsString('public function preprocessImageWidget(array &$variables): void {', file_get_contents($dot_theme_file));
  }

  /**
@@ -395,7 +395,6 @@ public function testDeleteDirectory(): void {
    $theme_path_absolute = $this->getWorkspaceDirectory() . '/themes/test_custom_theme';
    self::assertDirectoryExists($theme_path_absolute);
    self::assertFileDoesNotExist($theme_path_absolute . '/src/StarterKit.php');
    self::assertDirectoryDoesNotExist($theme_path_absolute . '/src');
  }

  public function testNoEditMissingFilesWarning(): void {
+31
Changes for core/themes/starterkit_theme/src/Hook/StarterkitThemeHooks.php: 31 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\starterkit_theme\Hook;

use Drupal\Core\Hook\Attribute\Hook;

/**
 * Hook implementations for starterkit_theme.
 */
class StarterkitThemeHooks {
  /**
   * @file
   * Functions to support theming.
   */

  /**
   * Implements hook_preprocess_image_widget().
   */
  #[Hook('preprocess_image_widget')]
  public function preprocessImageWidget(array &$variables): void {
    $data = &$variables['data'];
    // This prevents image widget templates from rendering preview container
    // HTML to users that do not have permission to access these previews.
    // @todo revisit in https://drupal.org/node/953034
    // @todo revisit in https://drupal.org/node/3114318
    if (isset($data['preview']['#access']) && $data['preview']['#access'] === FALSE) {
      unset($data['preview']);
    }
  }

}
−21

File deleted.