Hi,

We can't fill 'title' and 'url' for a Link field with rules and the 'set data value' option.
Anyone has a solution ?

Thanks !

Comments

Nicolas Bouteille’s picture

Title: 'Set data value' link field doesn't work » 'Set data value' Link field URI doesn't work without http:// protocol
Category: bug » support
Priority: Major » Normal

I personally don't have this problem. Make sure you provide a parameter of type URI to your component so that you can actually set data value for your Link url.
My problem is that if the incoming URI parameter does not have a protocol like : "www.mysite.com" Rules won't set the data value. The value has to be like "http://www.mysite.com" for it to work.
Any idea how I can work around that?

Nicolas Bouteille’s picture

Is it possible to provide a parameter of type Field_item_link to a Rules component ? That way I could pass the whole Link field instead of just its url.

massiws’s picture

Category: support » bug

I think there is a bug or bad integration with Link and/or Token module.

I build a rule to set data value in a link field and I try to set both title and url values:

  • url value can be set only if it doesn't contains token value: if url contains token, Rules don't work;
  • when you try to set a title AND there is a default value specified in field UI settings, the last will be set;
  • when you try to set a title AND nothing's specified in field UI settings, no value is set;

Drupal 7.22
Rules 7.x-2.3
Link 7.x-1.1
Token 7.x-1.5
Entity tokens 7.x-1.1

kruser’s picture

Issue summary: View changes

I'm seeing a similar issue. I set an Action "Set a data value" on a Link field "Selected data: entity-created:field-website-url:url". If I set any value containing an "http://" and click Save, the page simply refreshes and no value is set. If the the valuse being set does not contain http://, then it saves just fine.

TR’s picture

Version: 7.x-2.2 » 7.x-2.x-dev
Status: Active » Closed (cannot reproduce)

OK, so we have five posts with a total of 6 different issues, plus one feature request. Bottom line, I can't reproduce any of the problems - it all works for me (and I will give you a working example at the end of this post). Let's address these issues one-by-one.

Before I do that, even though no one has said exactly how they've created their link fields, I'm going to assume that everyone is using the Link module. That's what I tested with. There are MANY ways a link field can be configured using this module, and I used the defaults. Maybe there is a problem if you use some of the non-default settings, but if that's the case then that's up to you to report if you think there is still a problem. I'm not going to even try to guess how you've configured the field, let alone try out all the combinations of settings just to try to see if one of them fails.

First, the feature request:

Is it possible to provide a parameter of type Field_item_link to a Rules component?

Yes, but that would be something that would need to be provided by the Link module. That module would need to implement hook_rules_data_info() to expose a link data structure to the Entity API and hence to Rules. This is not something we would put into Rules core.

Next, the 6 issues:
1) The original poster wrote:

We can't fill 'title' and 'url' for a Link field with rules and the 'set data value' option.

I can't reproduce this, and post #1 said he couldn't reproduce this either. Since there is no further information provided, I can't guess what was wrong, but as far as I can tell this is not a bug in Rules (Cannot reproduce). I have provided below an export of a Rule that demonstrates how these values can be set.

2) Comment #1 wrote:

My problem is that if the incoming URI parameter does not have a protocol like : "www.mysite.com" Rules won't set the data value. The value has to be like "http://www.mysite.com" for it to work.

I'd like to note that this is EXACTLY THE OPPOSITE of what #4 said. They can't both be right, so logically they cancel each other out. The Rule export below shows me setting the url with an http protocol specified. Edit the Rule to remove the protocol and test again - both work for me. (Cannot reproduce).

3)

url value can be set only if it doesn't contains token value: if url contains token

The Rule export below shows how I set the url with a token, and it works for me. (Cannot reproduce).

4)

Rules don't work; when you try to set a title AND there is a default value specified in field UI settings, the last will be set;

This and 5) both demonstrate that a problem may be related to the field settings of the link field, which have not been specified in any comment except #3, and the only mention in #3 is about the default value, nothing about any of the other settings. As I said, I can't possibly try all the settings, so I'm going to stick to the default settings unless otherwise mentioned.

After configuring the field with a default value for the link field's title and url I cannot reproduce this. The Rule export below shows how I set the title and url with a default value for both the title and url, and it works for me. (Cannot reproduce).

5)

Rules don't work; when you try to set a title AND nothing's specified in field UI settings, no value is set;

After configuring the field with NO default value for the link field's title and url I cannot reproduce this. The Rule export below shows how I set the title and url with NO default value for both the title and url, and it works for me. (Cannot reproduce).

6) Comment #4 wrote:

If I set any value containing an "http://" and click Save, the page simply refreshes and no value is set. If the the valuse being set does not contain http://, then it saves just fine.

See 2) - this comment is exactly the opposite of comment #1. The Rule export below shows me setting the url with an http protocol specified. Edit the Rule to remove the protocol and test again - both work for me. (Cannot reproduce).

Here is my test Rule. I have set up a link field on the default Article content type, using the Link module as described above, with default settings for the link field. The link field is named linkurl with machine name field_linkurl, field type Link, widget Link. I am triggering on the event "After saving new content of type Article". To trigger this Rule, create a new node of type Article,and fill in the link title and url (or leave them blank, it works either way). The rule will change the title and url that you filled in, and print a system message saying what it is doing.

{ "rules_link_field" : {
    "LABEL" : "Link field",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_insert--article" : { "bundle" : "article" } },
    "DO" : [
      { "data_set" : {
          "data" : [ "node:field-linkurl:title" ],
          "value" : "[site:current-user:name] - 123"
        }
      },
      { "data_set" : {
          "data" : [ "node:field-linkurl:url" ],
          "value" : "http:\/\/www.example.com\/temp\/[node:nid]"
        }
      },
      { "drupal_message" : { "message" : "Changing link field title to: \u0022[site:current-user:name] - 123\u0022\u003Cbr \/\u003E\r\nChanging link field url to: \u0022http:\/\/www.example.com\/temp\/[node:nid]\u0022\r\n" } }
    ]
  }
}