You are here

public static function LinkImageFieldWidget::process in Link Image Field 8

Form API callback: Processes a image_image field element.

Expands the image_image type to include the alt and title fields.

This method is assigned as a #process callback in formElement() method.

Overrides ImageWidget::process

File

lib/Drupal/linkimagefield/Plugin/Field/FieldWidget/LinkImageFieldWidget.php, line 43

Class

LinkImageFieldWidget
Plugin implementation of the 'linkimagefield' widget.

Namespace

Drupal\linkimagefield\Plugin\Field\FieldWidget

Code

public static function process($element, &$form_state, $form) {
  $element = parent::process($element, $form_state, $form);
  $item = $element['#value'];
  $item['fids'] = $element['fids']['#value'];
  $element['url'] = array(
    '#title' => t('Link URL'),
    '#type' => 'textfield',
    '#default_value' => isset($item['url']) ? $item['url'] : $element['#url'],
    '#description' => t('This URL will be loaded when the image is clicked'),
    '#weight' => -4,
    '#access' => (bool) $item['fids'],
  );
  $element['rel'] = array(
    '#title' => t('Link Rel'),
    '#type' => 'textfield',
    '#default_value' => isset($item['rel']) ? $item['rel'] : '',
    '#description' => t('Add rel attributes for bots, lightbox galleries, etc...'),
    '#maxlength' => \Drupal::config('linkimagefield.basic')
      ->get('image_longdesc_length'),
    '#weight' => -4,
    '#access' => (bool) $item['fids'] && $element['#rel_field'],
  );
  $element['class'] = array(
    '#title' => t('Link Class'),
    '#type' => 'textfield',
    '#default_value' => isset($item['class']) ? $item['class'] : '',
    '#description' => t('Add classes for theming, colorboxes, etc...'),
    '#maxlength' => \Drupal::config('linkimagefield.basic')
      ->get('image_longdesc_length'),
    '#weight' => -4,
    '#access' => (bool) $item['fids'] && $element['#class_field'],
  );
  $custom_target = $element['#custom_target'];
  $options = array(
    'default' => t('Use Default') . ' (' . $element['#target'] . ')',
  ) + _linkimagefield_widget_url_target_options();
  $element['target'] = array(
    '#title' => t('Link Target'),
    '#type' => $custom_target ? 'select' : 'value',
    '#options' => $custom_target ? $options : NULL,
    '#default_value' => $custom_target && isset($item['target']) ? $item['target'] : $element['#target'],
    '#description' => t('Window/Frame Target for the URL'),
    '#weight' => -4,
    '#access' => (bool) $item['fids'] && $custom_target,
  );
  $element['longdesc'] = array(
    '#title' => t('Image Longdesc'),
    '#type' => 'textfield',
    '#default_value' => isset($item['longdesc']) ? $item['longdesc'] : '',
    '#description' => t('The longdesc is used to provide a link to a long description of the image.'),
    '#maxlength' => \Drupal::config('linkimagefield.basic')
      ->get('image_longdesc_length'),
    '#weight' => -1,
    '#access' => (bool) $item['fids'] && $element['#longdesc_field'],
  );
  return $element;
}