diff --git a/fieldable_panels_panes.module b/fieldable_panels_panes.module index d7a57b1..ab28256 100644 --- a/fieldable_panels_panes.module +++ b/fieldable_panels_panes.module @@ -588,10 +588,12 @@ function template_preprocess_fieldable_panels_pane(&$vars) { * Add a class for our bundle to the normal panels pane theme. */ function fieldable_panels_panes_preprocess_panels_pane(&$vars) { + global $language; if ($vars['pane']->type == 'fieldable_panels_pane') { $entity = fieldable_panels_panes_load_entity($vars['pane']->subtype); + $items = field_get_items('fieldable_panels_pane', $entity, 'fieldable_panels_panes_path', $language->language); if ($entity->link && !empty($vars['title'])) { - $vars['title'] = l($vars['title'], $entity->path); + $vars['title'] = l($vars['title'], $items[0]['value']); } $vars['classes_array'][] = 'pane-bundle-' . ctools_cleanstring($entity->bundle, array('lower case' => TRUE)); } @@ -812,14 +814,6 @@ function fieldable_panels_panes_entity_edit_form($form, &$form_state) { '#id' => 'edit-link', ); - $form['link']['path'] = array( - '#type' => 'textfield', - '#title' => t('Path'), - '#description' => t('The path for this link. This can be an internal Drupal path such as %add-node or an external URL such as %drupal. Enter %front to link to the front page.', array('%front' => '', '%add-node' => 'node/add', '%drupal' => 'http://drupal.org')), - '#dependency' => array('edit-link' => array(1)), - '#default_value' => $entity->path, - ); - $form['reusable'] = array( '#weight' => 10, ); @@ -890,6 +884,14 @@ function fieldable_panels_panes_entity_edit_form($form, &$form_state) { } field_attach_form('fieldable_panels_pane', $entity, $form, $form_state, $language); + // Shift the fieldable_panels_panes_path into the link fold and + // Make it dependent on link. + $form['fieldable_panels_panes_path']['#states'] = array( + 'visible' => array( + ':input#edit-link' => array('checked' => TRUE), + ), + ); + if (!empty($form_state['add submit'])) { $form['actions'] = array( '#type' => 'actions', @@ -908,7 +910,29 @@ function fieldable_panels_panes_entity_edit_form($form, &$form_state) { * Validate callback for the pane entity. */ function fieldable_panels_panes_entity_edit_form_validate($form, &$form_state) { - field_attach_form_validate('fieldable_panels_pane', $form_state['entity'], $form, $form_state); + field_attach_form_validate('fieldable_panels_pane', $form_state['fieldable_panels_pane'], $form, $form_state); + if ($form_state['values']['link']) { + $language = NULL; + if (function_exists('entity_language')) { + // entity_language() was added in Drupal 7.15. + $language = entity_language('fieldable_panels_pane', $form_state['fieldable_panels_pane']); + } + if (isset($form_state['values']['fieldable_panels_panes_path'][$language][0]['value']) + && !empty($form_state['values']['fieldable_panels_panes_path'][$language][0]['value'])) { + // Check that the link exists + $source = valid_url($form_state['values']['fieldable_panels_panes_path'][$language][0]['value'], TRUE); + if (!$source) { + $normal_path = drupal_get_normal_path($form_state['values']['fieldable_panels_panes_path'][$language][0]['value']); + $source = drupal_valid_path($normal_path); + } + if (!$source) { + form_set_error('fieldable_panels_panes_path', t('The path / url does not exist.')); + } + } + else { + form_set_error('fieldable_panels_panes_path', t('You have selected that the title links to a path please enter a valid path / url, or unselect "Make title a link".')); + } + } } /** @@ -925,6 +949,7 @@ function fieldable_panels_panes_entity_edit_form_submit($form, &$form_state) { $entity->category = $form_state['values']['category']; $entity->admin_title = $form_state['values']['admin_title']; $entity->admin_description = $form_state['values']['admin_description']; + $entity->fieldable_panels_panes_path = $form_state['values']['fieldable_panels_panes_path']; $entity->revision = $form_state['values']['revision']; // Only set a log message if there was a new revision. This prevents