diff --git a/js/metatags_quick.meta.js b/js/metatags_quick.meta.js new file mode 100644 index 0000000..62a5392 --- /dev/null +++ b/js/metatags_quick.meta.js @@ -0,0 +1,24 @@ + +(function ($) { + +/** + * Custom summary for the module vertical tab. + */ +Drupal.behaviors.metatags_quick_meta = { + attach: function (context) { + // Use the fieldset class to identify the vertical tab element + $('fieldset.metatags_quick-meta-form', context).drupalSetSummary(function (context) { + + var total = 0; + $('.metatags_quick-meta-form :input').each(function() { + total += this.value.length; + }); + + return total ? + Drupal.t('Using custom information') : + Drupal.t('None'); + }); + } +}; + +})(jQuery); \ No newline at end of file diff --git a/metatags_quick.meta.inc b/metatags_quick.meta.inc new file mode 100644 index 0000000..ee84926 --- /dev/null +++ b/metatags_quick.meta.inc @@ -0,0 +1,65 @@ + 'metatags_quick'))->fetchCol(); +} + +function _metatags_quick_meta_submit(&$form, &$form_state) { + $fields = metatags_quick_meta_find_fields(); + foreach ($fields as $field) { + if (isset($form_state['values']['vertical_tabs_meta'][$field])) { + $form_state['values'][$field] = $form_state['values']['vertical_tabs_meta'][$field]; + unset($form_state['values']['vertical_tabs_meta'][$field]); + } + } +} + + +/** + *Traverse through the form to reposition quicktabs. + */ +function metatags_quick_meta($form, &$form_state) { + + $fields = metatags_quick_meta_find_fields(); + + foreach ($fields as $field) { + if (isset($form[$field])) { + $form['vertical_tabs_meta'][$field] = $form[$field]; + unset($form[$field]); + } + } + + if (!isset($form['vertical_tabs_meta'])) { + return $form; + } + + $form['#submit'][] = '_metatags_quick_meta_submit'; + + $form['vertical_tabs_meta'] += array( + '#type' => 'fieldset', + '#title' => t('Meta search information'), + '#collapsible' => TRUE, + '#collapsed' => FALSE, + '#attributes' => array( + 'class' => array('metatags_quick-meta-form'), + ), + // The #group value must match the name of the vertical tabs element. + // In most cases, this is 'additional_settings'. + '#group' => 'additional_settings', + // Attach the javascript for vertical tabs. + '#attached' => array( + 'js' => array( + 'vertical-tabs' => drupal_get_path('module', 'metatags_quick') . '/metatags_quick.meta.js', + ), + ), + '#tree' => TRUE, + '#weight' => -2, + ); + + return $form; +} + diff --git a/metatags_quick.module b/metatags_quick.module index 8203818..f058a2f 100644 --- a/metatags_quick.module +++ b/metatags_quick.module @@ -480,3 +480,13 @@ function _metatags_quick_path_based_page() { || !($router_item['page_arguments'][0] instanceof stdClass); } +/** + * Implement hook_form_alter(). + */ +function metatags_quick_form_alter(&$form, &$form_state, $form_id) { + // Put Metatags inside on node edit form + if (function_exists('metatags_quick_field_info') && !empty($form['#node_edit_form'])) { + include_once(drupal_get_path('module', 'metatags_quick') . '/metatags_quick.meta.inc'); + $form = metatags_quick_meta($form, &$form_state); + } +}