Download & Extend

Autocomplete for internal links for nivo slider link fields

Project:Julio
Version:7.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:jgraham
Status:needs review

Issue Summary

At the moment the nivo slides can be linked to a url, which I think is good, however, it isn't clear a link is there, as there's no 'read more' link.

Also, as an alternative to supplying a url, it would be nice to be able to easily reference an existing node on the website.

For example, as a school I might want to promote an achievement on the slideshow, but to do so at the moment I would have to find the url to the node manually... and then julio doesn't make it clear there's any further information available.

Using node references instead we could also do the trimming of teaser text programatically, and hide all the more confusing field options in the slideshow node form, so all we have to fill in here is image and node reference.

Comments

#1

#2

Project:Julio» Media Nivo Slider
Version:7.x-1.x-dev» 7.x-1.x-dev

Unfortunately we don't have much control over this as we're using the Media Nivo Slider module. I'm moving this to the Media Nivo Slider queue, so feel free to follow up there.

#3

Version:7.x-1.x-dev» 7.x-1.2

#4

Status:active» closed (won't fix)

Unfortunately, I don't feel the above recommendations are really in line with what I want for the contrib releases of this module. The module is mainly intended as a way to easily take Media Gallery content and provide it for display via the Nivo Slider plugin and let the plugin handle all the display aspects and how the content is presented based on the available plugin settings.

Making modifications to the presentation by adding extra indicators or behavior that isn't standard to the plugin I feel would be confusing and unexpected to users who have seen the standard plugin and expect this module to provide that same presentation. That being said there is absolutely no reason you can't take the module and modify it to better suit your needs and requirements.

In terms of changing or adding the link functionality to use node reference rather than URLs, while I agree that in some use cases it may be easier to link to a node if the field was a node reference, I'm against tying the link functionality so directly to nodes. The link field as well as the caption are intended to remain flexible in allowing you to link to any URL regardless of backing entity or location of content. The same holds true for the caption, while it would be convenient in some cases if the slide caption was populated by the node teaser, doing so would limit the ability to create captions independent of content without having extra fields.

#5

Title:nivo slider - node reference / read more link» Autocomplete for internal links for nivo slider link fields?
Project:Media Nivo Slider» Julio
Version:7.x-1.2» 7.x-1.x-dev
Status:closed (won't fix)» active

We may not necessarily need the media_gallery module to include this. Below snippet is a proof of concept to use core autocomplete to help a user find internal links. It's subject to #93854: Allow autocompletion requests to include slashes (unless the module uses its own autocomplete.js) which will fix a problem with forward slashes, but it looks like that's due for inclusion in drupal 7.13

Better still, now we have #1524920: deprecate nivo-slider caption field in favor of description, it's fairly easy to add a read more button to the caption, such that it's appended to the nivo slider caption on node save/update when a link is present but not into the editable description, so we're not confusing users by altering their input. Attached screenshot shows a read more button on a nivo slider from another project, a similar style of read more button might work here?

<?php
function julio_slideshow_form_alter(&$form, &$form_state, $form_id) {
  if (
strpos($form_id, 'media_edit_') === 0) {
    if (!isset(
$form['#after_build'])) {
     
$form['#after_build'] = array();
    }
   
$form['#after_build'][] = 'julio_slideshow_media_multiedit_form_after_build';
  }
}

function
julio_slideshow_media_multiedit_form_after_build($form, &$form_state) {
  if (
$form['media_nivo_slider_image_link']) {
     
$form['media_nivo_slider_image_link']['und'][0]['value']['#autocomplete_path'] = 'julio_slideshow/autocomplete';
  }
  return
$form;
}

function
julio_slideshow_autocomplete($string = ''){
 
$args = func_get_args();
 
$string = implode('/', $args);
 
$matches = array();
  if (
$string) {
   
$result = db_query_range("SELECT alias FROM {url_alias} WHERE (alias) LIKE :string", 0, 10, array(':string' => '%' . $string . '%'));
    foreach (
$result as $record) {
     
$matches[$record->alias] = check_plain($record->alias);
    }
  }
  print
drupal_json_output($matches);
}
?>

We could even feasibly check if the link is internal and pull a caption / title from a node if so... But I've changed my mind on that and actually think it's better to allow a custom one, because we do have very little space here and trimming would likely result in a non-sensical sentence.

AttachmentSize
nivo_read_more.gif 72.38 KB

#6

autocomplete works quite nice:
nivo slider autocomplete

AttachmentSize
nivo_slider_autocomplete.png 2.35 KB

#7

actually, maybe doing this is better:

<?php
$result
= db_query_range("SELECT nid, title, status FROM {node} WHERE (title) LIKE :string AND status = 1", 0, 10, array(':string' => '%' . $string . '%'));
    foreach (
$result as $record) {
     
$path = drupal_get_path_alias('node/' . $record->nid);
     
$matches[$path] = check_plain($record->title . ' (' . $path . ')');
    }
?>

nivo slider autocomplete

AttachmentSize
nivo_slider2.png 2.28 KB

#8

Title:Autocomplete for internal links for nivo slider link fields?» Autocomplete for internal links for nivo slider link fields
Assigned to:Anonymous» jgraham

I have split the "Read More" functionality into #1528702: Caption overflow on excessive text in nivo-slider images let's keep this discussion focused on the autocomplete feature.

I like the idea of the auto-complete here as it improves the UX considerably.

#9

This patch adds:

  • An auto-complete helper for internal links, searching by title
  • A helper to suggest a http:// prefix where absent for valid absolute links
  • Inline indication of a bad absolute/relative url or no titles
  • New title and description of the field to reflect the helper, removing references to nivo slider which may be confusing

search by title
absolute link prefix helper
Invalid link/title

AttachmentSize
autocomplete_slideshow_helper-1516446-9.patch 3.82 KB

#10

Status:active» needs review

#11

Status:needs review» active

Forgot the hook_menu, also, not sure why I used after_build here.

Setting this back to active as I'm sure the maintainers get the idea and I can't see it being committed (coding standards, the autocomplete being a bit convoluted etc.) even if fixes for the above added.

#12

Status:active» needs work

Marking "needs work" as indicated by lightsurge's comments in 11.

Also, in general after_build is required when you want to modify fields as they just have stub entries in form_alter and haven't gone through their whole render chain yet.

#13

Status:needs work» needs review

Patch now includes the relevant hook_menu

Also moved all the form alterations back into the form_alter, it didn't seem to make any difference in this scenario

AttachmentSize
autocomplete_slideshow_helper-1516446-13.patch 4.34 KB

#14

Wrong patch... here's the right one.

AttachmentSize
autocomplete_slideshow_helper-1516446-13.patch 4.12 KB

#15

The Drupal core fix that this patch relies on is present in the 7.14 release of yesterday

nobody click here