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;
}

Comments

dqd’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
Status: Active » Closed (outdated)

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.