Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
},
"drupal/inline_entity_form": {
"Issue #3542076: Empty media entities with simple widget in paragraphs": "https://www.drupal.org/files/issues/2025-08-20/3542076-empty-media-entities-with-simple-widget-in-paragraphs.diff"
},
"drupal/graphql": {
"#3563846: Add node preview": "https://www.drupal.org/files/issues/2026-02-09/3563846.diff"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Render\RenderContext;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand Down Expand Up @@ -38,7 +39,8 @@ public static function create(ContainerInterface $container, array $configuratio
$configuration,
$plugin_id,
$plugin_definition,
$container->get('renderer')
$container->get('renderer'),
$container->get('current_route_match')
);
}

Expand All @@ -53,12 +55,15 @@ public static function create(ContainerInterface $container, array $configuratio
* The plugin definition.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer service.
* @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch
* The current route match.
*/
public function __construct(
array $configuration,
string $plugin_id,
$plugin_definition,
protected readonly RendererInterface $renderer,
protected readonly RouteMatchInterface $routeMatch,
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
Expand All @@ -73,6 +78,11 @@ public function __construct(
* The entity links.
*/
public function resolve(EntityInterface $entity): array {
// Do not expose links on node preview.
if ($this->routeMatch->getRouteName() === 'entity.node.preview') {
return [];
}

$context = new RenderContext();
$result = $this->renderer->executeInRenderContext($context, function () use ($entity): array {
$links = $entity->getEntityType()->getLinkTemplates();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public function __construct(
* Normalized metatags.
*/
public function resolve(mixed $value, ?string $type, RefinableCacheableDependencyInterface $metadata): array {
if ($value instanceof ContentEntityInterface) {
// Do not render metatags for new entities preview.
if ($value instanceof ContentEntityInterface && !$value->isNew()) {
$context = new RenderContext();
$result = $this->renderer->executeInRenderContext($context, function () use ($value): array {
$tags = $this->metatagManager->tagsFromEntityWithDefaults($value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@ protected function resolveBaseFields(string $type, string $entity_type_id): void
$this->addFieldResolverIfNotExists(
$type,
'id',
$this->builder->produce('entity_id')
->map('entity', $this->builder->fromParent())
$this->builder->compose(
$this->builder->produce('entity_id')
->map('entity', $this->builder->fromParent()),
// Coerce NULL to 0 for preview.
$this->builder->callback(fn ($parent) => $parent ?: 0)
)
);

$this->addFieldResolverIfNotExists(
Expand Down Expand Up @@ -121,10 +125,20 @@ protected function resolveBaseFields(string $type, string $entity_type_id): void
if ($entity_type->hasLinkTemplate('canonical')) {
$this->addFieldResolverIfNotExists($type, 'url',
$this->builder->compose(
$this->builder->produce('entity_url')
->map('entity', $this->builder->fromParent()),
$this->builder->produce('url_path')
->map('url', $this->builder->fromParent())
$this->builder->cond([
[
$this->builder->callback(fn ($entity) => !$entity->isNew()),
$this->builder->compose(
$this->builder->produce('entity_url')
->map('entity', $this->builder->fromParent()),
$this->builder->produce('url_path')
->map('url', $this->builder->fromParent()),
),
], [
$this->builder->fromValue('TRUE'),
$this->builder->fromValue('#'),
],
])
)
);
}
Expand Down