Hi; I'm using metatags quick right now to add cck fields for a couple of metatags on various types of content; one such field is for the description tag, but I noticed that when I add a normal textfield, the maxlength can be set to 155 characters and will count down normally as expected; but when I try to add in a meta field as a text field, it doesn't allow me to set the maxlength restriction (it doesn't even appear on the field configuration form).

Not sure if this is something that you can integrate or if I have to ask the maintainer of metatags quick to adjust to allow for this module to work with it, but I would like allow members to add a short description to their blog entries, but limit them to only using 155 characters (with the nice countdown).

Thank you

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev
Status: Active » Postponed (maintainer needs more info)

The development is currently done in maxlength 7.x-3.x.
There the feature of supporting different kind of widgets is supported already. This should work out of the box there.
It would be great if you could take some time to try it out and report back whether it's work for your with this module.

Fanaile’s picture

Hi Dereine :)

I must have totally spaced because I didn't even think to look through the releases to see if there was another dev version available... But I have successfully installed and updated to the 7.x-3.x-dev version.

I do see now when I add a meta description cck field from the metatags quick module (which is a textfield), it leads me to configure the settings for that field and there is a space where I can edit the countdown message... but there doesn't seem to be a place where I can input the maxlength in characters anywhere.

When I add a normal textfield, there is a setting where it lets me place in the maximum characters (usually defaults to 255) - that appears to be missing from the metatags textfield area...

So I started thinking that maybe that was actually caused by a difference between the metatags quick textfields and the regular textfields... And upon looking at the modules I noticed this:

metatags_quick.module

/**
 * Implements hook_field_info().
 * @see http://api.drupal.org/api/drupal/modules--field--field.api.php/function/hook_field_info/7
 */
function metatags_quick_field_info() {
  return array(
    'metatags_quick' => array(
      'label' => 'Meta',
      'description' => t('Meta tag to be displayed in the head section.'),
      'settings' => array('meta_name',),
      'default_widget' => 'text_textarea',
      'default_formatter' => 'metatags_quick_default',
      'property_type' => 'text',
    ),
  );
}

text.module

function text_field_info() {
  return array(
    'text' => array(
      'label' => t('Text'),
      'description' => t('This field stores varchar text in the database.'),
      'settings' => array('max_length' => 255),
      'instance_settings' => array('text_processing' => 0),
      'default_widget' => 'text_textfield',
      'default_formatter' => 'text_default',
    ),

So, I can't truly test anything out until I can get metatags quick to have an actual setting for maxlength; but from the looks of what I've seen so far, I think that this module is working as intended.

I am going to backup my metatags quick module and try adding in the needed settings; if it works then I will let you know that you're golden on this side and send this over to them so that maybe they can implement it as either a patch or commit (I don't know how to create a patch or I would do that).

Thanks again!

Fanaile’s picture

Status: Postponed (maintainer needs more info) » Needs work

We're really close :)

Okie - so it looks as though I was right in that metatags quick does not have a maxlength setting in their textfields; so by editing that module file to place in a maxlength I was able to go in and configure it correctly.

Now my only issue is that the countdown is not showing up when I go to add content. I'm going to give it a couple days so I can go back and look with fresh eyes or possibly get some input from others who can point at me and tell me where I went wrong, LOL. That'll also give you some time to see this before I move the issue over to the metatags queue :)

Thanks!

kjl’s picture

The reason why it doesn't work with the meta tags quick is because the types of widgets that maxlength looks for is hardcoded to:

$fields = array('text_textarea_with_summary', 'text_textarea');

While metagtags_quick defines its own widget as 'metatags_quick_textarea'

You can get around that with this:

function MYMODULE_NAME_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) {
  if (module_exists('metatags_quick') && module_exists('maxlength')) {
    $fields = array('metatags_quick_textarea');
    if (in_array($form['#instance']['widget']['type'], $fields)) {
      $form['instance']['widget']['settings']['maxlength_js'] = array(
        '#type' => 'textfield',
        '#title' => 'Maxlength JS',
        '#description' => t('The maximum length of the field in characters.'),
        '#default_value' => isset($form['#instance']['widget']['settings']['maxlength_js']) ? $form['#instance']['widget']['settings']['maxlength_js'] : NULL,
      );
      $form['instance']['widget']['settings']['maxlength_js_enforce'] = array(
        '#type' => 'checkbox',
        '#title' => t('Force text truncate'), 
        '#description' => t('Check this option if you want that the html (or the text) that the user inserts into the field to be truncated.'),
        '#default_value' => isset($form['#instance']['widget']['settings']['maxlength_js_enforce']) ? $form['#instance']['widget']['settings']['maxlength_js_enforce'] : NULL,
      );
      $form['instance']['widget']['settings']['maxlength_js_truncate_html'] = array(
        '#type' => 'checkbox',
        '#title' => t('Truncate html'),
        '#description' => t('Check this option if the input field may contain html text and you want to truncate it safely. This will also overwrite the maxlength validation from core, so that it will strip the tags before checking the length.'),
        '#default_value' => isset($form['#instance']['widget']['settings']['maxlength_js_truncate_html']) ? $form['#instance']['widget']['settings']['maxlength_js_truncate_html'] : NULL,
        '#states' => array(
          'enabled' => array(':input[id=edit-instance-widget-settings-maxlength-js-cut-text]' => array('checked' => TRUE),
         ),
       ),
     );
    }
  }
}
valderama’s picture

Status: Needs work » Needs review
FileSize
666 bytes

here is a patch, which adds support for metatags_quick directly to maxlength.

please review.

thx and best,
walter

Michèle’s picture

Thank you, vaderama! Your patch works like a charm.

cedewey’s picture

Issue summary: View changes
Status: Needs review » Closed (works as designed)

We are putting a feature freeze on the Drupal 7 version of the module, so I'm marking this Closed (works as designed). Thank you to each of you for working on this issue. If you do want to maintain the Drupal 7 version, do reach out. We'd be happy to bring you on board as a maintainer.