/** * @covers ::buildCancelLink * * Tests a cancel link provided by the destination. */ public function testCancelLinkDestination() { $query = array('destination' => 'baz'); $form = $this->getMock('Drupal\\Core\\Form\\ConfirmFormInterface'); $link = ConfirmFormHelper::buildCancelLink($form, new Request($query)); $this->assertSame($query['destination'], $link['#href']); }
/** * {@inheritdoc} */ protected function actions(array $form, FormStateInterface $form_state) { $actions = parent::actions($form, $form_state); $actions['submit']['#value'] = $this->getConfirmText(); unset($actions['delete']); // Prepare cancel link. $actions['cancel'] = ConfirmFormHelper::buildCancelLink($this, $this->getRequest()); return $actions; }
/** * Build the form gathering database credential and file location information. * * @param array $form * An associative array containing the structure of the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * * @return array * The form structure. */ public function buildConfirmForm(array $form, FormStateInterface $form_state) { $form['#title'] = $this->getQuestion(); $form['#attributes']['class'][] = 'confirmation'; $form['description'] = ['#markup' => $this->getDescription()]; $form[$this->getFormName()] = ['#type' => 'hidden', '#value' => 1]; $form['module_list'] = ['#type' => 'table', '#header' => [$this->t('Source module'), $this->t('Destination module'), $this->t('Data to be upgraded')]]; $table_data = []; $system_data = []; foreach ($form_state->get('migration_ids') as $migration_id) { /** @var MigrationInterface $migration */ $migration = Migration::load($migration_id); // Fetch the system data at the first opportunity. if (empty($system_data) && is_a($migration->getSourcePlugin(), '\\Drupal\\migrate_drupal\\Plugin\\migrate\\source\\DrupalSqlBase')) { $system_data = $migration->getSourcePlugin()->getSystemData(); } $template_id = $migration->get('template'); $source_module = $this->moduleUpgradePaths[$template_id]['source_module']; $destination_module = $this->moduleUpgradePaths[$template_id]['destination_module']; $table_data[$source_module][$destination_module][$migration_id] = $migration->label(); } ksort($table_data); foreach ($table_data as $source_module => $destination_module_info) { ksort($table_data[$source_module]); } $last_source_module = $last_destination_module = ''; foreach ($table_data as $source_module => $destination_module_info) { foreach ($destination_module_info as $destination_module => $migration_ids) { foreach ($migration_ids as $migration_id => $migration_label) { if ($source_module == $last_source_module) { $display_source_module = ''; } else { $display_source_module = $source_module; $last_source_module = $source_module; } if ($destination_module == $last_destination_module) { $display_destination_module = ''; } else { $display_destination_module = $destination_module; $last_destination_module = $destination_module; } $form['module_list'][$migration_id] = ['source_module' => ['#plain_text' => $display_source_module], 'destination_module' => ['#plain_text' => $display_destination_module], 'migration' => ['#plain_text' => $migration_label]]; } } } $unmigrated_source_modules = array_diff_key($system_data['module'], $table_data); ksort($unmigrated_source_modules); foreach ($unmigrated_source_modules as $source_module => $module_data) { if ($module_data['status']) { $form['module_list'][$source_module] = ['source_module' => ['#plain_text' => $source_module], 'destination_module' => ['#plain_text' => ''], 'migration' => ['#plain_text' => 'No upgrade path available']]; } } $form['actions'] = ['#type' => 'actions']; $form['actions']['submit'] = ['#type' => 'submit', '#value' => $this->getConfirmText(), '#button_type' => 'primary', '#validate' => [], '#submit' => ['::submitConfirmForm']]; $form['actions']['cancel'] = ConfirmFormHelper::buildCancelLink($this, $this->getRequest()); // By default, render the form using theme_confirm_form(). if (!isset($form['#theme'])) { $form['#theme'] = 'confirm_form'; } return $form; }
/** * Provides the action buttons for submitting this form. */ protected function actions(array $form, FormStateInterface $form_state) { return array('submit' => array('#type' => 'submit', '#value' => $this->getConfirmText(), '#submit' => array(array($this, 'submitForm'))), 'cancel' => ConfirmFormHelper::buildCancelLink($this, $this->getRequest())); }
/** * @covers ::buildCancelLink * * Tests a cancel link provided by the destination. * * @dataProvider providerTestCancelLinkDestination */ public function testCancelLinkDestination($destination) { $query = array('destination' => $destination); $form = $this->getMock('Drupal\\Core\\Form\\ConfirmFormInterface'); $path_validator = $this->getMock('Drupal\\Core\\Path\\PathValidatorInterface'); $container_builder = new ContainerBuilder(); $container_builder->set('path.validator', $path_validator); \Drupal::setContainer($container_builder); $url = Url::fromRoute('test_route'); $path_validator->expects($this->atLeastOnce())->method('getUrlIfValidWithoutAccessCheck')->with('baz')->willReturn($url); $link = ConfirmFormHelper::buildCancelLink($form, new Request($query)); $this->assertSame($url, $link['#url']); }
/** * Build the form gathering database credential and file location information. * * @param array $form * An associative array containing the structure of the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * * @return array * The form structure. */ public function buildConfirmForm(array $form, FormStateInterface $form_state) { $rollback = $form_state->getValue('upgrade_option') == static::MIGRATE_UPGRADE_ROLLBACK; if ($rollback) { $form_state->setStorage(['upgrade_option' => static::MIGRATE_UPGRADE_ROLLBACK]); } $form['#title'] = $this->getQuestion(); $form['#attributes']['class'][] = 'confirmation'; $form[$this->getFormName()] = ['#type' => 'hidden', '#value' => 1]; if ($rollback) { $form['rollback'] = ['#markup' => $this->t('All previously-imported content, as well as configuration such as field definitions, will be removed.')]; } else { $table_data = []; $system_data = []; foreach ($form_state->get('migration_ids') as $migration_id) { /** @var MigrationInterface $migration */ $migration = Migration::load($migration_id); // Fetch the system data at the first opportunity. if (empty($system_data) && is_a($migration->getSourcePlugin(), '\\Drupal\\migrate_drupal\\Plugin\\migrate\\source\\DrupalSqlBase')) { $system_data = $migration->getSourcePlugin()->getSystemData(); } $template_id = $migration->get('template'); $source_module = $this->moduleUpgradePaths[$template_id]['source_module']; $destination_module = $this->moduleUpgradePaths[$template_id]['destination_module']; $table_data[$source_module][$destination_module][$migration_id] = $migration->label(); } ksort($table_data); foreach ($table_data as $source_module => $destination_module_info) { ksort($table_data[$source_module]); } $unmigrated_source_modules = array_diff_key($system_data['module'], $table_data); // Missing migrations. $desc = "The following items will not be upgraded. " . 'For more information see <a href="https://www.drupal.org/upgrade/migrate"> Upgrading from Drupal 6 or 7 to Drupal 8</a>.'; $form['missing_module_list_title'] = ['#type' => 'item', '#title' => t('Missing upgrade paths'), '#description' => $this->t($desc)]; $form['missing_module_list'] = ['#type' => 'table', '#header' => [$this->t('Source'), $this->t('Destination')]]; $missing_count = 0; ksort($unmigrated_source_modules); foreach ($unmigrated_source_modules as $source_module => $module_data) { if ($module_data['status']) { $missing_count++; $form['missing_module_list'][$source_module] = ['source_module' => ['#plain_text' => $source_module], 'destination_module' => ['#plain_text' => 'Missing']]; } } // Available migrations. $form['available_module_list'] = ['#tree' => TRUE, '#type' => 'details', '#title' => t('Available upgrade paths')]; $form['available_module_list']['module_list'] = ['#type' => 'table', '#header' => [$this->t('Source'), $this->t('Destination')]]; $available_count = 0; foreach ($table_data as $source_module => $destination_module_info) { $available_count++; $destination_details = []; foreach ($destination_module_info as $destination_module => $migration_ids) { $destination_details[$destination_module] = ['#type' => 'item', '#plain_text' => t($destination_module)]; } $form['available_module_list']['module_list'][$source_module] = ['source_module' => ['#plain_text' => $source_module], 'destination_module' => $destination_details]; } $form['counts'] = ['#type' => 'item', '#title' => "<ul><li>" . t($available_count . ' available upgrade paths') . "</li><li>" . t($missing_count . ' missing upgrade paths') . "</li></ul>", '#weight' => -15]; } if ($rollback) { $confirm_text = $this->t('Perform rollback'); } else { $confirm_text = $this->t('Perform upgrade'); } $form['actions'] = ['#type' => 'actions']; $form['actions']['submit'] = ['#type' => 'submit', '#value' => $confirm_text, '#button_type' => 'primary', '#validate' => [], '#submit' => ['::submitConfirmForm']]; $form['actions']['cancel'] = ConfirmFormHelper::buildCancelLink($this, $this->getRequest()); // By default, render the form using theme_confirm_form(). if (!isset($form['#theme'])) { $form['#theme'] = 'confirm_form'; } return $form; }