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

Issue #3023341 by Pancho: Fix FillPdfFileContext label key; add FillPdfForm canonical route

parent 0f1845fc
No related branches found
No related tags found
No related merge requests found
...@@ -26,6 +26,16 @@ fillpdf.populate_pdf: ...@@ -26,6 +26,16 @@ fillpdf.populate_pdf:
requirements: requirements:
_custom_access: '\Drupal\fillpdf\FillPdfAccessController::checkLink' _custom_access: '\Drupal\fillpdf\FillPdfAccessController::checkLink'
entity.fillpdf_form.canonical:
path: '/admin/structure/fillpdf/{fillpdf_form}'
defaults:
_entity_form: fillpdf_form.edit
_title: 'Edit FillPDF form'
requirements:
_entity_access: fillpdf_form.update
options:
_admin_route: TRUE
entity.fillpdf_form.edit_form: entity.fillpdf_form.edit_form:
path: '/admin/structure/fillpdf/{fillpdf_form}' path: '/admin/structure/fillpdf/{fillpdf_form}'
defaults: defaults:
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
namespace Drupal\fillpdf\Entity; namespace Drupal\fillpdf\Entity;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Entity\Annotation\ContentEntityType;
use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Entity\ContentEntityBase; use Drupal\Core\Entity\ContentEntityBase;
...@@ -25,20 +23,21 @@ use Drupal\fillpdf\FillPdfFileContextInterface; ...@@ -25,20 +23,21 @@ use Drupal\fillpdf\FillPdfFileContextInterface;
* base_table = "fillpdf_file_context", * base_table = "fillpdf_file_context",
* entity_keys = { * entity_keys = {
* "id" = "id", * "id" = "id",
* "label" = "name", * "label" = "id",
* "uuid" = "uuid" * "uuid" = "uuid"
* }, * },
* ) * )
*/ */
class FillPdfFileContext extends ContentEntityBase implements FillPdfFileContextInterface { class FillPdfFileContext extends ContentEntityBase implements FillPdfFileContextInterface {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function preCreate(EntityStorageInterface $storage_controller, array &$values) { public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
parent::preCreate($storage_controller, $values); parent::preCreate($storage_controller, $values);
$values += array( $values += [
'user_id' => \Drupal::currentUser()->id(), 'user_id' => \Drupal::currentUser()->id(),
); ];
} }
/** /**
......
...@@ -34,6 +34,7 @@ use Drupal\fillpdf\Service\FillPdfAdminFormHelper; ...@@ -34,6 +34,7 @@ use Drupal\fillpdf\Service\FillPdfAdminFormHelper;
* "uuid" = "uuid", * "uuid" = "uuid",
* }, * },
* links = { * links = {
* "canonical" = "/admin/structure/fillpdf/{fillpdf_form}",
* "edit-form" = "/admin/structure/fillpdf/{fillpdf_form}", * "edit-form" = "/admin/structure/fillpdf/{fillpdf_form}",
* "delete-form" = "/admin/structure/fillpdf/{fillpdf_form}/delete", * "delete-form" = "/admin/structure/fillpdf/{fillpdf_form}/delete",
* "export-form" = "/admin/structure/fillpdf/{fillpdf_form}/export", * "export-form" = "/admin/structure/fillpdf/{fillpdf_form}/export",
......
...@@ -276,7 +276,7 @@ class FillPdfFormForm extends ContentEntityForm { ...@@ -276,7 +276,7 @@ class FillPdfFormForm extends ContentEntityForm {
$file = $form_state->getValue('upload_pdf'); $file = $form_state->getValue('upload_pdf');
$message = []; $message = [];
$message[] = $this->t('FillPDF Form %link has been updated.', ['%link' => $entity->toLink(NULL, 'edit-form')->toString()]); $message[] = $this->t('FillPDF Form %link has been updated.', ['%link' => $entity->toLink()->toString()]);
if ($file) { if ($file) {
$existing_fields = $this->entityHelper->getFormFields($entity); $existing_fields = $this->entityHelper->getFormFields($entity);
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
namespace Drupal\Tests\fillpdf\Functional; namespace Drupal\Tests\fillpdf\Functional;
use Drupal\field\Entity\FieldConfig; use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\file\Entity\File;
use Drupal\fillpdf\Entity\FillPdfForm; use Drupal\fillpdf\Entity\FillPdfForm;
use Drupal\simpletest\ContentTypeCreationTrait; use Drupal\simpletest\ContentTypeCreationTrait;
use Drupal\user\Entity\Role; use Drupal\user\Entity\Role;
...@@ -19,6 +19,7 @@ use Drupal\Tests\fillpdf\Traits\TestFillPdfTrait; ...@@ -19,6 +19,7 @@ use Drupal\Tests\fillpdf\Traits\TestFillPdfTrait;
class AdminIdTest extends BrowserTestBase { class AdminIdTest extends BrowserTestBase {
use ContentTypeCreationTrait; use ContentTypeCreationTrait;
use EntityReferenceTestTrait;
use TestFileCreationTrait; use TestFileCreationTrait;
use TestFillPdfTrait; use TestFillPdfTrait;
...@@ -26,7 +27,7 @@ class AdminIdTest extends BrowserTestBase { ...@@ -26,7 +27,7 @@ class AdminIdTest extends BrowserTestBase {
protected $profile = 'minimal'; protected $profile = 'minimal';
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
...@@ -111,6 +112,42 @@ class AdminIdTest extends BrowserTestBase { ...@@ -111,6 +112,42 @@ class AdminIdTest extends BrowserTestBase {
$this->assertSession()->pageTextContains('Only PDF files are supported, and they must end in .pdf.'); $this->assertSession()->pageTextContains('Only PDF files are supported, and they must end in .pdf.');
} }
/**
* Tests proper registration of managed_files.
*/
public function testFillPdfFileUsage() {
$this->uploadTestPdf('fillpdf_test_v3.pdf');
// Set the administrative title and check if it has been successfully set.
$admin_title = 'Example form';
$this->drupalPostForm(NULL, ['admin_title[0][value]' => $admin_title], 'Save');
$this->assertSession()->pageTextContains("FillPDF Form $admin_title has been updated.");
$this->assertSession()->fieldValueEquals('edit-admin-title-0-value', $admin_title);
// Grant additional permission to the logged in user.
$existing_user_roles = $this->loggedInUser->getRoles(TRUE);
$role_to_modify = Role::load(end($existing_user_roles));
$this->grantPermissions($role_to_modify, ['access files overview']);
// Check if the uploaded test PDF file is properly registered as a permanent
// managed_file.
$fillpdf_form = FillPdfForm::load($this->getLatestFillPdfForm());
$file_id = $fillpdf_form->get('file')->first()->getValue()['target_id'];
$this->drupalPostForm('admin/content/files', ['edit-filename' => 'fillpdf_test_v3.pdf'], 'Filter');
$this->assertSession()->elementsCount('css', 'table td.views-field.views-field-filename', 1);
$this->assertSession()->pageTextContains('Permanent');
// @todo Past 8.6.x, use File::load($file_id)->createFileUrl() directly.
// See https://www.drupal.org/project/fillpdf/issues/3023341.
$file_uri = File::load($file_id)->getFileUri();
$this->assertSession()->linkByHrefExists(file_create_url($file_uri));
// Now go check the File usage screen and see if the FillPdfForm is listed
// with its canonical link.
$this->drupalGet("admin/content/files/usage/$file_id");
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->linkByHrefExists($fillpdf_form->toUrl()->toString());
}
/** /**
* Tests an entity reference to a FillPdfForm. * Tests an entity reference to a FillPdfForm.
*/ */
...@@ -129,32 +166,20 @@ class AdminIdTest extends BrowserTestBase { ...@@ -129,32 +166,20 @@ class AdminIdTest extends BrowserTestBase {
$bundle_id = $bundle->id(); $bundle_id = $bundle->id();
// Create an entity reference to our FillPdfForm. // Create an entity reference to our FillPdfForm.
$storage = FieldStorageConfig::create([ $this->createEntityReferenceField('node', $bundle_id, 'field_fillpdf_form', 'FillPDF form', 'fillpdf_form');
'field_name' => 'field_fillpdf_form', $this->container->get('entity_type.manager')
'entity_type' => 'node',
'type' => 'entity_reference',
'settings' => [
'target_type' => 'fillpdf_form',
],
]);
$storage->save();
$field = FieldConfig::create([
'label' => 'FillPDF form',
'field_storage' => $storage,
'entity_type' => 'node',
'bundle' => $bundle_id,
'settings' => [
'handler' => 'default:fillpdf_form',
],
]);
$field->save();
\Drupal::entityTypeManager()
->getStorage('entity_form_display') ->getStorage('entity_form_display')
->load("node.{$bundle_id}.default") ->load("node.{$bundle_id}.default")
->setComponent('field_fillpdf_form', [ ->setComponent('field_fillpdf_form', [
'type' => 'options_select', 'type' => 'options_select',
]) ])->save();
->save(); $this->container->get('entity_type.manager')
->getStorage('entity_view_display')
->load("node.{$bundle_id}.default")
->setComponent('field_fillpdf_form', [
'type' => 'entity_reference_label',
'settings' => ['link' => TRUE],
])->save();
// Grant additional permission to the logged in user. // Grant additional permission to the logged in user.
$existing_user_roles = $this->loggedInUser->getRoles(TRUE); $existing_user_roles = $this->loggedInUser->getRoles(TRUE);
...@@ -166,6 +191,17 @@ class AdminIdTest extends BrowserTestBase { ...@@ -166,6 +191,17 @@ class AdminIdTest extends BrowserTestBase {
$this->drupalGet("/node/add/{$bundle_id}"); $this->drupalGet("/node/add/{$bundle_id}");
$this->assertSession()->statusCodeEquals(200); $this->assertSession()->statusCodeEquals(200);
$this->assertSession()->optionExists('edit-field-fillpdf-form', $admin_title); $this->assertSession()->optionExists('edit-field-fillpdf-form', $admin_title);
// Select our FillPdfForm reference, save and see the label is rendered as
// canonical link.
$edit = [
'title[0][value]' => 'Test node',
'field_fillpdf_form' => $fid,
];
$this->drupalPostForm(NULL, $edit, 'Save');
$fillpdf_form = FillPdfForm::load($fid);
$this->assertSession()->linkByHrefExists($fillpdf_form->toUrl()->toString());
} }
} }
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