You are here

function ds_block_field_form in Display Suite 6.2

Same name and namespace in other branches
  1. 6.3 includes/ds.fields.inc \ds_block_field_form()
  2. 6 includes/ds.fields.inc \ds_block_field_form()

Block field form.

Parameters

string $module The module the field is for.:

array $all_fields All fields for this module.:

string $object The object name (ie node, user, comment).:

string $key The key of the field.:

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

1 string reference to 'ds_block_field_form'
ds_fields in includes/ds.fields.inc
Fields overview.

File

includes/ds.fields.inc, line 503
Manage fields.

Code

function ds_block_field_form($form_state, $module, $all_fields, $object = '', $key = '', $field = array()) {
  $form = array();
  if (empty($field)) {
    $field = array(
      'title' => '',
      'exclude' => array(),
      'type' => DS_FIELD_TYPE_BLOCK,
      'status' => DS_FIELD_STATUS_CUSTOM,
      'properties' => array(
        'css-class' => '',
        'block' => '',
        'render' => DS_BLOCK_TEMPLATE,
      ),
    );
  }
  $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'],
  );
  $form['block_identity']['block_class'] = array(
    '#type' => 'textfield',
    '#title' => t('Field class'),
    '#description' => t('The classes you want to add to this field. This will replace the automatic class that Display Suite generates.'),
    '#default_value' => isset($field['properties']['css-class']) ? $field['properties']['css-class'] : '',
  );
  $api_info = ds_api_info($module);
  if (isset($api_info['types']) && count($api_info['types']()) > 1) {
    $types = array();
    foreach ($api_info['types']() as $tkey => $type) {

      // Views displays is special case.
      if ($module == 'vd') {
        $global_exclude = variable_get($module . '_type_' . $tkey, FALSE);
        if ($global_exclude == TRUE) {
          continue;
        }
      }
      $types[$tkey] = check_plain($type->name);
    }
    $form['block_identity']['block_exclude'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Field exclude'),
      '#options' => $types,
      '#default_value' => $field['exclude'],
      '#attributes' => array(
        'class' => 'exclude-types',
      ),
    );
    $form['block_identity']['block_exclude_all'] = array(
      '#type' => 'checkbox',
      '#title' => t('Select all'),
      '#description' => t('Toggle types which you don\'t want the field to appear in.'),
      '#attributes' => array(
        'class' => 'select-all',
      ),
    );
  }
  else {
    $form['code_identity']['block_exclude'] = array(
      '#type' => 'value',
      '#value' => array(),
    );
  }
  $blocks = array();
  foreach (module_list() as $drupal_module) {
    $module_blocks = module_invoke($drupal_module, 'block', 'list');
    if ($module_blocks) {
      foreach ($module_blocks as $module_key => $info) {
        $blocks[ucfirst($drupal_module)][$drupal_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['properties']['block'],
  );
  $form['block_identity']['block_render'] = array(
    '#type' => 'select',
    '#options' => array(
      DS_BLOCK_TEMPLATE => t('Render through block template'),
      DS_BLOCK_TITLE_CONTENT => t('Show block title + content'),
      DS_BLOCK_CONTENT => t('Show only block content'),
    ),
    '#title' => t('Block render'),
    '#required' => TRUE,
    '#default_value' => $field['properties']['render'],
  );
  $form['block_identity']['block_submit'] = array(
    '#type' => 'submit',
    '#submit' => array(
      'ds_block_field_form_submit',
    ),
    '#value' => t('Save block field'),
  );
  $form['#field_status'] = $field['status'] == DS_FIELD_STATUS_DEFAULT ? DS_FIELD_STATUS_OVERRIDDEN : ($field['type'] == DS_FIELD_STATUS_OVERRIDDEN ? DS_FIELD_STATUS_OVERRIDDEN : DS_FIELD_STATUS_CUSTOM);
  $form['#form_type'] = empty($key) ? 'insert' : 'update';
  $form['#module'] = $module;
  $form['#all_fields'] = $all_fields;
  return $form;
}