Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fillpdf
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drupal.org
fillpdf
Commits
ba662bad
Commit
ba662bad
authored
6 years ago
by
Bernd Oliver Suenderhauf
Browse files
Options
Downloads
Patches
Plain Diff
Issue #3046126 by Pancho: Delete FillPdfFormFields together with the FillPdfForm
parent
07cd6d5b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Entity/FillPdfForm.php
+19
-0
19 additions, 0 deletions
src/Entity/FillPdfForm.php
tests/src/Functional/FillPdfFormDeleteFormTest.php
+26
-1
26 additions, 1 deletion
tests/src/Functional/FillPdfFormDeleteFormTest.php
with
45 additions
and
1 deletion
src/Entity/FillPdfForm.php
+
19
−
0
View file @
ba662bad
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
Drupal\fillpdf\Entity
;
namespace
Drupal\fillpdf\Entity
;
use
Drupal\Core\Entity\ContentEntityBase
;
use
Drupal\Core\Entity\ContentEntityBase
;
use
Drupal\Core\Entity\EntityStorageInterface
;
use
Drupal\Core\Entity\EntityTypeInterface
;
use
Drupal\Core\Entity\EntityTypeInterface
;
use
Drupal\Core\Field\BaseFieldDefinition
;
use
Drupal\Core\Field\BaseFieldDefinition
;
use
Drupal\Core\Url
;
use
Drupal\Core\Url
;
...
@@ -153,6 +154,24 @@ class FillPdfForm extends ContentEntityBase implements FillPdfFormInterface {
...
@@ -153,6 +154,24 @@ class FillPdfForm extends ContentEntityBase implements FillPdfFormInterface {
return
$fields
;
return
$fields
;
}
}
/**
* Acts on FillPdfForms before they are deleted and before hooks are invoked.
*
* Deletes the FillPdfForm's FillPdfFormFields.
*
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The entity storage object.
* @param \Drupal\fillpdf\FillPdfFormInterface[] $entities
* An array of FillPdfForms.
*/
public
static
function
preDelete
(
EntityStorageInterface
$storage
,
array
$entities
)
{
parent
::
preDelete
(
$storage
,
$entities
);
foreach
(
$entities
as
$fillpdf_form
)
{
\Drupal
::
entityTypeManager
()
->
getStorage
(
'fillpdf_form_field'
)
->
delete
(
$fillpdf_form
->
getFormFields
());
}
}
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
...
...
This diff is collapsed.
Click to expand it.
tests/src/Functional/FillPdfFormDeleteFormTest.php
+
26
−
1
View file @
ba662bad
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
Drupal\Tests\fillpdf\Functional
;
namespace
Drupal\Tests\fillpdf\Functional
;
use
Drupal\fillpdf\Entity\FillPdfForm
;
use
Drupal\fillpdf\Entity\FillPdfForm
;
use
Drupal\fillpdf\Entity\FillPdfFormField
;
use
Drupal\Tests\BrowserTestBase
;
use
Drupal\Tests\BrowserTestBase
;
use
Drupal\Tests\fillpdf\Traits\TestFillPdfTrait
;
use
Drupal\Tests\fillpdf\Traits\TestFillPdfTrait
;
use
Drupal\Core\Url
;
use
Drupal\Core\Url
;
...
@@ -31,7 +32,7 @@ class FillPdfFormDeleteFormTest extends BrowserTestBase {
...
@@ -31,7 +32,7 @@ class FillPdfFormDeleteFormTest extends BrowserTestBase {
/**
/**
* Tests the cancel link works.
* Tests the cancel link works.
*/
*/
public
function
test
CancelDeletion
()
{
public
function
test
DeleteFormCancel
()
{
$this
->
uploadTestPdf
(
'fillpdf_test_v3.pdf'
);
$this
->
uploadTestPdf
(
'fillpdf_test_v3.pdf'
);
$fillpdf_form
=
FillPdfForm
::
load
(
$this
->
getLatestFillPdfForm
());
$fillpdf_form
=
FillPdfForm
::
load
(
$this
->
getLatestFillPdfForm
());
...
@@ -69,4 +70,28 @@ class FillPdfFormDeleteFormTest extends BrowserTestBase {
...
@@ -69,4 +70,28 @@ class FillPdfFormDeleteFormTest extends BrowserTestBase {
$this
->
assertSession
()
->
addressEquals
(
$fillpdf_form
->
toUrl
(
'canonical'
));
$this
->
assertSession
()
->
addressEquals
(
$fillpdf_form
->
toUrl
(
'canonical'
));
}
}
/**
* Tests the cancel link works.
*/
public
function
testDeleteForm
()
{
$this
->
uploadTestPdf
(
'fillpdf_test_v3.pdf'
);
$form_id
=
$this
->
getLatestFillPdfForm
();
// Verify the FillPdfForm's fields are stored.
$field_ids
=
\Drupal
::
entityQuery
(
'fillpdf_form_field'
)
->
condition
(
'fillpdf_form'
,
$form_id
)
->
execute
();
$this
->
assertCount
(
3
,
$field_ids
,
"3 FillPdfFormFields have been created."
);
// We're on the edit form. Click 'Delete' and confirm deletion.
$this
->
clickLink
(
'Delete'
);
$this
->
drupalPostForm
(
NULL
,
NULL
,
'Delete'
);
$this
->
assertSession
()
->
pageTextContains
(
'FillPDF form deleted.'
);
$this
->
assertSession
()
->
addressEquals
(
Url
::
fromRoute
(
'fillpdf.forms_admin'
));
// Now verify the FillPdfForm and its fields have actually been deleted.
$this
->
assertNull
(
FillPdfForm
::
load
(
$form_id
),
"The FillPdfForm #
{
$form_id
}
doesn't exist anymore."
);
foreach
(
$field_ids
as
$id
)
{
$this
->
assertNull
(
FillPdfFormField
::
load
(
$id
),
"The FillPdfFormField #
{
$id
}
doesn't exist anymore."
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment