BlockContentForm::form

public BlockContentForm::form(array $form, FormStateInterface $form_state)

Gets the actual form array to be built.

Overrides ContentEntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

core/modules/block_content/src/BlockContentForm.php, line 100

Class

BlockContentForm
Form handler for the custom block edit forms.

Namespace

Drupal\block_content

Code

public function form(array $form, FormStateInterface $form_state) {
  $block = $this->entity;
  $account = $this->currentUser();

  if ($this->operation == 'edit') {
    $form['#title'] = $this->t('Edit custom block %label', array('%label' => $block->label()));
  }
  // 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] = 'block-' . Html::getClass($block->bundle()) . '-form';

  $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' => $this->t('Revision information'),
    // Open by default when "Create new revision" is checked.
    '#open' => $block->isNewRevision(),
    '#group' => 'advanced',
    '#attributes' => array(
      'class' => array('block-content-form-revision-information'),
    ),
    '#attached' => array(
      'library' => array('block_content/drupal.block_content'),
    ),
    '#weight' => 20,
    '#access' => $block->isNewRevision() || $account->hasPermission('administer blocks'),
  );

  $form['revision_information']['revision'] = array(
    '#type' => 'checkbox',
    '#title' => $this->t('Create new revision'),
    '#default_value' => $block->isNewRevision(),
    '#access' => $account->hasPermission('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="revision_log"]' => array('empty' => FALSE),
      ),
    );
  }

  $form['revision_information']['revision_log'] = array(
    '#type' => 'textarea',
    '#title' => $this->t('Revision log message'),
    '#rows' => 4,
    '#default_value' => $block->getRevisionLog(),
    '#description' => $this->t('Briefly describe the changes you have made.'),
  );

  return parent::form($form, $form_state, $block);
}
doc_Drupal
2016-10-29 08:46:56
Comments
Leave a Comment

Please login to continue.