Problem/Motivation

Link module uses the same field validation when setting defaults for a field, as when submitting field values on a node. For this reason, when Title and URL are required, it's not possible to set a default Title but not a default URL.

Proposed resolution

Extend existing conditional to also test for $entity, which will be set in the context of editing a node but not on the field configuration form.

Remaining tasks

  • With the current patch, in the case that a default title is set without an accompanying default URL, an error will be generated if the title is left at the default and no URL is entered. If the field is not required, this leads to the unexpected result that a user cannot create a new piece of content without either providing a URL or deleting the default title. Proposed resolution: in validation, in the case that (a) the URL is empty and (b) the title is at the default, unset the title rather than raising an error.
  • Maintainer requested an accompanying test.

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

AaronBauman’s picture

Status: Active » Needs review
dqd’s picture

@aaronbauman, thanks for the patch! can at least two three users please confirm that it works and that should be committed so that I can commit ?

thx!

jcfiala’s picture

Status: Needs review » Needs work

I'm not able to get the patch to reply. I get this error:

ex-ncaffey:link john$ git apply -v link-allow_default_title_without_default_link.patch 
Checking patch link.module...
error: while searching for:
    }
  }
  // Require a link if we have a title.
  if ($field['url'] !== 'optional' && strlen($item['title']) > 0 && strlen(trim($item['url'])) == 0) {
    form_set_error($field['field_name'] .']['. $delta .'][url', t('You cannot enter a title without a link url.'));
  }
  // In a totally bizzaro case, where URLs and titles are optional but the field is required, ensure there is at least one link.

error: patch failed: link.module:320
error: link.module: patch does not apply
AaronBauman’s picture

Status: Needs work » Needs review
FileSize
755 bytes

I must have rolled against an older version.
This patch works against 6.x-dev

dqd’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
780 bytes

rerolled patch against latest dev for clean issue queue only.
... and as far as I can see it works.

dqd’s picture

Status: Reviewed & tested by the community » Fixed

committed and pushed to HEAD.
authored by aaronbauman.

THX

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

AaronBauman’s picture

Version: 6.x-2.x-dev » 7.x-1.x-dev
Status: Closed (fixed) » Active

this didn't make it into 7.x

AaronBauman’s picture

Status: Active » Needs review
FileSize
694 bytes
jantoine’s picture

Assigned: Unassigned » jantoine
Status: Needs review » Needs work

New comments should be combined with existing comments before the code block (coding standards). Also, if the default Title is all that is populated when saving a node, the field should be ignored and not through an error. I'll tackle this in the distant future if no one else gets to it.

jantoine’s picture

Updated the patch in #9 to apply to the latest dev release.

jantoine’s picture

The patch in #11 wouldn't apply for me after I created it, perhaps due to the extra whitespace issues my editor automatically fixed. Attached is a patch in which I have removed all changes except for the fix found in #9 and which I was able to apply cleanly.

jcfiala’s picture

Version: 7.x-1.x-dev » 7.x-1.1

Updating to point to the current version.

erykmynn’s picture

Sorry if I'm a bit confused on this thread. I think this is the issue we're having with 7.x

Am I correct in surmising this fix made it into 6.x but is not committed to 7.x yet? or is at least not in the stable version?

Thanks!

Jaesin’s picture

Issue summary: View changes
FileSize
838 bytes

Same patch that applies to commit#: 4331edd (7.x1.2).

jcfiala’s picture

Status: Needs work » Needs review

Given that we have a patch in the latest update, I'm updating this to "Needs Review".

codi’s picture

Status: Needs review » Reviewed & tested by the community

#15 works great for me.

dqd’s picture

Version: 7.x-1.1 » 7.x-1.2
Assigned: jantoine » Unassigned
Priority: Minor » Normal
Status: Reviewed & tested by the community » Needs review
FileSize
838 bytes

#15: Same patch that applies to commit#: 4331edd (7.x1.2).

try to re-upload patch authored by @Jaesin for retesting and set issue to latest version 7.x-1.2.

---
... RTBC needs more than one review and we have no system test yet. Set back to Needs review.

dqd’s picture

hm, for some reason d.o. system auto test doesn't work (maybe because its a FR, not a bug?)

dqd’s picture

Issue summary: View changes

@Jaesin #15 : Sorry, can you please rewrite your patch following the Drupal coding and commenting standarts? (yes I know, the link module code is not 100% like this, but I would like to watch after it more) the //comment should be in the row before and not behind the code and Drupal prefers code wrapped in 80 bits per line maximum.

Thanks for understanding.

Patch works fine so far. Feel free to test by yourself following this link to a test enviroment: http://simplytest.me/project/link/7.x-1.2?patch[]=https://drupal.org/fil...

More reviews much appreciated. Thanks to all.

codi’s picture

Here's a new patch with the comment moved up. 80 char limit isn't a hard rule. I think the condition is fine the way it is.

Greg Boggs’s picture

This patch works when saving a node form, but if you try to edit the node with VBO, the error persists.

andyrigby’s picture

Patch works fine for me on the field config form. Then when creating content the link title is populated by default.

nedjo’s picture

Issue summary: View changes

if you try to edit the node with VBO, the error persists

This is the issue that @jantoine noted in #10:

if the default Title is all that is populated when saving a node, the field should be ignored and not through an error.

With the current patch, in the case that a default title is set without an accompanying default URL, an error will be generated if the title is left at the default and no URL is entered. If the field is not required, this leads to the unexpected result that a user cannot create a new piece of content without either providing a URL or deleting the default title. Proposed resolution: in validation, in the case that (a) the URL is empty and (b) the title is at the default, unset the title rather than raising an error.

thommyboy’s picture

Did this not make it into the module- I miss the same function in D8!

Chris Matthews’s picture

Version: 7.x-1.2 » 7.x-1.x-dev
Status: Needs review » Needs work

With the current patch, in the case that a default title is set without an accompanying default URL, an error will be generated if the title is left at the default and no URL is entered. If the field is not required, this leads to the unexpected result that a user cannot create a new piece of content without either providing a URL or deleting the default title. Proposed resolution: in validation, in the case that (a) the URL is empty and (b) the title is at the default, unset the title rather than raising an error.