annotate core/modules/link/link.module @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /**
Chris@0 4 * @file
Chris@0 5 * Defines simple link field types.
Chris@0 6 */
Chris@0 7
Chris@18 8 use Drupal\Core\Url;
Chris@0 9 use Drupal\Core\Routing\RouteMatchInterface;
Chris@0 10
Chris@0 11 /**
Chris@0 12 * Implements hook_help().
Chris@0 13 */
Chris@0 14 function link_help($route_name, RouteMatchInterface $route_match) {
Chris@0 15 switch ($route_name) {
Chris@0 16 case 'help.page.link':
Chris@0 17 $output = '';
Chris@0 18 $output .= '<h3>' . t('About') . '</h3>';
Chris@18 19 $output .= '<p>' . t('The Link module allows you to create fields that contain internal or external URLs and optional link text. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href=":link_documentation">online documentation for the Link module</a>.', [':field' => Url::fromRoute('help.page', ['name' => 'field'])->toString(), ':field_ui' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? Url::fromRoute('help.page', ['name' => 'field_ui'])->toString() : '#', ':link_documentation' => 'https://www.drupal.org/documentation/modules/link']) . '</p>';
Chris@0 20 $output .= '<h3>' . t('Uses') . '</h3>';
Chris@0 21 $output .= '<dl>';
Chris@0 22 $output .= '<dt>' . t('Managing and displaying link fields') . '</dt>';
Chris@18 23 $output .= '<dd>' . t('The <em>settings</em> and the <em>display</em> of the link field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', [':field_ui' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? Url::fromRoute('help.page', ['name' => 'field_ui'])->toString() : '#']) . '</dd>';
Chris@0 24 $output .= '<dt>' . t('Setting the allowed link type') . '</dt>';
Chris@0 25 $output .= '<dd>' . t('In the field settings you can define the allowed link type to be <em>internal links only</em>, <em>external links only</em>, or <em>both internal and external links</em>. <em>Internal links only</em> and <em>both internal and external links</em> options enable an autocomplete widget for internal links, so a user does not have to copy or remember a URL.') . '</dd>';
Chris@0 26 $output .= '<dt>' . t('Adding link text') . '</dt>';
Chris@0 27 $output .= '<dd>' . t('In the field settings you can define additional link text to be <em>optional</em> or <em>required</em> in any link field.') . '</dd>';
Chris@0 28 $output .= '<dt>' . t('Displaying link text') . '</dt>';
Chris@0 29 $output .= '<dd>' . t('If link text has been submitted for a URL, then by default this link text is displayed as a link to the URL. If you want to display both the link text <em>and</em> the URL, choose the appropriate link format from the drop-down menu in the <em>Manage display</em> page. If you only want to display the URL even if link text has been submitted, choose <em>Link</em> as the format, and then change its <em>Format settings</em> to display <em>URL only</em>.') . '</dd>';
Chris@0 30 $output .= '<dt>' . t('Adding attributes to links') . '</dt>';
Chris@0 31 $output .= '<dd>' . t('You can add attributes to links, by changing the <em>Format settings</em> in the <em>Manage display</em> page. Adding <em>rel="nofollow"</em> notifies search engines that links should not be followed.') . '</dd>';
Chris@0 32 $output .= '<dt>' . t('Validating URLs') . '</dt>';
Chris@0 33 $output .= '<dd>' . t('All links are validated after a link field is filled in. They can include anchors or query strings.') . '</dd>';
Chris@0 34 $output .= '</dl>';
Chris@0 35 return $output;
Chris@0 36 }
Chris@0 37 }
Chris@0 38
Chris@0 39 /**
Chris@0 40 * Implements hook_theme().
Chris@0 41 */
Chris@0 42 function link_theme() {
Chris@0 43 return [
Chris@0 44 'link_formatter_link_separate' => [
Chris@0 45 'variables' => ['title' => NULL, 'url_title' => NULL, 'url' => NULL],
Chris@0 46 ],
Chris@0 47 ];
Chris@0 48 }
Chris@0 49
Chris@0 50 /**
Chris@0 51 * Prepares variables for separated link field templates.
Chris@0 52 *
Chris@0 53 * This template outputs a separate title and link.
Chris@0 54 *
Chris@0 55 * Default template: link-formatter-link-separate.html.twig.
Chris@0 56 *
Chris@0 57 * @param array $variables
Chris@0 58 * An associative array containing:
Chris@0 59 * - title: (optional) A descriptive or alternate title for the link, which
Chris@0 60 * may be different than the actual link text.
Chris@0 61 * - url_title: The anchor text for the link.
Chris@0 62 * - url: A \Drupal\Core\Url object.
Chris@0 63 */
Chris@0 64 function template_preprocess_link_formatter_link_separate(&$variables) {
Chris@0 65 $variables['link'] = \Drupal::l($variables['url_title'], $variables['url']);
Chris@0 66 }