Skip to content
Snippets Groups Projects
Commit 86fd86a1 authored by Bernd Oliver Suenderhauf's avatar Bernd Oliver Suenderhauf
Browse files

Issue #3048696 by Pancho: Avoid separately deleting FillPdfFormFields on uninstall

parent 2bbc0f2d
No related branches found
No related tags found
No related merge requests found
......@@ -2,8 +2,6 @@
namespace Drupal\fillpdf\Entity;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Entity\Annotation\ContentEntityType;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
......@@ -11,8 +9,7 @@ use Drupal\fillpdf\FillPdfFormFieldInterface;
use Drupal\fillpdf\Service\FillPdfAdminFormHelper;
/**
* Defines the entity for managing PDF fields associated with uploaded FillPDF
* forms.
* Defines an entity for PDF fields associated with a FillPDF form entity.
*
* Uses the same access handler as fillpdf_form.
*
......@@ -25,6 +22,7 @@ use Drupal\fillpdf\Service\FillPdfAdminFormHelper;
* "edit" = "Drupal\fillpdf\Form\FillPdfFormFieldForm",
* },
* "access": "Drupal\fillpdf\FillPdfFormAccessControlHandler",
* "storage" = "Drupal\fillpdf\FillPdfFormFieldStorage",
* },
* admin_permission = "administer pdfs",
* base_table = "fillpdf_fields",
......@@ -37,8 +35,7 @@ use Drupal\fillpdf\Service\FillPdfAdminFormHelper;
class FillPdfFormField extends ContentEntityBase implements FillPdfFormFieldInterface {
/**
* @inheritdoc
* @todo Fix field descriptions to match D7 version.
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = [];
......
<?php
namespace Drupal\fillpdf;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
/**
* Defines a custom storage handler for FillPdfFormFields.
*
* The default storage is overridden to avoid having to delete FillPdfFormField
* entities separately from their parent FillPdfForms.
*/
class FillPdfFormFieldStorage extends SqlContentEntityStorage {
/**
* {@inheritdoc}
*/
public function hasData() {
// @todo: entity_type.manager replaced the entity.manager in Drupal 8.7.
// Remove after Drupal 8.6 is no longer supported.
$manager = isset($this->entityTypeManager) ? $this->entityTypeManager : $this->entityManager;
// Announce having data only if there are orphan FillPdfFormFields after
// all FillPdfForms are deleted.
return $manager->getStorage('fillpdf_form')->hasData() ? FALSE : parent::hasData();
}
}
<?php
namespace Drupal\Tests\fillpdf\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\fillpdf\Traits\TestFillPdfTrait;
use Drupal\Core\Url;
/**
* Tests uninstalling the module.
*
* @group fillpdf
*/
class UninstallTest extends BrowserTestBase {
use TestFillPdfTrait;
static public $modules = ['fillpdf_test'];
protected $profile = 'minimal';
/**
* A user with administrative permissions.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->configureFillPdf();
$this->adminUser = $this->drupalCreateUser([
'access administration pages',
'administer modules',
'administer pdfs',
]);
$this->drupalLogin($this->adminUser);
}
/**
* Tests uninstalling the module.
*/
public function testUninstall() {
$this->uploadTestPdf('fillpdf_test_v3.pdf');
// Go to the uninstall page and check the requirements.
$this->drupalGet(Url::fromRoute('system.modules_uninstall'));
$this->assertSession()->pageTextContains('The following reasons prevent FillPDF from being uninstalled');
$this->assertSession()->pageTextContains('There is content for the entity type: FillPDF form. Remove fillpdf form entities');
$this->assertSession()->pageTextNotContains('There is content for the entity type: FillPDF form field. Remove fillpdf form field entities');
// Check the fillpdf form fields are discovered.
$this->drupalGet(Url::fromRoute('system.prepare_modules_entity_uninstall', ['entity_type_id' => 'fillpdf_form_field']));
$this->assertSession()->pageTextContains('This will delete 3 fillpdf form field entities');
// Now delete all fillpdf forms.
$this->drupalGet(Url::fromRoute('system.prepare_modules_entity_uninstall', ['entity_type_id' => 'fillpdf_form']));
$this->assertSession()->pageTextContains('Are you sure you want to delete all fillpdf form entities?');
$this->drupalPostForm(NULL, [], 'Delete all fillpdf form entities');
$this->assertSession()->pageTextContains('All fillpdf form entities have been deleted');
// Make sure all fillpdf form fields have been deleted as well.
$this->drupalGet(Url::fromRoute('system.prepare_modules_entity_uninstall', ['entity_type_id' => 'fillpdf_form_field']));
$this->assertSession()->pageTextContains('There are 0 fillpdf form field entities to delete');
// Now go back to the uninstall page and uninstall fillpdf_test and fillpdf.
foreach (['fillpdf_test', 'fillpdf'] as $module) {
$this->drupalPostForm(Url::fromRoute('system.modules_uninstall'), ["uninstall[$module]" => TRUE], 'Uninstall');
$this->assertSession()->pageTextContains('The following modules will be completely uninstalled from your site, and all data from these modules will be lost');
$this->drupalPostForm(NULL, [], 'Uninstall');
$this->assertSession()->pageTextContains('The selected modules have been uninstalled');
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment