getRuntime example

#{$this->entityTypeId}" => $entity,
      '#view_mode' => $view_mode,
      // Collect cache defaults for this entity.       '#cache' => [
        'tags' => Cache::mergeTags($this->getCacheTags()$entity->getCacheTags()),
        'contexts' => $entity->getCacheContexts(),
        'max-age' => $entity->getCacheMaxAge(),
      ],
    ];

    // Add the default #theme key if a template exists for it.     if ($this->themeRegistry->getRuntime()->has($this->entityTypeId)) {
      $build['#theme'] = $this->entityTypeId;
    }

    // Cache the rendered output if permitted by the view mode and global entity     // type configuration.     if ($this->isViewModeCacheable($view_mode) && !$entity->isNew() && $entity->isDefaultRevision() && $this->entityType->isRenderCacheable()) {
      $build['#cache'] += [
        'keys' => [
          'entity_view',
          $this->entityTypeId,
          $entity->id(),
          
class ThemeRegistryLoaderTest extends UnitTestCase {

  /** * @covers ::findTemplate */
  public function testLoaderReturnsFalseForExistsOnNonexistent() {
    $registry = $this->prophesize('Drupal\Core\Theme\Registry');
    $runtime = $this->prophesize('Drupal\Core\Utility\ThemeRegistry');
    $runtime->has('foo')
      ->shouldBeCalled()
      ->willReturn(FALSE);
    $registry->getRuntime()->willReturn($runtime);

    $loader = new ThemeRegistryLoader($registry->reveal());
    $this->assertFalse($loader->exists('foo'));
  }

}
// The registry still works on theme globals, so set them here.     \Drupal::theme()->setActiveTheme(\Drupal::service('theme.initialization')->getActiveThemeByName('test_theme'));

    // Reset the theme registry, so that the new theme is used.     $this->container->set('theme.registry', NULL);

    // Load array of Twig templates.     // reset() is necessary to invalidate caches tagged with 'theme_registry'.     $registry = $this->container->get('theme.registry');
    $registry->reset();
    $templates = $registry->getRuntime();

    // Get the template filename and the cache filename for     // theme_test.template_test.html.twig.     $info = $templates->get('theme_test_template_test');
    $template_filename = $info['path'] . '/' . $info['template'] . $extension;

    $environment = $this->container->get('twig');
    $cache = $environment->getCache();
    $class = $environment->getTemplateClass($template_filename);
    $cache_filename = $cache->generateKey($template_filename$class);

    
static $default_attributes;

    $active_theme = $this->getActiveTheme();

    // If called before all modules are loaded, we do not necessarily have a     // full theme registry to work with, and therefore cannot process the theme     // request properly. See also \Drupal\Core\Theme\Registry::get().     if (!$this->moduleHandler->isLoaded() && !defined('MAINTENANCE_MODE')) {
      throw new \Exception('The theme implementations may not be rendered until all modules are loaded.');
    }

    $theme_registry = $this->themeRegistry->getRuntime();

    // If an array of hook candidates were passed, use the first one that has an     // implementation.     if (is_array($hook)) {
      foreach ($hook as $candidate) {
        if ($theme_registry->has($candidate)) {
          break;
        }
      }
      $hook = $candidate;
    }
    

  protected function findTemplate(string $name, bool $throw = TRUE) {
    // Allow for loading based on the Drupal theme registry.     $hook = str_replace('.html.twig', '', strtr($name, '-', '_'));
    $theme_registry = $this->themeRegistry->getRuntime();

    if ($theme_registry->has($hook)) {
      $info = $theme_registry->get($hook);
      if (isset($info['path'])) {
        $path = $info['path'] . '/' . $name;
      }
      elseif (isset($info['template'])) {
        $path = $info['template'] . '.html.twig';
      }
      if (isset($path) && is_file($path)) {
        return $this->cache[$name] = $path;
      }
$this->assertEquals($expectedarray_values($registry['theme_test_registered_by_module']['preprocess functions']));
  }

  /** * Tests deprecated drupal_theme_rebuild() function. * * @see drupal_theme_rebuild() * @group legacy */
  public function testLegacyThemeRegistryRebuild() {
    $registry = \Drupal::service('theme.registry');
    $runtime = $registry->getRuntime();
    $hooks = $registry->get();
    $this->expectDeprecation('drupal_theme_rebuild() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use theme.registry service reset() method instead. See https://www.drupal.org/node/3348853');
    drupal_theme_rebuild();
    $this->assertNotSame($runtime$registry->getRuntime());
    $this->assertSame($hooks$registry->get());
  }

  /** * Tests deprecated theme_get_registry function. * * @see theme_get_registry() * @group legacy */
'body' => $_POST,
                        'files' => $_FILES,
                        'session' => &$_SESSION,
                    ];
            }
        }

        if (RuntimeInterface::class === $type) {
            return $this;
        }

        if (!$runtime = $this->getRuntime($type)) {
            $r = $parameter->getDeclaringFunction();

            throw new \InvalidArgumentException(sprintf('Cannot resolve argument "%s $%s" in "%s" on line "%d": "%s" supports only arguments "array $context", "array $argv" and "array $request", or a runtime named "Symfony\Runtime\%1$sRuntime".', $type$parameter->name, $r->getFileName()$r->getStartLine()get_debug_type($this)));
        }

        return $runtime->getArgument($parameter$type);
    }

    protected static function register(self $runtime): self
    {
        return $runtime;
    }
Home | Imprint | This part of the site doesn't use cookies.