Hi;

I have already posted one issue with the Maxlength module, but I think that what I am trying to do will need the help from both this module and that one?

I am maintaining one site that currently has about 30,000 active bloggers out of about 65,000 registered members. Now that we've upgraded to Drupal 7, I'm trying to add in meta tags that the bloggers can "place" in themselves within limits. I'm using tokens for the copyright and keywords meta tags along with this module. My last step is to get the description field to work the way I envision it.

So, for the meta_description field, what I'd like to do is allow the member to add in his own description with a limit of up to 155 characters - using the Maxlength module to provide the javascript countdown of how many characters he has left.

When I noticed that it wasn't working, I asked the maintainer of that module to integrate with metatags quick module, and he informed me of another dev version of that module which would work as it includes more widget types than the current releases. Now, when I add in a new meta field, I can configure the countdown message but there was no place to input a maxlength.

Looking at the module compared to the text module, I found 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 far, I changed the settings to 'settings' => array('meta_name', 'max_length' => 255), and then at metatags_quick_field_settings_form after '#required' => TRUE,
);

 $form['max_length'] = array(
 '#type' => 'textfield',
 '#title' => t('Maximum length'),
 '#default_value' => $settings['max_length'],
 '#required' => TRUE,
 '#description' => t('The maximum length of the field in characters.'),
 '#element_validate' => array('_element_validate_integer_positive'),
 );
   
   return $form;
 }

Now on the settings form for a meta_description I can input a maxlength in characters (although I'm not sure if it will validate). I don't know if I did this correctly and I don't know how to create a patch - or perhaps this is just a really niche feature that no one else really needs? But in case it is something that others would be interested in, I thought I should also let you know in case it is something that can be implemented by someone who knows more than I do?

Thank you

CommentFileSizeAuthor
#2 metatags_quick_maxlength-1272584.patch2.85 KBreujwils
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

valthebald’s picture

You're moving in the right direction.
To complete the cycle and to actually validate field value length, you need to modify metatags_quick_field_validate() (hook_field_validate)

reujwils’s picture

I also needed to get at the max length, exception from the perspective migration purposes as the old cms unfortunately had descriptions far longer than 255 characters. Bad, I know. So to support the migration and do data cleanup later, I need to change the length of the field definition.

So, I believe you also need to update hook_field_info and hook_field_widget_form. I'm attaching a patch with all changes mentioned so far in this thread. Let me know if there is anything missing still.

Thanks!

valthebald’s picture

Status: Active » Needs review

Marking this as 'needs review' to ease further commit...

valthebald’s picture

Title: Integrate with Maxlength? » Limit maximum length of the field value
Version: 7.x-2.x-dev » 7.x-2.1
Status: Needs review » Fixed
valthebald’s picture

Title: Limit maximum length of the field value » Limit maximum length of field values

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.