You are here

function nd_block_field_form in Node displays 6

Block field form.

Parameters

string $key The key of the field.:

array $field The field with title and code keys.:

1 string reference to 'nd_block_field_form'
nd_fields in includes/nd.fields.inc
Fields overview.

File

includes/nd.fields.inc, line 214
Manage fields.

Code

function nd_block_field_form($form_state, $key = '', $field = array()) {
  $form = array();
  if (empty($field)) {
    $field = array(
      'title' => '',
      'block' => '',
      'exclude' => array(),
      'type' => ND_FIELD_BLOCK,
    );
  }
  $form['block_identity'] = array(
    '#type' => 'fieldset',
    '#title' => empty($key) ? t('Add new block field') : t('Update block field'),
    '#collapsible' => empty($key) ? TRUE : FALSE,
    '#collapsed' => empty($key) ? TRUE : FALSE,
  );
  $form['block_identity']['block_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Field key'),
    '#description' => t('The machine-readable name of this field.'),
    '#required' => TRUE,
  );
  if (!empty($key)) {
    $form['block_identity']['block_key']['#disabled'] = TRUE;
    $form['block_identity']['block_key']['#value'] = $key;
    $form['block_identity']['block_key']['#description'] = t('The machine-readable name of this field. Note: you can not edit this field.');
  }
  $form['block_identity']['block_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Field title'),
    '#description' => t('The title to use when rendering the output and on the display administration screen.'),
    '#required' => TRUE,
    '#default_value' => $field['title'],
  );
  $ctypes = node_get_types('names');
  $form['block_identity']['block_exclude'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Field exclude'),
    '#options' => $ctypes,
    '#description' => t('Toggle content types which you don\'t want the field to appear in.'),
    '#default_value' => $field['exclude'],
  );
  $blocks = array();
  foreach (module_list() as $module) {
    $module_blocks = module_invoke($module, 'block', 'list');
    if ($module_blocks) {
      foreach ($module_blocks as $key => $info) {
        $blocks[ucfirst($module)][$module . '|' . $key] = $info['info'];
      }
    }
  }
  ksort($blocks);
  $form['block_identity']['block_block'] = array(
    '#type' => 'select',
    '#options' => $blocks,
    '#title' => t('Block'),
    '#required' => TRUE,
    '#default_value' => $field['block'],
  );
  $form['block_identity']['block_render'] = array(
    '#type' => 'select',
    '#options' => array(
      BLOCK_TEMPLATE => t('Render through block template'),
      BLOCK_TITLE_CONTENT => t('Show block title + content'),
      BLOCK_CONTENT => t('Show only block content'),
    ),
    '#title' => t('Block render'),
    '#required' => TRUE,
    '#default_value' => $field['render'],
  );
  $form['block_identity']['block_submit'] = array(
    '#type' => 'submit',
    '#submit' => array(
      'nd_block_field_form_submit',
    ),
    '#value' => t('Save block field'),
  );
  $form['#field_type'] = ND_FIELD_BLOCK;
  $form['#form_type'] = empty($key) ? 'insert' : 'update';
  return $form;
}