Skip to content

Move tabs/tab directive to rst package#1316

Open
wouterj wants to merge 2 commits intophpDocumentor:mainfrom
wouterj:tabs-directive-to-rst-package
Open

Move tabs/tab directive to rst package#1316
wouterj wants to merge 2 commits intophpDocumentor:mainfrom
wouterj:tabs-directive-to-rst-package

Conversation

@wouterj
Copy link
Contributor

@wouterj wouterj commented Mar 15, 2026

Symfony is using the .. tabs:: directive with our custom theme instead of BootstrapCSS. I can see this use-case for other users as well, so I propose to move the directive to the restructured-text sub-package. I provided a basic HTML template that does not work, but has enough to make a working JS implementation.

I've used the technique used by Symfony for moving a class to another namespace. This provides the smoothest upgrade path, with a deprecation notice for the old class, but no break in runtime code or static analysis.

At last, it looks like the GeneralDirectiveNodeRenderer did not function properly and always threw a Twig exception when defining the global variables. I've applied a basic fix to the TwigTemplateRenderer for this, to make the new tabs test pass.

wouterj added 2 commits March 15, 2026 15:17
This directive is also very useful outside of the Bootstrap theme (e.g.
it is used by the Symfony docs with their custom theme).

This moves the implementation to the guides-restructured-text and
provides a smooth upgrade path in the guides-theme-bootstrap package.
After initializing the Twig Environment, no new variables can be
introduced (existing ones can be changed). As Environment::load()
initializes the environment, this causes issues when calling
renderTemplate() afterwards. By defining them in both methods, no error
is thrown.
"php": "^8.1",
"phpdocumentor/guides": "^1.0 || ^2.0",
"phpdocumentor/guides-restructured-text": "^1.0 || ^2.0"
"phpdocumentor/guides-restructured-text": "^1.10 || ^2.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this package should also depend on doctrine/deprecations now that it uses it directly, instead of relying on the transitive dependency coming from phpdocumentor/guides

try {
$twig = $this->environmentBuilder->getTwigEnvironment();
$twig->addGlobal('env', $context);
$twig->addGlobal('debugInformation', $context->getLoggerInformation());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proper fix is probably to change the EnvironmentBuilder to define those global variable first, so that TwigTemplateRenderer::renderTemplate() ends up updating the value of existing global variables (which is allowed) instead of maybe defining new global variables (which is not allowed anymore after starting to render templates)

public function __construct(
protected readonly string $name,
protected readonly string $plainContent,
protected readonly InlineCompoundNode $content,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should those really be promoted properties if they are passed to the parent ? Isn't this overriding the parent properties (which has much bigger BC risk than using them, as property overrides in PHP enforce invariant types and modifier compatibility) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants