You are here

function _content_admin_field in Content Construction Kit (CCK) 6

Same name and namespace in other branches
  1. 5 content_admin.inc \_content_admin_field()

Menu callback; presents the field editing page.

5 string references to '_content_admin_field'
content_copy_export in modules/content_copy/content_copy.module
Process the export, get field admin forms for all requested fields and save the form values as formatted text.
content_copy_form_alter in modules/content_copy/content_copy.module
Implementation of hook_form_alter(). Intervene to run form through macro when doing export
content_menu in ./content.module
Implementation of hook_menu().
fieldgroup_form_alter in modules/fieldgroup/fieldgroup.module
optionwidgets_form_alter in modules/optionwidgets/optionwidgets.module
@file Defines selection, check box and radio button widgets for text and numeric fields.

File

includes/content.admin.inc, line 649
Administrative interface for content type creation.

Code

function _content_admin_field(&$form_state, $type_name, $field_name) {
  $output = '';
  $type = content_types($type_name);
  $field = $type['fields'][$field_name];
  $field_types = _content_field_types();
  $field_type = $field_types[$field['type']];
  $widget_types = _content_widget_types();
  $widget_type = $widget_types[$field['widget']['type']];
  drupal_set_title(isset($field['widget']['label']) ? $field['widget']['label'] : $field['field_name']);
  $form = array();
  $form['widget'] = array(
    '#type' => 'fieldset',
    '#title' => t('%type settings', array(
      '%type' => $type['name'],
    )),
    '#description' => t('These settings apply only to the %field field as it appears in the %type content type.', array(
      '%field' => $field['widget']['label'],
      '%type' => $type['name'],
    )),
  );
  $options = array();
  foreach ($widget_types as $possible_widget_name => $possible_widget_type) {
    if (in_array($field['type'], $possible_widget_type['field types'])) {
      $options[$possible_widget_name] = $possible_widget_type['label'];
    }
  }
  if (count($options) == 1) {
    $key = array_keys($options);
    $default_widget = array_pop($key);
  }
  $form['widget']['widget_type'] = array(
    '#type' => 'radios',
    '#title' => t('Widget'),
    '#options' => $options,
    '#default_value' => $field['widget']['type'] ? $field['widget']['type'] : $default_widget,
    '#required' => TRUE,
  );
  $form['widget']['label'] = array(
    '#type' => 'textfield',
    '#title' => t('Label'),
    '#default_value' => $field['widget']['label'],
    '#required' => TRUE,
  );
  $form['widget']['weight'] = array(
    '#type' => 'hidden',
    '#default_value' => $field['widget']['weight'],
  );
  $additions = module_invoke($widget_type['module'], 'widget_settings', 'form', $field['widget']);
  if (is_array($additions)) {
    $form['widget'] = array_merge($form['widget'], $additions);
  }
  $form['widget']['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Help text'),
    '#default_value' => $field['widget']['description'],
    '#rows' => 5,
    '#description' => t('Instructions to present to the user below this field on the editing form.'),
    '#required' => FALSE,
  );

  // Add handling for default value if not provided by field.
  if (content_callback('widget', 'default value', $field) == CONTENT_CALLBACK_DEFAULT) {
    $form['widget']['default_value_fieldset'] = array(
      '#type' => 'fieldset',
      '#title' => t('Default value'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );

    // Default value widget.
    $default_value = isset($field['widget']['default_value']) ? $field['widget']['default_value'] : array();
    $widget_form = array(
      '#node' => (object) array(
        'type' => $type_name,
      ),
    );
    $widget_form_state = array(
      'values' => array(
        $field['field_name'] => $default_value,
      ),
    );

    // Make sure the default value is not a required field.
    $widget_field = $field;
    $widget_field['required'] = FALSE;
    module_load_include('inc', 'content', 'includes/content.node_form');
    $form_element = content_field_form($widget_form, $widget_form_state, $widget_field, 0);
    $form['widget']['default_value_fieldset']['default_value_widget'] = $form_element;
    $form['widget']['default_value_fieldset']['default_value_widget']['#tree'] = TRUE;

    // Set up form info that the default value widget will need to find in the form.
    $form['#field_info'] = array(
      $widget_field['field_name'] => $widget_field,
    );

    // Advanced : PHP code.
    $form['widget']['default_value_fieldset']['advanced_options'] = array(
      '#type' => 'fieldset',
      '#title' => t('PHP code'),
      '#collapsible' => TRUE,
      '#collapsed' => empty($field['widget']['default_value_php']),
    );
    $db_info = content_database_info($field);
    $columns = array_keys($db_info['columns']);
    foreach ($columns as $key => $column) {
      $columns[$key] = "'{$column}' => value for {$column}";
    }
    $sample = 'array(
  0 => array(' . implode(', ', $columns) . '),
  // You\'ll usually want to stop here. Provide more values
  // if you want your \'default value\' to be multi-valued :
  1 => array(' . implode(', ', $columns) . '),
  2 => ...
);';
    $form['widget']['default_value_fieldset']['advanced_options']['default_value_php'] = array(
      '#type' => 'textarea',
      '#title' => t('Code'),
      '#default_value' => isset($field['widget']['default_value_php']) ? $field['widget']['default_value_php'] : '',
      '#rows' => 6,
      '#tree' => TRUE,
      '#description' => t("Advanced usage only: PHP code that returns a default value. Should not include &lt;?php ?&gt; delimiters. If this field is filled out, the value returned by this code will override any value specified above. Expected format :<pre>!sample</pre>Using !link_devel's 'devel load' tab on a %type content page might help you figure out the expected format.", array(
        '!sample' => $sample,
        '!link_devel' => l('devel.module', 'http://www.drupal.org/project/devel'),
        '%type' => $type_name,
      )),
    );
  }
  $form['field'] = array(
    '#type' => 'fieldset',
    '#title' => t('Global settings'),
    '#description' => t('These settings apply to the %field field in every content type in which it appears.', array(
      '%field' => $field['widget']['label'],
    )),
  );
  $form['field']['required'] = array(
    '#type' => 'checkbox',
    '#title' => t('Required'),
    '#default_value' => $field['required'],
  );
  $form['field']['multiple'] = array(
    '#type' => 'select',
    '#title' => t('Number of values'),
    '#options' => array(
      1 => t('Unlimited'),
      0 => 1,
    ) + drupal_map_assoc(range(2, 10)),
    '#default_value' => $field['multiple'],
    '#description' => t("Select a specific number of values for this field, or 'Unlimited' to provide an 'Add more' button so the users can add as many values as they like.") . '<br/><strong>' . t('Warning! Changing this setting after data has been created could result in the loss of data!') . '</strong>',
  );
  $form['field']['previous_field'] = array(
    '#type' => 'hidden',
    '#value' => serialize($field),
  );
  $additions = module_invoke($field_type['module'], 'field_settings', 'form', $field);
  if (is_array($additions)) {
    $form['field'] = array_merge($form['field'], $additions);
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save field settings'),
  );
  $form['type_name'] = array(
    '#type' => 'value',
    '#value' => $type_name,
  );
  $form['field_name'] = array(
    '#type' => 'value',
    '#value' => $field_name,
  );
  $form['type'] = array(
    '#type' => 'value',
    '#value' => $field['type'],
  );
  $form['module'] = array(
    '#type' => 'value',
    '#value' => $field['module'],
  );
  $form['widget_module'] = array(
    '#type' => 'value',
    '#value' => $field['widget']['module'],
  );
  $form['columns'] = array(
    '#type' => 'value',
    '#value' => $field['columns'],
  );
  return $form;
}