t('Meta tags'), 'description' => t('Meta tags fieldset.'), 'weight' => 10, ); return $extras; } /** * Implements hook_form_alter(). */ function nodewords_ui_form_alter(&$form, $form_state, $form_id) { if (isset($form['type']) && isset($form['#node']) && $form_id == $form['type']['#value'] . '_node_form') { if (!user_access('administer meta tags') && !user_access('edit meta tags')) { return; } $node = $form['#node']; $options = array('type' => NODEWORDS_TYPE_NODE, 'id' => 0); $tags = !empty($node->nodewords['metatags']) ? $node->nodewords['metatags'] : array(); if (!empty($form['nid']['#value'])) { $options['id'] = $form['nid']['#value']; } $form['nodewords'] = nodewords_tags_edit_fields($options, $tags, array( 'fieldset' => TRUE, 'tag options' => array('content type' => $form['type']['#value']), )); } } /** * Implements hook_form_FORM_ID_alter(). */ function nodewords_ui_form_taxonomy_form_term_alter(&$form, &$form_state) { if (!user_access('administer meta tags') && !user_access('edit meta tags')) { return; } if (isset($form_state['confirm_delete']) || isset($form_state['confirm_parents'])) { // Do not run on confirmation delete forms, which re-use the same form ID. return; } $options = array('type' => NODEWORDS_TYPE_TERM, 'id' => 0); $tags = !empty($form_state['values']['nodewords']) ? $form_state['values']['nodewords'] : array(); if (!empty($form['tid']['#value'])) { $options['id'] = $form['tid']['#value']; if (empty($tags)) { $tags = nodewords_load_tags($options); } } $form['nodewords'] = nodewords_tags_edit_fields($options, $tags, array('fieldset' => TRUE)); $form['submit'] += array('#weight' => 50); if (isset($form['delete'])) { $form['delete'] += array('#weight' => 55); } } /** * Implements hook_form_FORM_ID_alter(). */ function nodewords_ui_form_taxonomy_form_vocabulary_alter(&$form, &$form_state) { if (!user_access('administer meta tags') && !user_access('edit meta tags')) { return; } $options = array('type' => NODEWORDS_TYPE_VOCABULARY, 'id' => 0); $tags = !empty($form_state['values']['nodewords']) ? $form_state['values']['nodewords'] : array(); if (!empty($form['vid']['#value'])) { $options['id'] = $form['vid']['#value']; if (empty($tags)) { $tags = nodewords_load_tags($options); } } $form['nodewords'] = nodewords_tags_edit_fields($options, $tags, array('fieldset' => TRUE)); $form['submit'] += array('#weight' => 50); if (isset($form['delete'])) { $form['delete'] += array('#weight' => 55); } } /** * Implements hook_form_FORM_ID_alter(). */ function nodewords_ui_form_nodewords_admin_settings_form_alter(&$form, $form_state) { $enabled_options = array(); $user_pages = array( NODEWORDS_TYPE_NODE, NODEWORDS_TYPE_USER, ); $tags_info = nodewords_get_possible_tags(); if (!empty($tags_info)) { $form['enabled']['ui'] = array( '#type' => 'fieldset', '#title' => t('Meta tags enabled on other edit forms'), '#collapsible' => TRUE, '#weight' => 2, '#theme' => 'nodewords_ui_enabled_metatags', ); $select_options = array( 'never' => t('Never'), 'empty' => t('When the meta tag is empty'), 'always' => t('Always'), ); foreach ($tags_info as $name => $info) { $bool = ( ( !empty($info['context']['allowed']) && is_array($info['context']['allowed']) && count(array_intersect($user_pages, $info['context']['allowed'])) ) || ( !empty($info['context']['denied']) && is_array($info['context']['denied']) && (count(array_intersect($user_pages, $info['context']['denied'])) != count($user_pages)) ) ); if ($bool || empty($info['context']['allowed']) || empty($info['context']['allowed'])) { $enabled_options[$name] = ''; $form['enabled']['ui']['nodewords_ui_use_default_value_' . $name] = array( '#type' => 'select', '#default_value' => variable_get('nodewords_ui_use_default_value_' . $name, 'empty'), '#options' => $select_options, '#multiple' => FALSE, ); } } $form['enabled']['ui']['nodewords_ui_edit'] = array( '#type' => 'checkboxes', '#options' => $enabled_options, '#default_value' => variable_get('nodewords_ui_edit', array()), '#checkall' => TRUE ? 'nodewords-enabled-metatags-ui-edit-form' : FALSE, ); } else { $form['nodewords_ui_edit'] = array( '#type' => 'value', '#value' => variable_get('nodewords_ui_edit', array()), ); } } /** * Implements hook_nodeapi(). */ function nodewords_ui_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { if ($op == 'prepare translation' && isset($node->translation_source->nodewords)) { $node->nodewords = $node->translation_source->nodewords; } } /** * Implements hook_theme(). */ function nodewords_ui_theme() { return array( 'nodewords_ui_enabled_metatags' => array( 'arguments' => array('form' => array()), ), ); } /** * Implements hook_user(). */ function nodewords_ui_user($op, &$edit, &$account, $category = NULL) { if ($op == 'form' && $category == 'account') { if (user_access('administer meta tags') || user_access('edit meta tags')) { $options = array('type' => NODEWORDS_TYPE_USER, 'id' => $account->uid); $tags = isset($account->nodewords['metatags']) ? $account->nodewords['metatags'] : array(); $form['nodewords'] = nodewords_tags_edit_fields($options, $tags, array('fieldset' => TRUE)); return $form; } } } /** * Render the list of enabled meta tags in non administrative forms. */ function theme_nodewords_ui_enabled_metatags($form) { foreach (nodewords_get_possible_tags() as $name => $info) { $row = array(); if (isset($form['nodewords_ui_edit'][$name])) { $row[] = $info['label']; $row[] = drupal_render($form['nodewords_ui_edit'][$name]); $row[] = drupal_render($form['nodewords_ui_use_default_value_' . $name]); $rows[] = $row; } } $header[] = t('Meta tag'); $header[] = array( 'data' => t('Show in edit form'), 'class' => (TRUE && count($rows) > 1) ? 'nodewords-enabled-metatags-ui-edit-form' : '', ); $header[] = t('Use the default value'); return theme('table', $header, $rows) . drupal_render($form); }