Skip to content
Snippets Groups Projects
Commit 4fffb861 authored by Kevin Kaland's avatar Kevin Kaland
Browse files

Use entity form for FillPdfForm.

parent 37cb0cae
No related branches found
No related tags found
No related merge requests found
...@@ -24,3 +24,13 @@ fillpdf.populate_pdf: ...@@ -24,3 +24,13 @@ fillpdf.populate_pdf:
_controller: '\Drupal\fillpdf\Controller\HandlePdfController::populatePdf' _controller: '\Drupal\fillpdf\Controller\HandlePdfController::populatePdf'
requirements: requirements:
_custom_access: '\Drupal\fillpdf\FillPdfAccessController::checkLink' _custom_access: '\Drupal\fillpdf\FillPdfAccessController::checkLink'
entity.fillpdf_form.edit_form:
path: '/admin/structure/fillpdf/{fillpdf_form}'
defaults:
_entity_form: fillpdf_form.edit
_title: 'Edit FillPDF form'
requirements:
_permission: 'administer pdfs' # todo: do we have an administer own pdfs perm?
options:
_admin_route: TRUE
...@@ -8,6 +8,7 @@ namespace Drupal\fillpdf\Entity; ...@@ -8,6 +8,7 @@ namespace Drupal\fillpdf\Entity;
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;
use Drupal\Core\Url;
use Drupal\fillpdf\FillPdfFormInterface; use Drupal\fillpdf\FillPdfFormInterface;
/** /**
...@@ -18,6 +19,10 @@ use Drupal\fillpdf\FillPdfFormInterface; ...@@ -18,6 +19,10 @@ use Drupal\fillpdf\FillPdfFormInterface;
* label = @Translation("FillPDF form"), * label = @Translation("FillPDF form"),
* handlers = { * handlers = {
* "views_data" = "Drupal\fillpdf\FillPdfFormViewsData", * "views_data" = "Drupal\fillpdf\FillPdfFormViewsData",
* "form" = {
* "edit" = "Drupal\fillpdf\Form\FillPdfFormForm",
* "delete" = "Drupal\fillpdf\Form\FillPdfFormDeleteForm",
* },
* }, * },
* admin_permission = "administer pdfs", * admin_permission = "administer pdfs",
* base_table = "fillpdf_forms", * base_table = "fillpdf_forms",
...@@ -47,31 +52,67 @@ class FillPdfForm extends ContentEntityBase implements FillPdfFormInterface { ...@@ -47,31 +52,67 @@ class FillPdfForm extends ContentEntityBase implements FillPdfFormInterface {
->setDescription(t('The UUID of the FillPdfForm entity.')) ->setDescription(t('The UUID of the FillPdfForm entity.'))
->setReadOnly(TRUE); ->setReadOnly(TRUE);
$fields['title'] = BaseFieldDefinition::create('string')
->setLabel(t('Filename pattern'))
->setDescription(t('The pattern to use for serving populated PDF files.'));
$fields['file'] = BaseFieldDefinition::create('entity_reference') $fields['file'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('The associated managed file.')) ->setLabel(t('The associated managed file.'))
->setDescription(t('The associated managed file.')) ->setDescription(t('The associated managed file.'))
->setSetting('target_type', 'file'); ->setSetting('target_type', 'file');
// /** @var UrlGeneratorInterface $url_generator */
// $url_generator = \Drupal::service('url_generator');
// @todo: Figure out how to do this the right way...I get a router rebuild error if I use $url_generator->generateFromRoute()
$overview_url = Url::fromUri('base://admin/structure/fillpdf')->toString();
// @todo: what is wrong with the below?
$fields['admin_title'] = BaseFieldDefinition::create('string')
->setLabel(t('Administrative description'))
->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.', array('@overview_url' => $overview_url)))
->setDisplayOptions('form', array(
'type' => 'string',
'weight' => 0,
));
$fields['title'] = BaseFieldDefinition::create('string')
->setLabel(t('Filename pattern'))
->setDescription(t('Enter a title for this mapping configuration. This will be used for deciding the filename of your PDF. <strong>This field supports tokens.</strong>'))
->setDisplayOptions('form', array(
'type' => 'string',
'weight' => 1,
));
// @todo: Revisit this...I would probably need to store the entity and bundle types as well. // @todo: Revisit this...I would probably need to store the entity and bundle types as well.
// $fields['default_entity_id'] = BaseFieldDefinition::create('integer') // $fields['default_entity_id'] = BaseFieldDefinition::create('integer')
// ->setLabel(t('Default entity ID')) // ->setLabel(t('Default entity ID'))
// ->setDescription(t('The default entity ID to be filled from this FillPDF Form.')); // ->setDescription(t('The default entity ID to be filled from this FillPDF Form.'));
$fields['destination_path'] = BaseFieldDefinition::create('link') // @todo: set display options on this
->setLabel(t('Destination file path for saving')) $fields['destination_path'] = BaseFieldDefinition::create('string')
->setDescription(t('Subfolder in which to save the generated PDF.')); ->setLabel(t('Where to save generated PDFs'))
->setDescription(t("<p>By default, filled PDFs are not saved to disk; they are simply sent
directly to the browser for download. Enter a path here to change this behavior (tokens allowed).
<strong>Warning! Unless you include the &download=1 flag in the FillPDF URL, PDFs will only
be saved to disk <em>and won't</em> be sent to the browser as well.</strong></p><p>The path
you specify must be in one of the following two formats:<br />
<ul>
<li><em>path/to/directory</em> (path will be treated as relative to
your <em>files</em> directory)</li>
<li><em>/absolute/path/to/directory</em> (path will be treated as relative to your entire
filesystem)</li>
</ul>
Note that, in both cases, you are responsible for ensuring that the user under which PHP is running can write to this path. Do not include a trailing slash.</p>"))
->setDisplayOptions('form', array(
'type' => 'string',
'weight' => 3,
));
$fields['destination_redirect'] = BaseFieldDefinition::create('boolean') $fields['destination_redirect'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Redirect browser to saved PDF')) ->setLabel(t('Redirect browser directly to saved PDF'))
->setDescription(t("Whether to redirect the browser to the newly-saved PDF or not. By default, it's provided as a download. In some browsers, this will show the PDF in the browser windows; others will still prompt the user to download it.")); ->setDescription(t("<strong>This setting is applicable only if <em>Where to save generated PDFs</em> is set.</strong> Instead of redirecting your visitors to the front page, it will redirect them directly to the PDF. However, if you pass Drupal's <em>destination</em> query string parameter, that will override this setting."))
->setDisplayOptions('form', array(
$fields['admin_title'] = BaseFieldDefinition::create('string') 'type' => 'boolean_checkbox',
->setLabel(t('Administrative description')) 'weight' => 4,
->setDescription(t('A description to help administrators more easily distinguish FillPDF Forms.')); 'settings' => array(
'display_label' => TRUE,
),
));
return $fields; return $fields;
} }
......
<?php
/**
* @file
* Contains \Drupal\fillpdf\Form\FillPdfFormDeleteForm.
*/
namespace Drupal\fillpdf\Form;
use Drupal\Core\Entity\ContentEntityConfirmFormBase;
class FillPdfFormDeleteForm extends ContentEntityConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getQuestion() {
// TODO: Implement getQuestion() method.
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
// TODO: Implement getCancelUrl() method.
}
}
<?php
/**
* @file
* Contains \Drupal\fillpdf\Form\FillPdfFormForm.
*/
namespace Drupal\fillpdf\Form;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;
class FillPdfFormForm extends ContentEntityForm {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
/** @var FillPdfForm $entity */
$entity = $this->entity;
return $form;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
$entity = $this->getEntity();
$entity->save();
}
}
...@@ -205,5 +205,7 @@ class FillPdfOverviewForm extends FillPdfAdminFormBase { ...@@ -205,5 +205,7 @@ class FillPdfOverviewForm extends FillPdfAdminFormBase {
if (empty($fields)) { if (empty($fields)) {
drupal_set_message($this->t("No fields detected in PDF. Are you sure it contains editable fields?"), 'warning'); drupal_set_message($this->t("No fields detected in PDF. Are you sure it contains editable fields?"), 'warning');
} }
$form_state->setRedirect('entity.fillpdf_form.edit_form', array('fillpdf_form' => $fillpdf_form->id()));
} }
} }
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