Provide options in the UI to disable the metatag fields for a given entity type entirely. It should also provide options to control whether the global meta tags will be displayed instead.


Original request:

metatag settings:
admin/config/search/metatags

- taxonomy term (disabled)

edit any term:
/taxonomy/term/1/edit
Meta Tags fieldset still present.

Comments

dave reid’s picture

Category: bug » feature

Hrm, interesting. I guess it makes sense that if there is no valid configuration for that entity (aside from global) that you should not be able to edit any metatags for that item as well. I wonder if there is a use case to enable meta tags for specific content but not have any default meta tags for content?

Moving to feature request.

dave reid’s picture

Title: disabling taxonomy metatagas doesnt work. » Should not be able to edit individual entity meta tags if there is no default config for them
damienmckenna’s picture

Title: Should not be able to edit individual entity meta tags if there is no default config for them » Option to disable meta tags per entity/bundle/object
Version: » 7.x-1.x-dev
Component: Code » User interface
Status: Active » Postponed

A better way of making this a generic feature would be to provide a way of disabling meta tags for a given entity/bundle/object. Marking this as "postponed" as it won't be a 1.0 feature, unless someone provides a patch.

damienmckenna’s picture

Component: User interface » Code
damienmckenna’s picture

There was some code in #1371968: Show/Hide Meta tags fieldset per content type that might contribute towards this goal, will look at it after 1.0 is released.

JvE’s picture

This is the workaround module I used which should work again now that #1718594: Disabling metatags for bundles no longer works. is solved:


/**
 * @file
 * Module file for metatag_optional.
 */

/*
 * Implements hook_menu().
 */
function metatag_optional_menu() {
  $items['admin/config/search/metatags/optional'] = array(
    'title' => 'Enable/disable meta tags',
    'description' => 'Configure meta tag optional.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('metatag_optional_config_form'),
    'access arguments' => array('administer meta tags'),
    'type' => MENU_LOCAL_TASK,
  );
  return $items;
}

/*
 * Form definition for enabling and disabling meta tags.
 */
function metatag_optional_config_form($form, $form_state) {
  $form = array('#tree' => TRUE);
  // Show a title.
  $form['info'] = array(
    '#markup' => t('Choose which entities and bundles to enable meta tags for:'),
    '#prefix' => '<h3>',
    '#suffix' => '</h3>',
  );

  $entity_infos = entity_get_info();
  // Add in our own settings.
  $entity_infos = drupal_array_merge_deep($entity_infos, variable_get('metatag_optional_settings', array()));

  // Loop through entities and bundles.
  foreach ($entity_infos as $entity_key => $entity_info) {
    if (!empty($entity_info['bundles'])) {
      $options = array();
      $defaults = array();
      foreach ($entity_info['bundles'] as $bundle_key => $bundle_info) {
        if (!isset($entity_info['metatags']) || $entity_info['metatags']) {
          if (!isset($bundle_info['metatags']) || $bundle_info['metatags']) {
            $defaults[] = $bundle_key;
          }
        }
        $options[$bundle_key] = $bundle_info['label'];
      }
      // Add a checkboxes group for the bundles in this entity.
      $form['metatags'][$entity_key] = array(
        '#type' => 'checkboxes',
        '#options' => $options,
        '#default_value' => $defaults,
        '#title' => check_plain($entity_info['label']),
      );
    }
  }

  // Add submit button.
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save options'),
  );

  return $form;
}

/*
 * Handle form submission.
 */
function metatag_optional_config_form_submit($form, $form_state) {
  // Convert user input to mergable array.
  $config = array();
  foreach ($form_state['values']['metatags'] as $entity => $bundles) {
    foreach ($bundles as $bundle => $value) {
      $config[$entity]['bundles'][$bundle]['metatags'] = !empty($value);
    }
  }
  variable_set('metatag_optional_settings', $config);
  // Clear the entity info cache to ensure our alter hook gets called.
  entity_info_cache_clear();
  drupal_set_message(t('Meta tags options saved.'), 'status');
}

/*
 * Implements hook_entity_info_alter().
 */
function metatag_optional_entity_info_alter(&$entity_info) {
  // Merge our setting with the entity info to override any metatags.
  $entity_info = drupal_array_merge_deep($entity_info, variable_get('metatag_optional_settings', array()));
}

I'm a bit busy with project work atm but in a week or so I'd be willing to work on this if it becomes clear what approach to take.

JvE’s picture

damienmckenna’s picture

@JvE: They're two separate issues, one is a fix of the default interaction with entities, the other is a UI feature.

damienmckenna’s picture

Closed a duplicate: #1958992: Administrators cannot disable meta tags with the beta5 release.

That issue was gong by the assumption that if a configuration was not available for a given entity type that the fields should not be displayed. I don't know Dave's intentions, but that is not what I expect to happen, instead functionality from this issue would control it.

damienmckenna’s picture

Issue summary: View changes

Clarified the goals for this issue.

damienmckenna’s picture

Temporary solution:

/**
 * Implements hook_entity_info_alter().
 */
function example_entity_info_alter(&$info) {
  if (!empty($info['file'])) {
    $info['file']['metatags'] = FALSE;
  }
}
damienmckenna’s picture

Issue summary: View changes
Status: Postponed » Needs review
StatusFileSize
new1.99 KB

I've not tested this, but theoretically it should work. Check the README.txt for instructions.

damienmckenna’s picture

StatusFileSize
new2.05 KB

Rerolled, with a slight tweak on the note in README.txt.

damienmckenna’s picture

Status: Needs review » Fixed

Committed, after I did some testing and verified it worked correctly.

Status: Fixed » Closed (fixed)

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

user654’s picture

.

damienmckenna’s picture

@pinkonomy: Go to the new settings page under admin/content/search/metatags.

user654’s picture

.

damienmckenna’s picture

Uncheck the content type you want to exclude?

Exclude the Basic Page content type and users

That shows how to exclude the Basic Page content type and User entity entirely.

user654’s picture

.

damienmckenna’s picture

The settings page was added in 7.x-1.0-rc2.

mrpauldriver’s picture

Good work everyone