Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* vim: set tabstop=2 shiftwidth=2: */
- function view_field_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {
- //dsm(array('func' => 'view_field_field_attach_form', 'entity_type' => $entity_type, 'entity' => $entity, 'form' => $form, 'form_state' => $form_state, 'langcode' => $langcode));
- foreach (field_info_instances($entity_type, $entity->type) as $field_name => $instance) {
- if (!field_access('edit', $instance, $entity_type, $entity) && field_access('view', $instance, $entity_type, $entity)) {
- // Add state for field to form_state
- $parents = $form['#parents'];
- $items = field_get_items($entity_type, $entity, $field_name, $langcode);
- field_form_set_state($parents, $field_name, $langcode, $form_state, array(
- 'field' => field_info_field($field_name),
- 'instance' => $instance,
- 'items_count' => count($items),
- 'array_parents' => array(),
- 'errors' => array(),
- ));
- $form[$field_name]['#type'] = 'container';
- $form[$field_name]['#weight'] = $instance['widget']['weight'];
- $form[$field_name][$langcode] = field_view_field($entity_type, $entity, $field_name, 'form', $langcode);
- }
- }
- }
- function view_field_entity_info_alter(&$entity_info) {
- $entity_info['node']['view modes']['form'] = array(
- 'label' => 'Form',
- 'custom settings' => FALSE,
- );
- }
Add Comment
Please, Sign In to add comment