You are here

function fieldblock_field_display_submit in Field as Block 7

Same name and namespace in other branches
  1. 8 fieldblock.module \fieldblock_field_display_submit()

Form submit handler for field_ui_display_overview_form. Saves a single variable for each entity + bundle + view mode combination if a field has been made available as block. Having separate variables makes the configuration more flexible for exporting with strongarm and features.

1 string reference to 'fieldblock_field_display_submit'
fieldblock_form_field_ui_display_overview_form_alter in ./fieldblock.module
Implements hook_form_alter(). Adds a column to the "display fields" table-form, with a checkbox for each field.

File

./fieldblock.module, line 66
Allow fields to be rendered in blocks.

Code

function fieldblock_field_display_submit($form, &$form_state) {
  $entity_type = $form['#entity_type'];
  $bundle = $form['#bundle'];
  $view_mode = $form['#view_mode'];
  $variable_name = 'fieldblock-' . $entity_type . '-' . $bundle . '-' . $view_mode;
  $settings = array();
  foreach ($form_state['values']['fields'] as $field_name => $field) {
    if (!empty($field['fieldblock'])) {
      $settings[$field_name] = $form['fields'][$field_name]['human_name']['#markup'];
    }
  }
  if (empty($settings)) {

    // This variable may have existed before, so let's clean up a little.
    variable_del($variable_name);
  }
  else {
    variable_set($variable_name, $settings);
    drupal_set_message(t('One or more fields have been made available as block. Do not forget to assign the block(s) to a region.'));
  }
}