1 ckeditor5.upgrade.inc ckeditor5_upgrade_form($form, &$form_state, $format)

Form callback for upgrading a text format from CKEditor 4 to CKEditor 5.

File

core/modules/ckeditor5/ckeditor5.upgrade.inc, line 10
CKEditor 4 to CKEditor 5 upgrade code.

Code

function ckeditor5_upgrade_form($form, &$form_state, $format) {
  backdrop_set_title(t('Upgrade %format to CKEditor 5', array('%format' => $format->name)), PASS_THROUGH);
  form_load_include($form_state, 'inc', 'ckeditor5', 'ckeditor5.upgrade');
  $form_state['format'] = $format;

  $config_name = 'filter.format.' . $format->format;
  $form['help'] = array(
    '#type' => 'help',
    '#markup' => t('Upgrading from CKEditor 4 to CKEditor 5 is a one-way process. The text format configuration can be restored using a <a href="!full_export">full site configuration export</a>, or by restoring the individual text format configuration file (!example). Back up the configuration now before continuing.', array(
      '!full_export' => url('admin/config/development/configuration/full/export'),
      '!example' => '<code>' . l($config_name . '.json', 'admin/config/development/configuration/single/export', array(
        'query' => array('group' => 'Text formats', 'name' => $config_name))
      ) . '</code>')
    ),
  );

  // Check for upgrade issues before actually running the upgrade.
  $warnings = ckeditor5_upgrade_warnings($format);
  if ($warnings['error']) {
    backdrop_set_message($warnings['error'], 'error');
  }
  elseif (!empty($warnings['removed_buttons'])) {
    $warning_message = '<p>' . t('The following toolbar buttons will removed in the upgrade:') . '</p>';
    $warning_message .= theme('item_list', array(
      'items' => $warnings['removed_buttons'],
      'attributes' => array(
        'class' => array('ckeditor5-removed-buttons-list'))
    )
    );
    $warning_message .= '<p>' . t('Some buttons are no longer needed in CKEditor 5, while others might not be supported. See the <a href="!url">CKEditor 5 change record</a> for more information.', array('!url' => 'https://docs.backdropcms.org/change-records/ckeditor5-upgrade')) . '</p>';
    $form['warnings'] = array(
      '#type' => 'markup',
      '#markup' => $warning_message,
    );
  }

  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['upgrade'] = array(
    '#type' => 'submit',
    '#value' => t('Confirm upgrade'),
    '#attributes' => array('class' => array('button-danger')),
    '#access' => empty($warnings['error']),
  );
  $form['actions']['cancel'] = array(
    '#type' => 'link',
    '#href' => 'admin/config/content/formats/' . $format->format,
    '#title' => t('Cancel'),
  );
  return $form;
}