function power_menu_add_fields_entity_fields in Power Menu 7.2
Add the power menu field entity to the given form.
2 calls to power_menu_add_fields_entity_fields()
- power_menu_form_menu_edit_item_alter in ./
power_menu.module - Implements hook_form_ID_alter().
- power_menu_form_menu_overview_form_alter in ./
power_menu.module - Implements hook_form_ID_alter().
File
- ./
power_menu.module, line 534
Code
function power_menu_add_fields_entity_fields($menu_name, $mlid, &$form, &$form_state) {
// Create bundle name for the given menu name
$bundle_name = power_menu_create_machine_name($menu_name);
// Check is this field selected for menu fields
$selected_menus = variable_get('power_menu_fields_menus', array());
// Check is this menu selected for fieldable
if (in_array($menu_name, $selected_menus)) {
$form['#submit'][] = 'power_menu_form_menu_edit_fields_submit';
$form['#validate'][] = 'power_menu_form_menu_edit_fields_validate';
// Add Power Menu fields
$form['power_menu']['fields'] = array(
'#type' => 'fieldset',
'#title' => t('Power Menu fields'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#tree' => TRUE,
'#parents' => array(
'power_menu',
'fields',
),
);
// Load entity id for this menu link
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'power_menu_fields')
->propertyCondition('mlid', $mlid)
->propertyCondition('menu_name', $bundle_name);
$result = $query
->execute();
// Is no entity found, create a new
if (empty($result)) {
$entity = entity_create('power_menu_fields', array(
'menu_name' => $bundle_name,
'mlid' => $mlid,
));
}
else {
$entity_nid = array_keys($result['power_menu_fields']);
$entity = entity_load('power_menu_fields', $entity_nid);
$entity = reset($entity);
}
// Set the correct parents for the attached field values, because they added to a fieldset
$form['#parents'] = array(
'power_menu',
'fields',
);
// Add entity fields
field_attach_form('power_menu_fields', $entity, $form['power_menu']['fields'], $form_state);
// Add entity to form
$form['power_menu']['fields']['entity'] = array(
'#type' => 'value',
'#value' => $entity,
);
}
}