Guest User

Untitled

a guest
Feb 18th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.39 KB | None | 0 0
  1. <?php
  2. /* vim: set tabstop=2 shiftwidth=2: */
  3.  
  4. function view_field_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {
  5.   //dsm(array('func' => 'view_field_field_attach_form', 'entity_type' => $entity_type, 'entity' => $entity, 'form' => $form, 'form_state' => $form_state, 'langcode' => $langcode));
  6.   foreach (field_info_instances($entity_type, $entity->type) as $field_name => $instance) {
  7.     if (!field_access('edit', $instance, $entity_type, $entity) && field_access('view', $instance, $entity_type, $entity)) {
  8.       // Add state for field to form_state
  9.       $parents = $form['#parents'];
  10.       $items = field_get_items($entity_type, $entity, $field_name, $langcode);
  11.       field_form_set_state($parents, $field_name, $langcode, $form_state, array(
  12.         'field' => field_info_field($field_name),
  13.         'instance' => $instance,
  14.         'items_count' => count($items),
  15.         'array_parents' => array(),
  16.         'errors' => array(),
  17.       ));
  18.  
  19.       $form[$field_name]['#type'] = 'container';
  20.       $form[$field_name]['#weight'] = $instance['widget']['weight'];      
  21.       $form[$field_name][$langcode] = field_view_field($entity_type, $entity, $field_name, 'form', $langcode);
  22.     }
  23.   }
  24. }
  25.  
  26. function view_field_entity_info_alter(&$entity_info) {
  27.   $entity_info['node']['view modes']['form'] = array(
  28.     'label' => 'Form',
  29.     'custom settings' => FALSE,
  30.   );
  31. }
Add Comment
Please, Sign In to add comment