Commit 5efd16b1 authored by Nathan Haug's avatar Nathan Haug
Browse files

Keeping up with 5 version changes. No funtionality changes.

parent ddaeee7e
div.link-field-column {
float: left;
width: 50%;
width: 48%;
}
\ No newline at end of file
......@@ -153,9 +153,18 @@ function link_widget_info() {
*/
function link_widget($op, &$node, $field, &$node_field) {
switch ($op) {
case 'prepare form values':
if ($_POST[$field['field_name']]) {
$node_field = $_POST[$field['field_name']];
unset($node_field['count']);
unset($node_field['more-url']);
unset($node_field['more']);
}
case 'form':
foreach($node_field as $delta => $value) {
_link_widget_prepare($node_field[$delta],$delta);
if (is_numeric($delta)) {
_link_widget_prepare($node_field[$delta],$delta);
}
}
$form = array();
......@@ -174,10 +183,11 @@ function link_widget($op, &$node, $field, &$node_field) {
if ($_POST['edit'][$field['field_name']]) {
$node_field = $_POST['edit'][$field['field_name']];
}
$delta = 0;
// Render link fields for all the entered values
foreach ($node_field as $data) {
if ($data['url']) {
if (is_array($data) && $data['url']) {
_link_widget_form($form[$field['field_name']][$delta], $field, $data, $delta);
$delta++;
}
......@@ -186,6 +196,35 @@ function link_widget($op, &$node, $field, &$node_field) {
foreach (range($delta, $delta + 1) as $delta) {
_link_widget_form($form[$field['field_name']][$delta], $field, $node_field, $delta);
}
// Create a wrapper for additional fields
$form[$field['field_name']]['wrapper'] = array(
'#type' => 'markup',
'#value' => '<div id="' . str_replace('_', '-', $field['field_name']) . '-wrapper" class="clear-block"></div>',
);
// Add 'More' Javascript Callback
$form[$field['field_name']]['more-url'] = array(
'#type' => 'hidden',
'#value' => url('link/widget/js/' . $field['type_name'] . '/' . $field['field_name'], NULL, NULL, TRUE),
'#attributes' => array('class' => 'more'),
'#id' => str_replace('_', '-', $field['field_name']) . '-more-url',
);
// Add Current Field Count
$form[$field['field_name']]['count'] = array(
'#type' => 'hidden',
'#value' => $delta,
'#id' => str_replace('_', '-', $field['field_name']) . '-count',
);
// Add More Button
$form[$field['field_name']]['more'] = array(
'#type' => 'button',
'#value' => t('More Links'),
'#name' => 'more',
'#id' => str_replace('_', '-', $field['field_name']) . '-more',
);
} // end if multiple
else {
_link_widget_form($form[$field['field_name']][0], $field, $node_field[0]);
......@@ -194,6 +233,9 @@ function link_widget($op, &$node, $field, &$node_field) {
case 'validate':
if (!is_object($node)) return;
unset($node_field['count']);
unset($node_field['more-url']);
unset($node_field['more']);
foreach($node_field as $delta => $value) {
if ($value['url'] && !(isset($field['widget']['default_value'][$delta]['url']) && $value['url'] == $field['widget']['default_value'][$delta]['url'] && !$field['required'])) {
// Validate the link
......@@ -213,12 +255,29 @@ function link_widget($op, &$node, $field, &$node_field) {
return;
case 'process form values':
// Remove the JS helper fields
unset($node_field['more-url']);
unset($node_field['count']);
unset($node_field['more']);
foreach($node_field as $delta => $value) {
_link_widget_process($node_field[$delta],$delta, $field, $node);
if (is_numeric($delta)) {
_link_widget_process($node_field[$delta],$delta, $field, $node);
}
}
return;
case 'submit':
// Don't save empty fields (beyond the first one)
$save_field = array();
unset($node_field['more-url']);
unset($node_field['count']);
unset($node_field['more']);
foreach ($node_field as $delta => $value) {
if (!empty($value['url']) || $delta == 0) {
$save_field[] = $node_field[$delta];
}
}
$node_field = $save_field;
return;
}
}
......@@ -230,7 +289,7 @@ function link_widget($op, &$node, $field, &$node_field) {
function _link_widget_form(&$form_item, $field, $node_field, $delta = 0) {
$form_item = array(
'#tree' => true,
'#tree' => TRUE,
'#theme' => 'link_widget_form_row',
// Add a microweight to keep fields in first-in first-out order
'#weight' => $field['widget']['weight'].".00".$delta,
......@@ -244,7 +303,7 @@ function _link_widget_form(&$form_item, $field, $node_field, $delta = 0) {
$form_item['url'] = array(
'#type' => 'textfield',
'#maxlength' => '255',
'#title' => t('URL'),
'#title' => $delta == 0 ? t('URL') : NULL,
'#default_value' => ($node_field['url']) ? $node_field['url'] : $default_url,
'#required' => ($delta == 0) ? $field['required'] : FALSE,
);
......@@ -256,7 +315,7 @@ function _link_widget_form(&$form_item, $field, $node_field, $delta = 0) {
$form_item['title'] = array(
'#type' => 'textfield',
'#maxlength' => '255',
'#title' => t('Title'),
'#title' => $delta == 0 ? t('Title') : NULL,
'#default_value' => ($node_field['title']) ? $node_field['title'] : $default_title,
'#required' => ($delta == 0 && $field['title'] == 'required') ? $field['required'] : FALSE,
);
......@@ -294,15 +353,32 @@ function _link_widget_process(&$node_field, $delta = 0, $field, $node) {
}
}
function _link_widget_name($form) {
if (!isset($form['#name'])) {
$name = array_shift($form['#parents']);
$form['#name'] = $name;
if (count($form['#parents'])) {
$form['#name'] .= '['. implode('][', $form['#parents']) .']';
}
array_unshift($form['#parents'], $name);
}
if (!isset($form['#id'])) {
$form['#id'] = form_clean_id('edit-'. implode('-', $form['#parents']));
}
return $form;
}
/**
* Theme the display of the entire link set
*/
function theme_link_widget_form($element) {
drupal_set_html_head('<style type="text/css" media="all">@import "/' . drupal_get_path('module', 'link') .'/link.css' . '";</style>');
// Check for multiple
// Check for multiple (output normally)
if (isset($element[1])) {
$output = form_render($element);
}
// Add the field label to the 'Title' and 'URL' labels
else {
if (isset($element[0]['title'])) {
$element[0]['title']['#title'] = $element['#title'] . ' ' . $element[0]['title']['#title'];
......@@ -323,11 +399,12 @@ function theme_link_widget_form($element) {
*/
function theme_link_widget_form_row($element) {
$output = '';
$output .= '<div class="link-field-row">';
$output .= '<div class="link-field-row"><div class="link-field-subrow">';
if ($element['title']) {
$output .= '<div class="link-field-title link-field-column">' . form_render($element['title']) . '</div>';
}
$output .= '<div class="link-field-url' . ($element['title'] ? ' link-field-column' : '') . '">' . form_render($element['url']) . '</div>';
$output .= '</div><br class="clear" />';
if ($element['attributes']) {
$output .= '<div class="link-attributes">' . form_render($element['attributes']) . '</div>';
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment