> $links * @param array $context */ function opd_podcast_node_links_alter(array &$links, NodeInterface $entity, array &$context): void { if ($entity->bundle() !== 'podcast_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, types: array} */ 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 NodeInterface); assert($node->hasField('field_podcast_guests')); $guests = $node->get('field_podcast_guests')->referencedEntities(); assert(is_array($guests)); assert(!is_null($guests[0])); assert($guests[0] instanceof TermInterface); $replacements[$original] = $guests[0]->label(); break; } } } return $replacements; }