Overrides \Drupal\Core\Entity\EntityFormController::form().
Overrides EntityFormControllerNG::form
public function form(array $form, array &$form_state) {
$block = $this->entity;
// Override the default CSS class name, since the user-defined custom block
// type name in 'TYPE-block-form' potentially clashes with third-party class
// names.
$form['#attributes']['class'][0] = drupal_html_class('block-' . $block->type->value . '-form');
// Basic block information.
// These elements are just values so they are not even sent to the client.
foreach (array(
'revision_id',
'id',
) as $key) {
$form[$key] = array(
'#type' => 'value',
'#value' => $block->{$key}->value,
);
}
$form['info'] = array(
'#type' => 'textfield',
'#title' => t('Block description'),
'#required' => TRUE,
'#default_value' => $block->info->value,
'#weight' => -5,
'#description' => t('A brief description of your block. Used on the <a href="@overview">Blocks administration page</a>.', array(
'@overview' => url('admin/structure/block'),
)),
);
$language_configuration = module_invoke('language', 'get_default_configuration', 'custom_block', $block->type->value);
// Set the correct default language.
if ($block
->isNew() && !empty($language_configuration['langcode'])) {
$language_default = language($language_configuration['langcode']);
$block->langcode->value = $language_default->langcode;
}
$form['langcode'] = array(
'#title' => t('Language'),
'#type' => 'language_select',
'#default_value' => $block->langcode->value,
'#languages' => Language::STATE_ALL,
'#access' => isset($language_configuration['language_show']) && $language_configuration['language_show'],
);
$form['advanced'] = array(
'#type' => 'vertical_tabs',
'#weight' => 99,
);
// Add a log field if the "Create new revision" option is checked, or if the
// current user has the ability to check that option.
$form['revision_information'] = array(
'#type' => 'details',
'#title' => t('Revision information'),
'#collapsible' => TRUE,
// Collapsed by default when "Create new revision" is unchecked.
'#collapsed' => !$block
->isNewRevision(),
'#group' => 'advanced',
'#attributes' => array(
'class' => array(
'custom-block-form-revision-information',
),
),
'#attached' => array(
'js' => array(
drupal_get_path('module', 'custom_block') . '/custom_block.js',
),
),
'#weight' => 20,
'#access' => $block
->isNewRevision() || user_access('administer blocks'),
);
$form['revision_information']['revision'] = array(
'#type' => 'checkbox',
'#title' => t('Create new revision'),
'#default_value' => $block
->isNewRevision(),
'#access' => user_access('administer blocks'),
);
// Check the revision log checkbox when the log textarea is filled in.
// This must not happen if "Create new revision" is enabled by default,
// since the state would auto-disable the checkbox otherwise.
if (!$block
->isNewRevision()) {
$form['revision_information']['revision']['#states'] = array(
'checked' => array(
'textarea[name="log"]' => array(
'empty' => FALSE,
),
),
);
}
$form['revision_information']['log'] = array(
'#type' => 'textarea',
'#title' => t('Revision log message'),
'#rows' => 4,
'#default_value' => $block->log->value,
'#description' => t('Briefly describe the changes you have made.'),
);
return parent::form($form, $form_state, $block);
}