diff --git a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php index f5a5353..7e58edd 100644 --- a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php @@ -156,9 +156,17 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen /** @var \Drupal\link\LinkItemInterface $item */ $item = $items[$delta]; + // We will customize the form depending on if the title form element is + // to be show, and what the cardinality is. + $title_is_enabled = $this->getFieldSetting('title') != DRUPAL_DISABLED; + $cardinality_is_one = $this->fieldDefinition->getFieldStorageDefinition()->getCardinality() == 1; + $element['uri'] = array( '#type' => 'url', - '#title' => $this->t('URL'), + // When the title is not enabled, we will not use a fieldset and will + // lose the field label. So, use the field label as the uri form element + // label in that case. + '#title' => ($title_is_enabled || !$cardinality_is_one) ? $this->t('URL') : $this->fieldDefinition->getLabel() . ' (' . $this->t('URL') . ')', '#placeholder' => $this->getSetting('placeholder_url'), // The current field value could have been entered by a different user. // However, if it is inaccessible to the current user, do not display it @@ -184,16 +192,38 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $element['uri']['#process_default_value'] = FALSE; } + // We will be taking off the fieldset since the title is not enabled. Which + // will mean the description from the field will not show when there is + // more than one link. Add the description from the field so it shows. + if ($cardinality_is_one && !$title_is_enabled) { + $element['uri']['#description'] = $this->fieldDefinition->getDescription(); + } + // If the field is configured to allow only internal links, add a useful // element prefix. if (!$this->supportsExternalLinks()) { $element['uri']['#field_prefix'] = rtrim(\Drupal::url('', array(), array('absolute' => TRUE)), '/'); } - // If the field is configured to allow both internal and external links, - // show a useful description. - elseif ($this->supportsExternalLinks() && $this->supportsInternalLinks()) { - $element['uri']['#description'] = $this->t('Start typing the title of a piece of content to select it. You can also enter an internal path such as %add-node or an external URL such as %url. Enter %front to link to the front page.', array('%front' => '', '%add-node' => '/node/add', '%url' => 'http://example.com')); - } + // Internal-only does not need a description, since the field prefix + // accomplishes what help text would. When external is allowed, show a + // useful description. + else { + // If description is not already initialized from the field, initialize + // it. If using the description from the field, add a space before + // appending the description from the uri form element. + if (!isset($element['uri']['#description'])) { + $element['uri']['#description'] = ''; + } + else { + $element['uri']['#description'] .= ' '; + } + if ($this->supportsExternalLinks() && $this->supportsInternalLinks()) { + $element['uri']['#description'] .= $this->t('This can be an internal Drupal path such as %add-node or an external URL such as %drupal. Enter %front to link to the front page.', array('%front' => '', '%add-node' => 'node/add', '%drupal' => 'http://drupal.org')); + } + elseif ($this->supportsExternalLinks() && !$this->supportsInternalLinks()) { + $element['uri']['#description'] .= $this->t('This must be an external URL such as %drupal.', array('%drupal' => 'http://drupal.org')); + } + } $element['title'] = array( '#type' => 'textfield', @@ -201,7 +231,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen '#placeholder' => $this->getSetting('placeholder_title'), '#default_value' => isset($items[$delta]->title) ? $items[$delta]->title : NULL, '#maxlength' => 255, - '#access' => $this->getFieldSetting('title') != DRUPAL_DISABLED, + '#access' => $title_is_enabled, ); // Post-process the title field to make it conditionally required if URL is // non-empty. Omit the validation on the field edit form, since the field @@ -219,8 +249,15 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen '#attributes' => array('class' => array('link-field-widget-attributes')), ); - // If cardinality is 1, ensure a proper label is output for the field. - if ($this->fieldDefinition->getFieldStorageDefinition()->getCardinality() == 1) { + // If cardinality is 1, a title and URI form elements will mix with other + // form elements and not appear related. Ensure a label is output for the + // link field and the title and URI form elements are grouped by making it + // a fieldset. When the cardinality is greater than one, each set of title + // and URI form elements are already grouped visually, because of the UI + // that allows reordering them. Also, if the title form element is not shown + // we do not need the grouping. So, only make it a fieldset when title is + // enabled. + if ($cardinality_is_one && $title_is_enabled) { // If the link title is disabled, use the field definition label as the // title of the 'uri' element. if ($this->getFieldSetting('title') == DRUPAL_DISABLED) { diff --git a/core/modules/menu_link_content/src/Entity/MenuLinkContent.php b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php index 78d7483..4638dca 100644 --- a/core/modules/menu_link_content/src/Entity/MenuLinkContent.php +++ b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php @@ -253,7 +253,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setReadOnly(TRUE); $fields['title'] = BaseFieldDefinition::create('string') - ->setLabel(t('Menu link title')) + ->setLabel(t('Text')) ->setDescription(t('The text to be used for this link in the menu.')) ->setRequired(TRUE) ->setTranslatable(TRUE) @@ -289,13 +289,12 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { )); $fields['menu_name'] = BaseFieldDefinition::create('string') - ->setLabel(t('Menu name')) + ->setLabel(t('Text')) ->setDescription(t('The menu name. All links with the same menu name (such as "tools") are part of the same menu.')) ->setDefaultValue('tools'); $fields['link'] = BaseFieldDefinition::create('link') - ->setLabel(t('Link')) - ->setDescription(t('The location this menu link points to.')) + ->setLabel(t('Location')) ->setRequired(TRUE) ->setSettings(array( 'link_type' => LinkItemInterface::LINK_GENERIC, diff --git a/core/modules/shortcut/shortcut.routing.yml b/core/modules/shortcut/shortcut.routing.yml index d6c0e1a..ddceb45 100644 --- a/core/modules/shortcut/shortcut.routing.yml +++ b/core/modules/shortcut/shortcut.routing.yml @@ -50,7 +50,7 @@ shortcut.link_add: path: '/admin/config/user-interface/shortcut/manage/{shortcut_set}/add-link' defaults: _controller: '\Drupal\shortcut\Controller\ShortcutController::addForm' - _title: 'Add link' + _title: 'Add shortcut link' requirements: _entity_create_access: 'shortcut:{shortcut_set}' @@ -58,7 +58,7 @@ entity.shortcut.canonical: path: '/admin/config/user-interface/shortcut/link/{shortcut}' defaults: _entity_form: 'shortcut.default' - _title: 'Edit' + _title: 'Edit shortcut link' requirements: _entity_access: 'shortcut.update' diff --git a/core/modules/shortcut/src/Entity/Shortcut.php b/core/modules/shortcut/src/Entity/Shortcut.php index 9fd0332..0d06b4f 100644 --- a/core/modules/shortcut/src/Entity/Shortcut.php +++ b/core/modules/shortcut/src/Entity/Shortcut.php @@ -128,7 +128,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setRequired(TRUE); $fields['title'] = BaseFieldDefinition::create('string') - ->setLabel(t('Name')) + ->setLabel(t('Text')) ->setDescription(t('The name of the shortcut.')) ->setRequired(TRUE) ->setTranslatable(TRUE)