$payload One entry, as it travels to the browser. * @param string|null $url `get_privacy_policy_url()`, which is `''` where none is set. * @return array */ public static function into(array $payload, ?string $url): array { if ($url === null || $url === '') { return $payload; } return TemplateTree::rewrittenIn($payload, static fn (array $node): array => self::resolve($node, $url)); } /** * One node, with the site's link filled in where it was asked for. * * The walk is {@see TemplateTree::rewrittenIn()}'s, so what is left here * is the rule and nothing else — which is the point: the rule is the half * worth reading, and it used to sit under fifteen lines of recursion that * {@see CartLink} then copied. * * @param array $node * @return array */ private static function resolve(array $node, string $url): array { if (!self::asksForPolicy($node)) { return $node; } $link = $node['link'] ?? null; // A label and no destination: the one shape only the site can // complete. No label means no anchor text, so there is nothing to // render whatever href it were handed. if ( is_array($link) && is_string($link['label'] ?? null) && $link['label'] !== '' && !is_string($link['href'] ?? null) ) { $link['href'] = $url; $node['link'] = $link; } return $node; } /** * Whether this node is one of the two sentences a policy link belongs in. * * Public because the publish check asks the mirror question: a hrefless * link in any OTHER node is a blocker, since nothing will ever fill it. * * @param array $node */ public static function asksForPolicy(array $node): bool { return ($node['type'] ?? null) === 'consent' || (($node['type'] ?? null) === 'text' && ($node['role'] ?? null) === 'fine_print'); } }