You are here

function metatag_admin_settings_form in Metatag 7

Misc settings page.

1 string reference to 'metatag_admin_settings_form'
metatag_menu in ./metatag.module
Implements hook_menu().

File

./metatag.admin.inc, line 667
Administration page callbacks for the metatag module.

Code

function metatag_admin_settings_form() {
  $form = array();
  $form['#attached'] = array(
    'js' => array(
      drupal_get_path('module', 'metatag') . '/metatag.admin.js',
    ),
    'css' => array(
      drupal_get_path('module', 'metatag') . '/metatag.admin.css',
    ),
  );
  $form['entities'] = array(
    '#type' => 'fieldset',
    '#title' => t('Master controls for all entities'),
    '#description' => t("By enabling and disabling items here, it is possible to control which entities (e.g. nodes, taxonomy terms) and bundles (e.g. content types, vocabularies) will have the meta tag form available on their respective edit pages. If an entity type is disabled it also disables it for <em>all</em> of that entity type's bundles.<br />Technical note: Entity types must not be configuration entities and must have view modes in order to be compatible."),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  foreach (entity_get_info() as $entity_type => $entity_info) {

    // Only show entities that are capable of using meta tags.
    if (metatag_entity_type_is_suitable($entity_type, $entity_info)) {
      $entity_enabled = metatag_entity_supports_metatags($entity_type);
      $form['entities']['metatag_enable_' . $entity_type] = array(
        '#type' => 'checkbox',
        '#title' => t($entity_info['label']),
        '#default_value' => $entity_enabled,
      );

      // Some entities, e.g. User, (core) File, have a single bundle with the
      // same name as the entity, so only show the bundles list if there is
      // more than one of them and the bundle's name isn't the same as the
      // entity type's.
      if (!empty($entity_info['bundles'])) {
        foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
          if (count($entity_info['bundles']) > 1 || $entity_type != $bundle_name) {

            // If the entity type was disabled, automatically enable the bundle.
            // This will have the effect that if the entity type is enabled in
            // the form then all of the bundles will then also be enabled. This
            // is safe to do because in the rest of the module the bundle will
            // be ignored if the entity is disabled.
            $form['entities']['metatag_enable_' . $entity_type . '__' . $bundle_name] = array(
              '#type' => 'checkbox',
              '#title' => t($bundle_info['label']),
              '#default_value' => !$entity_enabled || metatag_entity_supports_metatags($entity_type, $bundle_name),
              '#attributes' => array(
                // Add some theming that'll indent this bundle.
                'class' => array(
                  'metatag-bundle-checkbox',
                ),
              ),
              '#states' => array(
                'visible' => array(
                  ':input[name="metatag_enable_' . $entity_type . '"]' => array(
                    'checked' => TRUE,
                  ),
                ),
              ),
            );
          }
        }
      }
    }
  }
  $form['additional'] = array(
    '#type' => 'fieldset',
    '#title' => t('Additional settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['additional']['metatag_pager_string'] = array(
    '#title' => t('Custom pager string'),
    '#type' => 'textfield',
    '#description' => t('When the current page includes a pager, e.g. the URL contains "?page=42", the [current-page:pager] token may be added to a meta tag to differentiate between two pages that would otherwise have the same meta tags. The value "PAGER" (must be in uppercase) will be replaced by the actual page count. Note: the pager will only output if the page number is 2 or above and the string "page=NUMBER" is in the URL.<br />For best use, it may be worthwhile to add the [current-page:pager] to the page title to the left of the site name, to the start of description tags, etc.'),
    '#default_value' => variable_get('metatag_pager_string', 'Page PAGER | '),
  );
  $form['additional']['metatag_summary_text_field'] = array(
    '#title' => t('Add summary tokens for regular text fields'),
    '#type' => 'checkbox',
    '#description' => t("By default Metatag's summary tokens are added to long text fields. Enabling this option will also add summary tokens for all plain text fields."),
    '#default_value' => variable_get('metatag_summary_text_field', FALSE),
  );
  $form['additional']['metatag_summary_length'] = array(
    '#title' => t('Length of summary'),
    '#type' => 'textfield',
    '#description' => t("How long each of the summary tokens will be after it is truncated."),
    '#default_value' => variable_get('metatag_summary_length', 200),
  );
  $form['i18n'] = array(
    '#type' => 'fieldset',
    '#title' => t('Internationalization options'),
    '#description' => t('Additional options are available when using the <a href="@url">Internationalization module</a>.', array(
      '@url' => 'https://www.drupal.org/project/i18n',
    )),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['i18n']['metatag_i18n_disabled'] = array(
    '#title' => t('Disable i18n integration'),
    '#type' => 'checkbox',
    '#description' => t('If the i18n_string module is enabled but the site does not need to translate Metatag strings, the integration may be disabled to avoid a large volume of records being added to the translation system.'),
    '#default_value' => variable_get('metatag_i18n_disabled', FALSE),
    '#disabled' => !module_exists('i18n_string'),
  );
  $form['i18n']['metatag_i18n_translate_output'] = array(
    '#title' => t('Translate output'),
    '#type' => 'checkbox',
    '#description' => t('Optionally translate the final page output.'),
    '#default_value' => variable_get('metatag_i18n_translate_output', FALSE),
    '#disabled' => !module_exists('i18n_string'),
  );
  $form['i18n']['metatag_i18n_enable_watchdog'] = array(
    '#title' => t('Enable logging of translations to Watchdog'),
    '#type' => 'checkbox',
    '#description' => t('Optionally log to Watchdog any changes that happen.'),
    '#default_value' => variable_get('metatag_i18n_enable_watchdog', FALSE),
    '#disabled' => !module_exists('i18n_string'),
  );
  $form['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['advanced']['metatag_load_all_pages'] = array(
    '#type' => 'checkbox',
    '#title' => t('Output meta tags even if only global settings apply'),
    '#description' => t('By default Metatag will load the global default values for all pages that do not have meta tags assigned via the normal entity display or via Metatag Context. This may be disabled so that meta tags will only be output on pages that specifically have meta tags configured for them.'),
    '#default_value' => variable_get('metatag_load_all_pages', TRUE),
  );
  $form['advanced']['metatag_tag_admin_pages'] = array(
    '#type' => 'checkbox',
    '#title' => t('Output meta tags on admin pages'),
    '#description' => t('By default meta tags will not be output on admin pages, but it may be beneficial for some sites to do so.'),
    '#default_value' => variable_get('metatag_tag_admin_pages', FALSE),
  );
  $form['advanced']['metatag_extended_permissions'] = array(
    '#type' => 'checkbox',
    '#title' => t('Advanced permissions'),
    '#description' => t('Optionally add a permission for each individual meta tag. This provides tremendous flexibility for the editorial process, at the expense of making the permissions configuration more tedious.'),
    '#default_value' => variable_get('metatag_extended_permissions', FALSE),
  );
  $form['advanced']['metatag_entity_no_lang_default'] = array(
    '#type' => 'checkbox',
    '#title' => t("Don't load entity's default language values if no languages match"),
    '#description' => t("On a site with multiple languages it is possible for an entity to not have meta tag values assigned for the language of the current page. By default the meta tags for an entity's default language value will be used in this scenario, with the canonical URL pointing to the URL. This option may be disabled, i.e. to only load meta tags for languages that specifically have them assigned, otherwise using defaults."),
    '#default_value' => variable_get('metatag_entity_no_lang_default', FALSE),
  );
  $form['advanced']['metatag_load_defaults'] = array(
    '#type' => 'checkbox',
    '#title' => t("Load the module's default configurations"),
    '#description' => t("Control whether the module's default configuration is used. This will not affect configurations exported via Features."),
    '#default_value' => variable_get('metatag_load_defaults', TRUE),
  );
  $form['advanced']['metatag_cache_output'] = array(
    '#type' => 'checkbox',
    '#title' => t('Cache meta tag output'),
    '#description' => t('Enabling this will cause all meta tag output to be cached for each page, which may aid with site performance in some circumstances. Should not be used if there are paths which include user-specific meta tags for the <em>current user</em>, they may lead to information about the user being accidentally leaked; this problem does not affect the "user/[uid]" pages. It may also cause the {cache_metatag} cache table to grow to be extremely large in certain circumstances.'),
    '#default_value' => variable_get('metatag_cache_output', FALSE),
  );
  $form['advanced']['metatag_leave_core_tags'] = array(
    '#type' => 'checkbox',
    '#title' => t("Leave core's meta tags as-is"),
    '#description' => t("Drupal core outputs a number of meta tags itself: canonical, shortlink, and generator. Metatag can be used to replace these with custom values. Should Metatag not have values for these meta tags, core's tags will normally be removed. Enabling this option will leave those meta tags on the page, even if Metatag is not replacing them."),
    '#default_value' => variable_get('metatag_leave_core_tags', FALSE),
  );
  $form['advanced']['metatag_page_region'] = array(
    '#type' => 'select',
    '#title' => t("Page region to use"),
    '#description' => t("By default Metatag uses the 'Content' region to trigger output of the meta tags. Some themes do not have this region, so it can be necessary to pick another."),
    '#options' => system_region_list(variable_get('theme_default', 'bartik')),
    '#default_value' => variable_get('metatag_page_region', 'content'),
  );
  $form['advanced']['metatag_token_sanitize'] = array(
    '#type' => 'checkbox',
    '#title' => t('Sanitize content during token replacement'),
    '#description' => t('If checked, will ensure that metatag value output is encoded and text filters are processed.'),
    '#default_value' => variable_get('metatag_token_sanitize', FALSE),
  );
  $form['lengths'] = array(
    '#type' => 'fieldset',
    '#title' => t('Maximum meta tag lengths'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#description' => t('Many meta tags may be shortened to a certain length. To reset to the default, leave the field blank. To keep the entire meta tag, regardless of length, set the value to zero (0). Note: the meta tag will be shortened <em>after</em> the tokens have been replaced, not before.'),
  );
  $info = metatag_get_info();
  $groups = $info['groups'];
  $tags = $info['tags'];
  foreach ($tags as $tag => $info) {
    if (isset($info['maxlength'])) {
      $default = $info['maxlength'];
      $var_name = 'metatag_maxlength_' . $tag;
      $title = $info['label'];
      if (!empty($info['group']) && isset($groups[$info['group']])) {
        $title = $groups[$info['group']]['label'] . ': ' . $title;
      }
      $form['lengths'][$var_name] = array(
        '#type' => 'textfield',
        '#title' => $title,
        '#default_value' => intval(variable_get($var_name, $default)),
      );
    }
  }

  // Extra submission logic.
  $form['#submit'][] = 'metatag_admin_settings_form_submit';
  return system_settings_form($form);
}