You are here

function microdata_get_bundle_type_mapping_form in Microdata 7

Form builder helper function.

Creates the bundle mapping form to be added to forms like node_type. This is also used by microdata_bundle_mapping_form to add the bundle type settings to Microdata's custom UI.

3 calls to microdata_get_bundle_type_mapping_form()
microdata_bundle_mapping_form in ./microdata.admin.inc
Form builder helper function.
microdata_form_node_type_form_alter in includes/microdata.form_alter.inc
Implements hook_form_FORM_ID_alter().
microdata_form_taxonomy_form_vocabulary_alter in includes/microdata.form_alter.inc
Implements hook_form_FORMID_alter().

File

./microdata.admin.inc, line 176
Microdata administration and module settings UI.

Code

function microdata_get_bundle_type_mapping_form($mapping, $entity_type, $bundle_type) {
  $form_element['itemtype'] = _microdata_get_form_elements('itemtype', '', $mapping);
  $form_element['is_item'] = array(
    '#type' => 'checkbox',
    '#title' => t('Handle as an item in microdata'),
    '#default_value' => isset($mapping['#is_item']) ? $mapping['#is_item'] : $mapping['#value_type'] == 'item',
  );
  $form_element['itemid_settings'] = array(
    '#type' => 'container',
    '#states' => array(
      'visible' => array(
        ':input[name="microdata[' . $entity_type . '][is_item]"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );

  // Get the default itemid token for known entity types.
  $default_token = '';
  switch ($entity_type) {
    case 'node':
      $default_token = '[node:url]';
      break;
    case 'taxonomy_term':
      $default_token = '[term:url]';
      break;
    case 'user':
      $default_token = '[user:url]';
      break;
    case 'taxonomy_vocabulary':
      $default_token = '[comment:url]';
      break;
  }
  $form_element['itemid_settings']['itemid_token'] = array(
    '#type' => 'textfield',
    '#title' => t('Token to use for itemid'),
    '#default_value' => isset($mapping['#itemid_token']) ? $mapping['#itemid_token'] : $default_token,
  );
  $form_element['itemid_settings']['use_schema_url'] = array(
    '#type' => 'checkbox',
    '#title' => t('Output schema:url'),
    '#default_value' => isset($mapping['#use_schema_url']) ? $mapping['#use_schema_url'] : FALSE,
    '#description' => t('This can be helpful for getting Rich Snippets, e.g. for Events. The relative URI of the entity will be used.'),
  );
  $form_element['title_itemprop'] = _microdata_get_form_elements('itemprop', 'title', $mapping, t('Itemprop(s) for title field'));
  $form_element['bundle_type'] = array(
    '#type' => 'hidden',
    '#default_value' => $bundle_type,
  );
  if ($entity_type == 'taxonomy_term') {

    // Additional options that are unique to terms.
    $form_element['description_itemprop'] = _microdata_get_form_elements('itemprop', 'description', $mapping, t('Property for term description'));
    $form_element['url_itemprop'] = _microdata_get_form_elements('itemprop', 'url', $mapping, t("Property for term's url on this site (i.e. http://example.com/taxonomy/term/1)"));
  }
  return $form_element;
}