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

Issue #3022485 by Anas_maw, Pancho: Undefined entity label impedes identifying FillPdfForm

parent 67c67ddf
No related branches found
No related tags found
No related merge requests found
...@@ -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\ContentEntityBase; use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Field\BaseFieldDefinition;
...@@ -32,6 +30,7 @@ use Drupal\fillpdf\Service\FillPdfAdminFormHelper; ...@@ -32,6 +30,7 @@ use Drupal\fillpdf\Service\FillPdfAdminFormHelper;
* base_table = "fillpdf_forms", * base_table = "fillpdf_forms",
* entity_keys = { * entity_keys = {
* "id" = "fid", * "id" = "fid",
* "label" = "admin_title",
* "uuid" = "uuid", * "uuid" = "uuid",
* }, * },
* links = { * links = {
...@@ -68,8 +67,8 @@ class FillPdfForm extends ContentEntityBase implements FillPdfFormInterface { ...@@ -68,8 +67,8 @@ class FillPdfForm extends ContentEntityBase implements FillPdfFormInterface {
$overview_url = Url::fromUri('base://admin/structure/fillpdf')->toString(); $overview_url = Url::fromUri('base://admin/structure/fillpdf')->toString();
$fields['admin_title'] = BaseFieldDefinition::create('string') $fields['admin_title'] = BaseFieldDefinition::create('string')
->setLabel(t('Administrative description')) ->setLabel(t('Administrative title'))
->setDescription(t('Enter the name of the form here, and it will be shown on the <a href="@overview_url">form overview page</a>. It has no effect on functionality, but it can help you identify which form configuration you want to edit.', ['@overview_url' => $overview_url])) ->setDescription(t('Enter an administrative title to help identifying this FillPDF Form on the <a href="@overview_url">form overview page</a> and in some other places.', ['@overview_url' => $overview_url]))
->setDisplayOptions('form', [ ->setDisplayOptions('form', [
'type' => 'string', 'type' => 'string',
'weight' => 0, 'weight' => 0,
......
...@@ -275,6 +275,9 @@ class FillPdfFormForm extends ContentEntityForm { ...@@ -275,6 +275,9 @@ class FillPdfFormForm extends ContentEntityForm {
/** @var \Drupal\file\FileInterface $file */ /** @var \Drupal\file\FileInterface $file */
$file = $form_state->getValue('upload_pdf'); $file = $form_state->getValue('upload_pdf');
$message = [];
$message[] = $this->t('FillPDF Form %link has been updated.', ['%link' => $entity->toLink(NULL, 'edit-form')->toString()]);
if ($file) { if ($file) {
$existing_fields = $this->entityHelper->getFormFields($entity); $existing_fields = $this->entityHelper->getFormFields($entity);
...@@ -288,20 +291,24 @@ class FillPdfFormForm extends ContentEntityForm { ...@@ -288,20 +291,24 @@ class FillPdfFormForm extends ContentEntityForm {
$form_fields = $added['fields']; $form_fields = $added['fields'];
$message[] = $this->t('Your previous field mappings have been transferred to the new PDF template you uploaded.');
// Import previous form field values over new fields. // Import previous form field values over new fields.
$non_matching_msg = '';
$non_matching_fields = $this->serializer->importFormFieldsByKey($existing_fields, $form_fields); $non_matching_fields = $this->serializer->importFormFieldsByKey($existing_fields, $form_fields);
if (count($non_matching_fields)) { if (count($non_matching_fields)) {
$non_matching_msg = $this->t(" These keys couldn't be found in the new PDF"); $message[] = $this->t("These keys couldn't be found in the new PDF:");
} }
drupal_set_message($this->t("Your previous field mappings have been transferred to the new PDF template you uploaded.") . $non_matching_msg); $this->messenger()->addStatus(implode(' ', $message));
foreach ($non_matching_fields as $non_matching_field) { foreach ($non_matching_fields as $non_matching_field) {
drupal_set_message($non_matching_field, 'warning'); $this->messenger()->addWarning($non_matching_field);
} }
drupal_set_message($this->t('You might also want to update the <em>Filename pattern</em> field; this has not been changed.')); $this->messenger()->addStatus($this->t('You might also want to update the <em>Filename pattern</em> field; this has not been changed.'));
}
else {
$this->messenger()->addStatus(reset($message));
} }
$entity->set('default_entity_type', $form_state->getValue('default_entity_type')); $entity->set('default_entity_type', $form_state->getValue('default_entity_type'));
......
...@@ -2,7 +2,11 @@ ...@@ -2,7 +2,11 @@
namespace Drupal\Tests\fillpdf\Functional; namespace Drupal\Tests\fillpdf\Functional;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\fillpdf\Entity\FillPdfForm; use Drupal\fillpdf\Entity\FillPdfForm;
use Drupal\simpletest\ContentTypeCreationTrait;
use Drupal\user\Entity\Role;
use Drupal\Tests\BrowserTestBase; use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\TestFileCreationTrait; use Drupal\Tests\TestFileCreationTrait;
use Drupal\Tests\fillpdf\Traits\TestFillPdfTrait; use Drupal\Tests\fillpdf\Traits\TestFillPdfTrait;
...@@ -14,6 +18,7 @@ use Drupal\Tests\fillpdf\Traits\TestFillPdfTrait; ...@@ -14,6 +18,7 @@ use Drupal\Tests\fillpdf\Traits\TestFillPdfTrait;
*/ */
class AdminIdTest extends BrowserTestBase { class AdminIdTest extends BrowserTestBase {
use ContentTypeCreationTrait;
use TestFileCreationTrait; use TestFileCreationTrait;
use TestFillPdfTrait; use TestFillPdfTrait;
...@@ -62,15 +67,16 @@ class AdminIdTest extends BrowserTestBase { ...@@ -62,15 +67,16 @@ class AdminIdTest extends BrowserTestBase {
public function testOverviewFormLinks() { public function testOverviewFormLinks() {
$this->uploadTestPdf('fillpdf_test_v3.pdf'); $this->uploadTestPdf('fillpdf_test_v3.pdf');
// Set the administrative title. // Set the administrative title and check if it has been successfully set.
$admin_title = 'Example form'; $admin_title = 'Example form';
$this->drupalPostForm(NULL, ['admin_title[0][value]' => $admin_title], 'Save'); $this->drupalPostForm(NULL, ['admin_title[0][value]' => $admin_title], 'Save');
$this->assertSession()->statusCodeEquals(200); $this->assertSession()->pageTextContains("FillPDF Form $admin_title has been updated.");
$this->assertSession()->fieldValueEquals('edit-admin-title-0-value', $admin_title);
// Go back to the overview page. // Go back to the overview page.
$this->drupalGet('admin/structure/fillpdf'); $this->drupalGet('admin/structure/fillpdf');
// Check if the administrative title has been set and appears in the view. // Check if the administrative title appears in the view.
$this->assertSession()->pageTextContains($admin_title); $this->assertSession()->pageTextContains($admin_title);
// Check hook_entity_operation_alter(). Only the altered link should exist. // Check hook_entity_operation_alter(). Only the altered link should exist.
...@@ -105,4 +111,61 @@ class AdminIdTest extends BrowserTestBase { ...@@ -105,4 +111,61 @@ 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 an entity reference to a FillPdfForm.
*/
public function testEntityReference() {
// Create new FillPdfForm.
$this->uploadTestPdf('fillpdf_test_v3.pdf');
$fid = $this->getLatestFillPdfForm();
// Set the administrative title.
$admin_title = 'Example form';
$this->drupalPostForm("admin/structure/fillpdf/{$fid}", ['admin_title[0][value]' => $admin_title], 'Save');
$this->assertSession()->statusCodeEquals(200);
// Create host content type.
$bundle = $this->createContentType();
$bundle_id = $bundle->id();
// Create an entity reference to our FillPdfForm.
$storage = FieldStorageConfig::create([
'field_name' => 'field_fillpdf_form',
'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')
->load("node.{$bundle_id}.default")
->setComponent('field_fillpdf_form', [
'type' => 'options_select',
])
->save();
// 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, ["create $bundle_id content"]);
// On a new node, check if the select contains an option with the
// administrative title we have set.
$this->drupalGet("/node/add/{$bundle_id}");
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->optionExists('edit-field-fillpdf-form', $admin_title);
}
} }
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