1 block.module block_custom_block_form($edit = array(), $stand_alone = TRUE)

Form constructor for the custom block form.

Parameters

$edit: (optional) An associative array of information retrieved by block_custom_get_block() if an existing block is being edited, or an empty array otherwise. Defaults to array().

$stand_alone: (optional) Set to FALSE if this form is used when displaying as part of a form within the Layout UI. The default value of TRUE should be used if this is a stand-alone form, such as when editing a block at it's own URL.

Related topics

File

core/modules/block/block.module, line 242
Provides the ability to create reusable custom blocks.

Code

function block_custom_block_form($edit = array(), $stand_alone = TRUE) {
  $edit += array(
    'delta' => NULL,
    'info' => '',
    'title' => '',
    'description' => '',
    'body' => array('value' => '', 'format' => NULL),
    'default_langcode' => LANGUAGE_NONE,
  );
  // If the description is the default from hook_block_info(), leave blank.
  if ($edit['description'] === t('A reusable custom block.')) {
    $edit['description'] = '';
  }

  $form['info'] = array(
    '#type' => 'textfield',
    '#title' => t('Admin label'),
    '#default_value' => $edit['info'],
    '#maxlength' => 64,
    '#description' => t('This text is used only in administrative interfaces. It will not be shown to site visitors.'),
    '#required' => TRUE,
    '#id' => 'block-info',
  );
  $form['delta'] = array(
    '#type' => 'machine_name',
    '#default_value' => $edit['delta'],
    '#maxlength' => 128,
    '#machine_name' => array(
      'exists' => 'block_custom_block_load',
      'source' => array('info'),
    ),
    '#description' => t('A unique machine-readable name for this Block. It must only contain lowercase letters, numbers, and underscores.'),
    '#disabled' => isset($edit['delta']),
  );
  $form['description'] = array(
    '#type' => 'textfield',
    '#title' => t('Admin description'),
    '#default_value' => $edit['description'],
    '#maxlength' => 128,
    '#description' => t('This text is used only in administrative interfaces. It will not be shown to site visitors.<br />Allowed HTML tags: @tags', array('@tags' => _filter_xss_display_allowed_tags())),
    '#id' => 'block-description',
  );
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Display title'),
    '#default_value' => $edit['title'],
    '#maxlength' => 255,
    '#description' => t('The title of the block as shown to the user. This will affect all places where this block is used.'),
  );
  $form['body'] = array(
    '#type' => 'text_format',
    '#title' => t('Block content'),
    '#default_value' => $edit['body']['value'],
    '#format' => $edit['body']['format'],
    '#editor_uploads' => TRUE,
    '#rows' => 8,
    '#required' => TRUE,
  );

  // Add default language select dropdown on the stand-alone config form only.
  // Not shown on the translation forms at all.
  if ($stand_alone && module_exists('locale') && empty($edit['langcode'])) {
    $language_options = array(LANGUAGE_NONE => t('- None -'));
    $language_options += language_list(TRUE, TRUE);

    $form['default_langcode'] = array(
      '#type' => 'select',
      '#title' => t('Language'),
      '#description' => 'If assigned a language, options will be shown to translate this block into other langauges.',
      '#options' => $language_options,
      '#default_value' => $edit['default_langcode'],
    );
  }

  // When displaying as part of the Layout UI.
  if (!$stand_alone) {
    // The Layout UI may show the translated block admin title and description,
    // but this form will only show the source translation contents. Notify
    // the user that they may be about to edit something they weren't expecting.
    if (!empty($edit['translations'])) {
      $form['translation_help'] = array(
        '#type' => 'help',
        '#markup' => '<strong>' . t('Translation notice') . ':</strong> ' . t('The settings in this form are for the source translation only. Translations may be modified on the <a href="!url">block\'s translation settings page</a>.', array('!url' => url('admin/structure/block/manage/' . $edit['delta'] . '/translation'))),
        '#weight' => -99,
      );
    }

    $form['title']['#states'] = array(
      'visible' => array(
        '[name=title_display]' => array('value' => LAYOUT_TITLE_DEFAULT),
      ),
    );
    $form['reusable'] = array(
      '#type' => 'checkbox',
      '#title' => t('Make this block reusable'),
      '#description' => t('This option may not be unchecked once enabled. You may configure or delete this reusable block from the !block_link page.', array('!block_link' => l(t('Custom blocks'), 'admin/structure/block'))),
      '#weight' => 4,
      '#default_value' => TRUE,
      '#disabled' => TRUE,
    );
    $form['info']['#weight'] = 5;
    $form['delta']['#weight'] = 6;
    $form['delta']['#machine_name']['source'] = array('block_settings', 'info');
    $form['description']['#weight'] = 7;
  }

  return $form;
}