/** * Overrides EntityInlineEntityFormController::entityForm(). * * Copied from fieldable_panels_panes_entity_edit_form(). */ public function entityForm($entity_form, &$form_state) { // Make the other form items dependent upon it. ctools_include('dependent'); ctools_add_js('dependent'); $entity = $entity_form['#entity']; $entity_type = 'fieldable_panels_pane'; list(, , $bundle) = entity_extract_ids($entity_type, $entity); // Map these properties for entity translations. $entity_form['#entity_type'] = array('#type' => 'value', '#value' => $entity->bundle); $form_state['fieldable_panels_pane'] = $entity_form['#entity']; $entity_form['title'] = array('#type' => 'textfield', '#title' => t('Title'), '#default_value' => $entity->title, '#weight' => -10); $entity_form['language'] = array('#type' => 'value', '#value' => $entity->language); $entity_form['link'] = array('#weight' => -10); $entity_form['link']['link'] = array('#title' => t('Make title a link'), '#type' => 'checkbox', '#default_value' => $entity->link, '#description' => t('Check here to make the title link to another page.'), '#id' => 'edit-link'); $entity_form['link']['path'] = array('#type' => 'textfield', '#title' => t('Path'), '#description' => t('The path for this link. This can be an internal Drupal path such as %add-node or an external URL such as %drupal. Enter %front to link to the front page.', array('%front' => '<front>', '%add-node' => 'node/add', '%drupal' => 'http://drupal.org')), '#dependency' => array('edit-link' => array(1)), '#default_value' => $entity->path); $entity_form['reusable'] = array('#weight' => 10); $entity_form['revision'] = array('#weight' => 11); if (empty($entity->fpid)) { $entity_form['revision']['#access'] = FALSE; } $entity_form['reusable']['reusable'] = array('#type' => 'checkbox', '#title' => t('Make this entity reusable'), '#default_value' => $entity->reusable, '#id' => 'edit-reusable'); $entity_form['reusable']['category'] = array('#type' => 'textfield', '#title' => t('Category'), '#description' => t('The category this content will appear in the "Add content" modal. If left blank the category will be "Miscellaneous".'), '#dependency' => array('edit-reusable' => array(1)), '#default_value' => $entity->category); $entity_form['reusable']['admin_title'] = array('#type' => 'textfield', '#title' => t('Administrative title'), '#description' => t('The name this content will appear in the "Add content" modal.'), '#dependency' => array('edit-reusable' => array(1)), '#default_value' => $entity->admin_title); $entity_form['reusable']['admin_description'] = array('#type' => 'textarea', '#title' => t('Administrative description'), '#description' => t('A description of what this content is, does or is for, for administrative use.'), '#dependency' => array('edit-reusable' => array(1)), '#default_value' => $entity->admin_description); $entity_form['revision']['revision'] = array('#type' => 'checkbox', '#title' => t('Create new revision'), '#default_value' => 1, '#id' => 'edit-revision'); if (!user_access('administer fieldable panels panes') || empty($entity->fpid) || $entity->vid != $entity->current_vid) { $form['revision']['revision']['#disabled'] = TRUE; $form['revision']['revision']['#value'] = TRUE; } $entity_form['revision']['log'] = array('#type' => 'textarea', '#title' => t('Log message'), '#description' => t('Provide an explanation of the changes you are making. This will help other authors understand your motivations.'), '#dependency' => array('edit-revision' => array(1)), '#default_value' => ''); $langcode = entity_language('fieldable_panels_pane', $entity); field_attach_form('fieldable_panels_pane', $entity, $entity_form, $form_state, $langcode); // _field_extra_fields_pre_render() doesn't execute properly, so manually // set the weights. $extra_fields = field_info_extra_fields($entity_type, $bundle, 'form'); foreach ($extra_fields as $name => $settings) { if (isset($entity_form[$name])) { $entity_form[$name]['#weight'] = $settings['weight']; } } return $entity_form; }
protected function getExtraFieldsDisplay($entityType, $bundle) { // Resets a webform's static cache to ensure to get the "webform" extra // field information. The webform features may have been enabled for the // current content type after the static cache has been built. drupal_static_reset('webform_node_types'); return field_info_extra_fields($entityType, $bundle, 'display'); }
function cubert_field_attach_view_alter(&$output, $context) { if (!empty($context['entity']) && !empty($context['entity']->type) && $context['entity']->type == 'project_issue') { global $user; // Some fields can only be edited by admin users $admin_fields = array('field_issue_priority', 'field_issue_component', 'field_task_type', 'field_issue_status', 'milestone_fieldset', 'field_issue_assigned', 'field_due_date', 'time_tracker', 'time_estimate'); // We proceed only on nodes. if ($context['entity_type'] != 'node' || $context['view_mode'] != 'full') { return; } $node = $context['entity']; $is_admin = user_access('administer projects'); $can_edit = node_access('update', $node); // Load all instances of the fields for the node. $instances = _field_invoke_get_instances('node', $node->type, array('default' => TRUE, 'deleted' => FALSE)); // Load extra fields $extra_fields = field_info_extra_fields('node', $node->type, 'form'); if (!empty($extra_fields['title'])) { $title['label'] = 'Title'; $instances['title'] = $title; } foreach ($instances as $field_name => $instance) { // Only work with fields that we display or that have empty values $access = !empty($output[$field_name]['#access']) ? $output[$field_name]['#access'] : FALSE; if ($field_name == 'title') { $access = TRUE; } $value_empty = FALSE; if (!empty($node->{$field_name}[LANGUAGE_NONE])) { if (array_key_exists('value', $node->{$field_name}[LANGUAGE_NONE][0])) { $value_empty = empty($node->{$field_name}[LANGUAGE_NONE][0]['value']); } } if ($access || empty($node->{$field_name}) || $value_empty) { // Set content for fields if they are empty. if ((empty($node->{$field_name}) || $value_empty) && $field_name != 'title') { $display = field_get_display($instance, 'full', $node); // Do not add field that is hidden in current display. if ($display['type'] == 'hidden') { continue; } // Load field settings. $field = field_info_field($field_name); // Set output for field. $output[$field_name] = array('#theme' => 'field', '#title' => $instance['label'], '#label_display' => 'above', '#field_type' => $field['type'], '#field_name' => $field_name, '#bundle' => $node->type, '#object' => $node, '#items' => array(array()), '#entity_type' => 'node', '#weight' => $display['weight'], '#prefix' => '<div class="mode-read">', '#suffix' => '</div>', 0 => array('#markup' => 'N/A')); } // Embed the editable widget on the page if user can edit - // Normal users: has node access and the field is not an admin-only field // Admin users: has node access, field is an admin-only field, and user is admin $is_admin_field = in_array($field_name, $admin_fields); if ($can_edit && !$is_admin_field || $can_edit && $is_admin_field && $is_admin) { $form = array('#type' => 'form', '#attributes' => array('data-edit' => $field_name, 'class' => array('field', 'mode-edit'))); $form_state = array(); $values = field_get_items('node', $node, $field_name); $field_val = ''; if (!empty($values[0]['value'])) { $field_val = $values[0]['value']; } if (!empty($values[0]['target_id'])) { $field_val = $values[0]['target_id']; } // A few fields are handled a bit differently - create their form elements manually if (in_array($field_name, array('title', 'body', 'field_project'))) { if ($field_name == 'title') { $form['title'][LANGUAGE_NONE][0] = array('#type' => 'textfield', '#title' => t('Title'), '#default_value' => $node->title, '#value' => $node->title, '#required' => TRUE); } if ($field_name == 'body') { $form['body'][LANGUAGE_NONE][0] = array('#type' => 'textarea', '#title' => t('Body'), '#format' => 'full_html', '#value' => $field_val, '#rows' => 25); } // Use a select rather than the standard autocomplete if ($field_name == 'field_project') { drupal_add_library('system', 'drupal.ajax'); $projects = node_load_multiple(array(), array('type' => 'project')); $project_options = array(); $field_val_title = ''; foreach ($projects as $project) { // Only include project if user has access to it if (node_access('view', $project)) { $project_options[$project->nid] = $project->title; } if ($project->nid == $field_value) { $field_val_title = $project->title; } } // Show dropdown if the Project value is in the list of allowed options if (array_key_exists($field_val, $project_options)) { $form['field_project'][LANGUAGE_NONE][0] = array('#type' => 'select', '#title' => t('Project'), '#options' => $project_options, '#default_value' => $field_val, '#required' => TRUE, '#chosen' => FALSE, '#attributes' => array('class' => array('select-project'))); } else { $form['field_project'][LANGUAGE_NONE][0] = array('#type' => 'hidden', '#value' => $field_val); $form['project_readonly'] = array('#markup' => $field_val_title); } } } else { cubert_attach_form($field_name, 'node', $node->type, $node, $form, $form_state, LANGUAGE_NONE); $form[$field_name][LANGUAGE_NONE]['#value'] = $field_val; $form[$field_name][LANGUAGE_NONE]['#default_value'] = $field_val; if (!empty($form[$field_name][LANGUAGE_NONE][0]['value'])) { $form[$field_name][LANGUAGE_NONE][0]['value']['#value'] = $field_val; } if ($field_name == 'field_issue_component') { $form[$field_name][LANGUAGE_NONE]['#attributes']['class'] = array('select-dept'); } } if ($field_name == 'field_due_date') { $form[$field_name][LANGUAGE_NONE][0] = array('#type' => 'textfield', '#title' => t('Due Date'), '#value' => $field_val); } // Hide the default label and add a Bootstrap-wrapped label instead $form[$field_name]['#label_display'] = 'hidden'; $form[$field_name]['#prefix'] = '<div class="field-label"><label>' . $instance['label'] . '</label></div><div class="field-items">'; $form[$field_name]['#suffix'] = '</div>'; $form[$field_name][LANGUAGE_NONE]['#attributes']['class'][] = 'form-control'; $form[$field_name][LANGUAGE_NONE][0]['#attributes']['class'][] = 'form-control'; // Add classes to Time Estimate field if ($field_name == 'time_estimate') { $form[$field_name][LANGUAGE_NONE][0]['value']['#attributes']['class'][] = 'form-control'; $form[$field_name][LANGUAGE_NONE][0]['value']['#attributes']['class'][] = 'textbox-med'; } $output[$field_name]['edit_form'] = $form; } } } } }