You are here

function bean_admin_ui_type_form in Bean (for Drupal 7) 7

Generates the bean type editing form.

2 string references to 'bean_admin_ui_type_form'
bean_admin_ui_menu in bean_admin_ui/bean_admin_ui.module
Implements hook_menu().
PanelizerEntityBean::hook_form_alter in plugins/entity/PanelizerEntityBean.class.php
Implements a delegated hook_form_alter.

File

bean_admin_ui/bean_admin_ui.admin.inc, line 73
Bean Admin Page

Code

function bean_admin_ui_type_form($form, &$form_state, $bean_type = NULL) {
  $form['new'] = array(
    '#type' => 'value',
    '#value' => TRUE,
  );

  // If bean_type is null then load an empty one.
  if (is_null($bean_type)) {
    $plugin_info = _bean_admin_default_plugin();
    $plugin_info['name'] = '';
    $bean_type = new BeanCustom($plugin_info);
  }
  elseif (!method_exists($bean_type, 'getExportStatus') || $bean_type
    ->getExportStatus() == 'Normal') {
    $form['new'] = array(
      '#type' => 'value',
      '#value' => FALSE,
    );
  }
  $disabled = !$bean_type
    ->isEditable();
  if ($disabled) {
    drupal_set_message(t('This Block Type can not be edited'));
  }
  $form['bean_type'] = array(
    '#type' => 'value',
    '#value' => $bean_type,
  );
  $form['label'] = array(
    '#title' => t('Label'),
    '#type' => 'textfield',
    '#default_value' => $bean_type
      ->getLabel(),
    '#description' => t('The human-readable name of this block type.'),
    '#required' => TRUE,
    '#size' => 30,
    '#disabled' => $disabled,
  );
  $form['description'] = array(
    '#title' => t('Description'),
    '#type' => 'textarea',
    '#default_value' => $bean_type
      ->getDescription(),
    '#description' => t('The description of this block type.'),
    '#disabled' => $disabled,
  );

  // Machine-readable type name.
  $form['name'] = array(
    '#type' => 'machine_name',
    '#default_value' => isset($bean_type->type) ? $bean_type->type : '',
    '#maxlength' => 32,
    '#machine_name' => array(
      'exists' => 'bean_type_load',
      'source' => array(
        'label',
      ),
    ),
    '#description' => t('A unique machine-readable name for this block type. It must only contain lowercase letters, numbers, and underscores.'),
    '#disabled' => $disabled,
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save Block type'),
    '#weight' => 40,
    '#disabled' => $disabled,
  );

  // This is a new bean type.
  if (!empty($bean_type->type)) {
    $form['actions']['delete'] = array(
      '#type' => 'submit',
      '#name' => 'delete',
      '#value' => t('Delete Block type'),
      '#weight' => 45,
      '#limit_validation_errors' => array(),
      '#disabled' => $disabled,
    );
    if (method_exists($bean_type, 'getExportStatus')) {
      if ($bean_type
        ->getExportStatus() == 'Overridden') {
        $form['actions']['delete']['#name'] = 'revert';
        $form['actions']['delete']['#value'] = t('Revert to defaults');
      }
      else {
        unset($form['actions']['delete']);
      }
    }
  }
  return $form;
}