function _microdata_get_form_elements in Microdata 7
Form builder helper function.
Gets a form element setup to collect different parts of the mapping.
2 calls to _microdata_get_form_elements()
- microdata_get_bundle_type_mapping_form in ./
microdata.admin.inc - Form builder helper function.
- microdata_get_instance_mapping_form in ./
microdata.admin.inc - Form builder helper function.
File
- includes/
microdata.form_alter.inc, line 329 - Provides inline structured data using Microdata format.
Code
function _microdata_get_form_elements($element, $field_name, $mapping, $label = NULL) {
switch ($element) {
case 'itemprop':
if (empty($label)) {
$label = t('Field property(s)');
}
$itemtypes = array();
if (!empty($mapping['#itemtype'])) {
foreach ($mapping['#itemtype'] as $itemtype) {
// Change '/' to ';' (as recommended at http://us.php.net/urlencode)
// so the itemtype isn't recognized as a path by the browser.
$itemtypes[] = str_replace('/', ';', $itemtype);
}
}
else {
$itemtypes[] = 'empty';
}
return array(
'#type' => 'textfield',
'#title' => $label,
'#default_value' => empty($mapping[$field_name]['#itemprop']) ? '' : implode(', ', $mapping[$field_name]['#itemprop']),
'#description' => t('Comma-separated list. Example: !properties', array(
'!properties' => 'name, http://xmlns.com/foaf/0.1/name',
)),
'#autocomplete_path' => 'microdata_autocomplete/itemprop/' . urlencode(check_plain(implode(', ', $itemtypes))),
'#resizable' => FALSE,
);
case 'is_item':
return array(
'#type' => 'checkbox',
'#title' => t('Handle as an item in microdata'),
'#default_value' => isset($mapping['#is_item']) ? $mapping['#is_item'] : $mapping['#value_type'] == 'item',
);
case 'item_fieldset':
return array(
'#type' => 'fieldset',
'#title' => t('@label Item', array(
'@label' => $label,
)),
);
case 'itemtype':
if (empty($mapping[$field_name]['#entity_type'])) {
// The mapping passed in is either for the entity or for a field that
// has sub-properties.
if (empty($field_name)) {
$default_value = empty($mapping['#itemtype']) ? array() : implode(', ', $mapping['#itemtype']);
}
else {
$default_value = empty($mapping[$field_name]['#itemtype']) ? array() : implode(', ', $mapping[$field_name]['#itemtype']);
}
return array(
'#type' => 'textfield',
'#title' => 'Item Type',
'#default_value' => $default_value,
'#description' => t('For example, !types.', array(
'!types' => 'http://schema.org/Person',
)),
'#autocomplete_path' => 'microdata_autocomplete/itemtype',
'#resizable' => FALSE,
);
}
else {
return array(
'#markup' => t("This field's value is a <em>{$mapping[$field_name]['#entity_type']}</em> entity. You will need to go to the entity's configuration page to edit its microdata mapping."),
);
}
}
}