You are here

function metatags_quick_admin_settings in Meta tags quick 7.2

Same name and namespace in other branches
  1. 8.3 metatags_quick.admin.inc \metatags_quick_admin_settings()
  2. 7 metatags_quick.admin.inc \metatags_quick_admin_settings()

General settings form

Return value

renderable array

1 string reference to 'metatags_quick_admin_settings'
metatags_quick_menu in ./metatags_quick.module
Implements hook_menu().

File

./metatags_quick.admin.inc, line 6

Code

function metatags_quick_admin_settings() {
  $current_settings = variable_get('metatags_quick_settings', _metatags_quick_settings_default());
  $module_path = drupal_get_path('module', 'metatags_quick');
  $fields = field_info_fields();
  $metatags_found = FALSE;
  include_once $module_path . '/known_tags.inc';
  $known_tags = _metatags_quick_known_fields();
  $form['global'] = array(
    '#type' => 'fieldset',
    '#title' => t('Global settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  foreach ($fields as $key => $field) {
    if ($field['module'] != 'metatags_quick') {
      continue;
    }
    $metatags_found = TRUE;
  }
  if (!$metatags_found) {
    $form['global']['basic_init'] = array(
      '#markup' => t('No meta tags found in your installation') . '<br/>',
    );
  }
  $form['global']['use_path_based'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use path-based meta tags'),
    '#default_value' => variable_get('metatags_quick_use_path_based', 1),
    '#return_value' => 1,
  );
  $form['global']['remove_tab'] = array(
    '#type' => 'checkbox',
    '#title' => t('Hide Path-based Metatags tab'),
    '#default_value' => variable_get('metatags_quick_remove_tab', 0),
  );
  $form['global']['default_field_length'] = array(
    '#type' => 'textfield',
    '#title' => t('Default maximum length'),
    '#description' => t('Default maximum length for the meta tag fields'),
    '#default_value' => variable_get('metatags_quick_default_field_length', 255),
  );
  $form['global']['show_admin_hint'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show entities/bundles hint in admin'),
    '#default_value' => variable_get('metatags_quick_show_admin_hint', 1),
  );
  $form['standard_tags'] = array(
    '#type' => 'fieldset',
    '#title' => t('Create and attach'),
    '#description' => t('The following meta tags are known to the module and can be created automatically. However, you are not limited to this list and can define tags of your own using the Fields UI.'),
    '#collapsible' => TRUE,
    '#attached' => array(
      'js' => array(
        $module_path . '/js/admin.js',
      ),
      'css' => array(
        $module_path . '/css/admin.css',
      ),
    ),
  );
  if (variable_get('metatags_quick_show_admin_hint', 1)) {
    $form['standard_tags']['hint'] = array(
      '#prefix' => '<div class="messages status">',
      '#markup' => t('<strong>Hint</strong>: press on entity type name to edit individual bundles settings (you can hide this hint in global settings).'),
      '#suffix' => '</div>',
    );
  }
  $field_instances = field_info_instances();

  // Build the sortable table header.
  $header = array(
    'title' => array(
      'data' => t('Bundle/entity'),
    ),
  );
  foreach ($known_tags as $name => $tag) {
    $header[$name] = $tag['title'];
  }

  //$header['_select_all'] = t('Select all');
  foreach (field_info_bundles() as $entity_type => $bundles) {
    $entity_info = entity_get_info($entity_type);
    if (!$entity_info['fieldable']) {
      continue;
    }
    $options[$entity_type]['data'] = array(
      'title' => array(
        'class' => array(
          'entity_type_collapsible',
          'entity_type_collapsed',
          "entity_name_{$entity_type}",
        ),
        'data' => check_plain($entity_info['label']),
      ),
    );
    foreach ($known_tags as $name => $tag) {
      $bundle_workable[$name] = FALSE;
      $options[$entity_type]['data'][$name] = array(
        'data' => array(
          '#type' => 'checkbox',
          '#attributes' => array(
            'class' => array(
              'cb_bundle_parent',
              "cb_bundle_name_{$entity_type}_{$name}",
            ),
          ),
          '#return_value' => 1,
          '#checked' => FALSE,
        ),
      );
    }

    /*$options[$entity_type]['data']['_select_all'] = array(
        'data' => array(
        '#type' => 'checkbox',
        '#return_value' => 1,
        '#checked' => FALSE,
        ),
      );*/

    // How do we mark that specific meta is already attached to bundle
    $checked_markup = array(
      '#markup' => theme('image', array(
        'path' => 'misc/watchdog-ok.png',
        'width' => 18,
        'height' => 18,
        'alt' => 'ok',
        'title' => 'ok',
      )),
    );
    foreach ($bundles as $key => $bundle) {

      // Which meta tags are set for this bundle?
      $meta_set = array();
      foreach ($field_instances[$entity_type][$key] as $bundle_instance) {
        if ($bundle_instance['widget']['module'] == 'metatags_quick') {
          $field_info = field_info_field_by_id($bundle_instance['field_id']);
          $meta_set[$field_info['settings']['meta_name']] = 1;
        }
      }
      $options[$entity_type . '_' . $key] = array(
        'class' => array(
          'entity_type_children',
          "entity_child_{$entity_type}",
        ),
        'style' => 'display: none',
        'data' => array(
          'title' => array(
            'class' => array(
              'entity_type_child_title',
            ),
            'data' => $bundle['label'],
          ),
        ),
      );
      foreach ($known_tags as $name => $tag) {
        $tag_name = isset($tag['meta_name']) ? $tag['meta_name'] : $name;
        if (empty($meta_set[$tag_name])) {

          // Mark parent bundle as workable - display checkbox.
          $bundle_workable[$name] = TRUE;
          $options[$entity_type . '_' . $key]['data'][$name] = array(
            'data' => array(
              '#name' => $entity_type . '[' . $key . '][' . $name . ']',
              '#type' => 'checkbox',
              '#attributes' => array(
                'class' => array(
                  'cb_bundle_child',
                  "cb_child_{$entity_type}_{$name}",
                ),
              ),
              '#return_value' => 1,
              '#checked' => FALSE,
            ),
          );
        }
        else {
          $options[$entity_type . '_' . $key]['data'][$name]['data'] = $checked_markup;
        }
      }

      /*$options[$entity_type . '_' . $key]['data']['_select_all']['data'] = array(
          '#type' => 'checkbox',
          '#return_value' => 1,
          '#checked' => FALSE,
        );*/
    }

    // Now check if we have completely set bundles
    foreach ($known_tags as $name => $tag) {
      if (!$bundle_workable[$name]) {
        $options[$entity_type]['data'][$name]['data'] = $checked_markup;
      }
    }
  }
  $form['standard_tags']['existing'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $options,
    '#empty' => t('No content available.'),
  );
  $form['standard_tags']['basic_init_op'] = array(
    '#type' => 'submit',
    '#value' => t('Attach'),
  );
  $form['op'] = array(
    '#value' => t('Submit'),
    '#type' => 'submit',
  );
  return $form;
}