PlaceholderGenerator example

case 'theme':
              $keys[] = 'stark';
              break;

            default:
              $keys[] = $context_id;
          }
        }
        return new ContextCacheKeys($keys);
      });
    $this->placeholderGenerator = new PlaceholderGenerator($this->rendererConfig);
    $this->renderCache = new PlaceholderingRenderCache($this->requestStack, $this->cacheFactory, $this->cacheContextsManager, $this->placeholderGenerator);
    $this->renderer = new Renderer($this->controllerResolver, $this->themeManager, $this->elementInfo, $this->placeholderGenerator, $this->renderCache, $this->requestStack, $this->rendererConfig);

    $container = new ContainerBuilder();
    $container->set('cache_contexts_manager', $this->cacheContextsManager);
    $container->set('render_cache', $this->renderCache);
    $container->set('renderer', $this->renderer);
    \Drupal::setContainer($container);
  }

  /** * Generates a random context value for the placeholder tests. * * The #context array used by the placeholder #lazy_builder callback will * generally be used to provide metadata like entity IDs, field machine names, * paths, etc. for JavaScript replacement of content or assets. In this test, * the #lazy_builder callback PlaceholdersTest::callback() renders the context * inside test HTML, so using any random string would sometimes cause random * test failures because the test output would be unparseable. Instead, we * provide random tokens for replacement. * * @see PlaceholdersTest::callback() * @see https://www.drupal.org/node/2151609 */
Home | Imprint | This part of the site doesn't use cookies.