How to include the link field into a custom field?

Created on 22 November 2011, almost 13 years ago
Updated 31 August 2024, 3 months ago

I am trying to write a custom field, which basically contains the following 3 fields:

  • Title
  • Description
  • Link

I tried to reuse the link module to implement the 'Link' field. But I got a lot problem in storing the input data, configuration, and validation. Could anyone help me on this, thanks.

This is what i write in the hook_field_widget_form():

function my_custom_fields_field_widget_form(&$form, &$form_state, $field, $instance,
  $langcode, $items, $delta, $element) {
  $widget = $element;
  $widget['#delta'] = $delta;

  switch ($instance['widget']['type']) {
    case 'examples_basic':
      $widget += array(
        '#type' => 'fieldset',
      	'#element_validate' => array('my_custom_fields_lever_examples_basic_validate'),
        '#delta' => $delta,
      );
      $widget['title'] = array(
        '#type' => 'textfield',
        '#title' => t('Title'),
        '#default_value' => isset($items[$delta]['title']) ? $items[$delta]['title'] : null,
      );
      $widget['desc'] = array(
        '#type' => 'textarea',
        '#title' => t('Descrption'),
        '#default_value' => isset($items[$delta]['desc']) ? $items[$delta]['desc'] : null,
      );
      $widget['url'] =  array(
        '#type' => 'link_field',
        '#title' => t('Link'),
      );
  }
  $element += $widget;
  return $element;
}
💬 Support request
Status

Closed: outdated

Version

1.0

Component

Code

Created by

🇨🇳China kurtzhong

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • 🇫🇷France dqd London | N.Y.C | Paris | Hamburg | Berlin

    I'll close this issue due to inactivity for 12 years and upcoming EOL of Drupal 7 in January 2025 . While the project version for Drupal 7 will keep providing support for security issues and website breaking bug fixes for Drupal 7, we should try to minimize the open issues for Drupal 7 in the queue as much as possible. Thanks for the report and all the efforts in here. Feel free to re-open if you can provide a fix or found an additional related problem which increases the issue priority to "Critical" here.

Production build 0.71.5 2024