I've been searching around for help on this and I suspect it's not there because drupal 7 isn't mainstream in the release cycle yet so I thought I'd ask the question here since Link is the Field Type I want to use.

I'm creating a custom content type in a module I'm building and I'd like to add Link as one of the installed fields. I'm following the example from the Examples project (node_example) and I'm wondering after I install Link what is the Type that I'd put in and what are the display options.

As an example here is what is in node_example:

'node_example_link' => array(
'field_name' => 'node_example_link',
'cardinality' => 3,
'type' => 'text', <------ What would this be
'settings' => array( <------ Are there any settings?
'max_length' => 60,
),

And then for defining the instances:

'node_example_link' => array(
'field_name' => 'node_example_link',
'label' => $t('A Link.'),
'widget' => array(
'type' => 'text_textfield', <----- What are the available widgets?
),
'display' => array(
'example_node_list' => array(
'label' => 'hidden',
'type' => 'node_example_???', <------- What are the available displays?
),
),
),

Thanks so much for your help. I'm sure this will help others even with other field types.

Tony

Comments

jlaurin’s picture

Hi,

I found that you can add a link field with this type :

'type' => 'link_field',

I don't know all the other settings, but I will check it out.

jlaurin’s picture

Version: 7.x-1.0-alpha3 » 7.x-1.0-alpha2

Here is an exemple to create a Link in a content type :

  $field = field_info_field('fc_urlaudio');
  $instance = field_info_instance('node', 'fc_urlaudio', 'formation_continue');
  
  if (empty($field))
  {
		$field = array(
      'field_name' => 'fc_urlaudio', 
      'type' => 'link_field', 
      'entity_types' => array('node'), 
    );
	
    $field = field_create_field($field);
  }

  if (empty($instance))
  {
		$instance = array(
      'field_name' => 'fc_urlaudio', 
      'entity_type' => 'node', 
      'bundle' => 'formation_continue', 
      'label' => utf8_encode("URL des documents audios"), 
      'settings' => array(
				'title' => 'none',
        'attributes' => array(
          'target' => '_blank',
        ),
			),
    );
    
		$instance = field_create_instance($instance);
  }
jcfiala’s picture

Version: 7.x-1.0-alpha2 » 7.x-1.0-alpha3

Hey folks - if you enclose your php with <code>, it'll display better.

scuba_fly’s picture

Version: 7.x-1.0-alpha2 » 7.x-1.1

Correct me if I'm wrong but I couldn't find this in the current version.

Thanks for the example jlaurin #2 was really helpful!
I tried 'type' => 'link' but only got errors ;)

jbenjamin’s picture

some more detail:

field:

 'machine_name' => array(
      'field_name' => 'name', 
      'cardinality' => 1,
      'type' => 'link_field',
  ),

instance:

  'link' => array(
    'field_name' => 'name_of_link_field',
    'label'       => $t('label of link field'),
    'widget'      => array(
      'type'    => 'link',
    ),
    'settings' => array(
      'title' => 'value', // value = Static Title, none = No Title,  required = Required Title, optional = Optional Title
      'title_value' => 'value of static title',
      'enable_tokens' => 0,
      'attributes' => array(
        'target' => '_blank',
      ),
    ),
  ),

hope this helps anyone looking.