Short description: Link field URL textfield is populated with a fully generated URL in node (or any other entity) edit form if internal URL is used as a link field URL value. Instead only internal path (system path) should be populated in link URL textfield.

Steps to reproduce:

  1. Install Drupal-8.x-dev in a subdirectory.
  2. Attach a link field to a content type. Allow it to accept both internal and external links.
  3. Create a node and type <front> in the link field URL part.
  4. After the node is saved, click on Edit link to edit the node again.
  5. URL textfield of the link field contains a base url to the Drupal installation (e.g., /subdir/drupal) rather than <front>.
  6. Upon saving an unchanged form, an error is thrown informing that The URL /subdir/drupal is not valid.

Notes:

  • If the link field URL part contains an internal path to a another node (say, node/31, which has an aliased path example-node), upon editing of the node the link field URL part contains the aliased path to the linked node ($base_url . "/example-node"). In this case also an error will be thrown informing that the URL is not valid.
  • If Drupal-8.x-dev is installed in webroot, link field URL value <front> in repeated node edit form will be displayed as an empty string (as base url is empty), therefore upon node form submission link field value will be saved as empty.

Comments

larowlan’s picture

Issue tags: +Needs tests
maijs’s picture

Attaching a test patch.

  1. <front> is added to the list of allowed internal paths.
  2. Upon add entity form submission raw values of links should be asserted with assertRaw(String::checkPlain($value)) rather than with assertRaw($value) as link value is displayed in a textfield (for example, <front> becomes &lt;front&gt;).
  3. assertFieldByName("{$field_name}[0][url]", $value, t('The URL @url in entity edit form is correct.', array('@url' => $value))) asserts whether link value that is displayed on the entity edit form is the same as user has entered it.

This bug makes a link field module unusable because entities, that have link field attached to them, cannot be successfully re-saved without reentering the path again if link URL is intended to be an internal path.

maijs’s picture

Status: Active » Needs review
StatusFileSize
new2.41 KB

The patch attached contains improved test and solution for this problem.

Update to the test:
massageFormValues() in LinkWidget class modifies the path entered by user so that the system path is stored, if an alias is provided. Therefore system path should be used in asserting the saved link URL value, if the link provided is an internal path.

Solution:
In entity edit form a system path should be displayed in link field URL textfield, rather than generated URL from that path, if user entered an internal path.

maijs’s picture

Issue summary: View changes

Short description updated.

Status: Needs review » Needs work

The last submitted patch, 3: d8-link-invalid-internal-link-in-editform-2300161.diff, failed testing.

maijs’s picture

Status: Needs work » Needs review
StatusFileSize
new2.42 KB

Updated patch after changes made to link module.

Status: Needs review » Needs work

The last submitted patch, 8: d8-link-invalid-internal-link-in-editform-2300161-2.diff, failed testing.

lendude’s picture

Status: Needs work » Closed (fixed)