$bundles */ function opd_podcast_entity_bundle_info_alter(array &$bundles): void { if (isset($bundles['node'])) { $bundles['node'][Episode::NODE_TYPE]['class'] = Episode::class; } if (isset($bundles['taxonomy_term'])) { $bundles['taxonomy_term'][Guest::TERM_TYPE]['class'] = Guest::class; } } /** * @param array> $links * @param array $context */ function opd_podcast_node_links_alter(array &$links, NodeInterface $entity, array &$context): void { if (!$entity instanceof Episode) { return; } $links['node']['#links']['node-readmore']['title'] = t('Listen now to @title →'); $links['node']['#links']['node-readmore']['attributes']['class'] = [ 'p-0', ]; $links['#attributes']['class'][] = 'list-none'; $links['#attributes']['class'][] = 'm-0'; $links['#attributes']['class'][] = 'p-0'; } /** * Implements hook_token_info(). * * @return array{tokens: array{opd-podcast: array{description: TranslatableMarkup, name: TranslatableMarkup}[]}, types: array{opd-podcast: array{description: TranslatableMarkup, name: TranslatableMarkup}}} */ function opd_podcast_token_info(): array { $tokens = []; $type = [ 'description' => t('Tokens related to podcasts.'), 'name' => t('Podcasts'), ]; $tokens['guest-names'] = [ 'description' => t('The names of the guests on a podcast episode.'), 'name' => t('Guest names'), ]; return [ 'tokens' => [ 'opd-podcast' => $tokens, ], 'types' => [ 'opd-podcast' => $type, ], ]; } /** * Implements hook_tokens(). * * @param array $tokens * @param array $data * @param array $options * * @return array */ function opd_podcast_tokens(string $type, array $tokens, array $data, array $options, BubbleableMetadata $bubbleableMetadata) : array { $replacements = []; if ($type === 'opd-podcast') { foreach ($tokens as $name => $original) { switch ($name) { case 'guest-names': $node = $data['node'] ?? NULL; assert($node instanceof Episode); $replacements[$original] = strval($node->getGuests()); break; } } } return $replacements; }