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

Revert "Issue #2539213: Flesh out FillPdfForm more."

This reverts commit fcfa48c0.
parent fcfa48c0
No related branches found
No related tags found
No related merge requests found
......@@ -28,11 +28,9 @@ use Drupal\fillpdf\FillPdfFormInterface;
* base_table = "fillpdf_forms",
* entity_keys = {
* "id" = "fid",
* "label" = "title",
* "uuid" = "uuid",
* },
* links = {
* "delete-form" = "/admin/structure/fillpdf/{fillpdf_form}/delete"
* }
* )
*/
class FillPdfForm extends ContentEntityBase implements FillPdfFormInterface {
......@@ -78,19 +76,10 @@ class FillPdfForm extends ContentEntityBase implements FillPdfFormInterface {
'weight' => 10,
));
// @todo: Validate this with a custom constraint or whatever
$fields['default_entity_type'] = BaseFieldDefinition::create('string')
->setLabel(t('Default entity type'))
->setDescription(t('The type of the below entity ID.'));
// @todo: Validate this with a custom constraint, if possible
$fields['default_entity_id'] = BaseFieldDefinition::create('integer')
->setLabel(t('Default entity ID'))
->setDescription(t('The default entity ID to be filled from this FillPDF Form.'))
->setDisplayOptions('form', array(
'type' => 'string',
'weight' => 15,
));
// @todo: Revisit this...I would probably need to store the entity and bundle types as well.
// $fields['default_entity_id'] = BaseFieldDefinition::create('integer')
// ->setLabel(t('Default entity ID'))
// ->setDescription(t('The default entity ID to be filled from this FillPDF Form.'));
// @todo: set display options on this
$fields['destination_path'] = BaseFieldDefinition::create('string')
......
......@@ -5,7 +5,9 @@
*/
namespace Drupal\fillpdf;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Defines an interface to allow parsing and building FillPDF Links.
......@@ -17,7 +19,7 @@ use Symfony\Component\HttpFoundation\Request;
interface FillPdfLinkManipulatorInterface {
/**
* @param \Symfony\Component\HttpFoundation\Request $request The request containing the query string to parse.
* @param Request $request The request containing the query string to parse.
* @return array
*/
public function parseLink(Request $request);
......@@ -26,7 +28,7 @@ interface FillPdfLinkManipulatorInterface {
* @param array $parameters
* The array of parameters to be converted into a
* URL and query string.
* @return \Drupal\Core\Url
* @return string
*/
public function generateLink(array $parameters);
......
......@@ -7,30 +7,20 @@ namespace Drupal\fillpdf\Form;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\file\Entity\File;
use Drupal\file\FileInterface;
use Drupal\fillpdf\Component\Utility\FillPdf;
use Drupal\fillpdf\FillPdfAdminFormHelperInterface;
use Drupal\fillpdf\FillPdfFormInterface;
use Drupal\fillpdf\FillPdfLinkManipulatorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class FillPdfFormForm extends ContentEntityForm {
protected $adminFormHelper;
protected $linkManipulator;
public function __construct(FillPdfAdminFormHelperInterface $admin_form_helper,
FillPdfLinkManipulatorInterface $link_manipulator) {
public function __construct(FillPdfAdminFormHelperInterface $admin_form_helper) {
$this->adminFormHelper = $admin_form_helper;
$this->linkManipulator = $link_manipulator;
}
public static function create(ContainerInterface $container) {
return new static(
$container->get('fillpdf.admin_form_helper'),
$container->get('fillpdf.link_manipulator')
);
return new static($container->get('fillpdf.admin_form_helper'));
}
/**
......@@ -39,7 +29,7 @@ class FillPdfFormForm extends ContentEntityForm {
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
/** @var FillPdfFormInterface $entity */
/** @var FillPdfForm $entity */
$entity = $this->entity;
$form['tokens'] = array(
......@@ -50,125 +40,20 @@ class FillPdfFormForm extends ContentEntityForm {
'token_tree' => $this->adminFormHelper->getAdminTokenForm(),
);
$entity_types = array();
$entity_type_definitions = $this->entityManager->getDefinitions();
foreach ($entity_type_definitions as $machine_name => $definition) {
$label = $definition->getLabel();
$entity_types[$machine_name] = "$machine_name ($label)";
}
// @todo: Encapsulate this logic into a ::getDefaultEntityType() method on FillPdfForm
$default_entity_type = $entity->get('default_entity_type')->first()->value;
if (empty($default_entity_type)) {
$default_entity_type = 'node';
}
$form['default_entity_type'] = array(
'#type' => 'select',
'#title' => $this->t('Default entity type'),
'#options' => $entity_types,
'#weight' => 12.5,
'#default_value' => $default_entity_type,
);
$fid = $entity->id();
/** @var FileInterface $file_entity */
$file_entity = File::load($entity->get('file')->first()->target_id);
$pdf_info_weight = 0;
$form['pdf_info'] = array(
'#type' => 'fieldset',
'#title' => $this->t('PDF form information'),
'#weight' => $form['default_entity_id']['#weight'] + 1,
'submitted_pdf' => array(
'#type' => 'item',
'#title' => t('Uploaded PDF'),
'#description' => $file_entity->getFileUri(),
'#weight' => $pdf_info_weight++,
),
// @todo: make work
'upload_pdf' => array(
'#type' => 'file',
'#title' => 'Update PDF template',
'#description' => 'Update the PDF template used by this form',
'#weight' => $pdf_info_weight++,
),
'sample_populate' => array(
'#type' => 'item',
'#title' => 'Sample PDF',
'#description' => $this->l($this->t('See which fields are which in this PDF.'),
$this->linkManipulator->generateLink(array(
'fid' => $fid,
'sample' => TRUE,
))) . '<br />' .
$this->t('If you have set a custom path on this PDF, the sample will be saved there silently.'),
'#weight' => $pdf_info_weight++,
),
'form_id' => array(
'#type' => 'item',
'#title' => 'Form Info',
'#description' => "Form ID: [$fid]. Populate this form with entity IDs, such as /fillpdf?fid=$fid&entity_type=node&entity_id=10<br/>",
'#weight' => $pdf_info_weight++,
),
);
if (!empty($entity->get('default_entity_id')->first()->value)) {
$form['pdf_info']['populate_default'] = array(
'#type' => 'item',
'#title' => 'Fill PDF from default node',
'#description' => $this->l($this->t('Download this PDF filled with data from the default entity (@entity_type:@entity).',
array(
'@entity_type', $entity->get('default_entity_type')->first()->value,
'@entity' => $entity->get('default_entity_id')->first()->value)
),
$this->linkManipulator->generateLink(array('fid' => $fid))) . '<br />' .
$this->t('If you have set a custom path on this PDF, the sample will be saved there silently.'),
'#weight' => $form['pdf_info']['form_id']['#weight'] - 0.1,
);
}
$form['additional_settings'] = array(
'#type' => 'details',
'#title' => $this->t('Additional settings'),
'#weight' => $form['pdf_info']['#weight'] + 1,
'#open' => $entity->get('destination_path')->first()->value || $entity->get('destination_redirect')->first()->value,
);
$form['destination_path']['#group'] = 'additional_settings';
$form['destination_redirect']['#group'] = 'additional_settings';
$form['fillpdf_fields'] = FillPdf::embedView('fillpdf_form_fields',
'block_1',
$entity->id());
$form['fillpdf_fields']['#weight'] = 100;
// @todo: Add import/export links once those routes actually exist
return $form;
}
public function validate(array $form, FormStateInterface $form_state) {
// @todo: default_entity_id without a default entity type might not make sense. but maybe defaulting to node is fine for now.
return parent::validate($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
/** @var FillPdfFormInterface $entity */
$entity = $this->getEntity();
$entity->set('default_entity_type', $form_state->getValue('default_entity_type'));
$entity->save();
}
......
......@@ -22,10 +22,17 @@ class FillPdfAdminFormHelper implements FillPdfAdminFormHelperInterface {
* {@inheritdoc}
*/
public function getAdminTokenForm() {
$token_types = array('node', 'webform-tokens', 'submission');
// If not using Webform Rules, then show potential Webform Tokens
// webform:-namespaced tokens.
if ($this->moduleHandler->moduleExists('webform_rules') === FALSE) {
$token_types[] = 'webform';
}
return array(
'#theme' => 'token_tree',
'#token_types' => 'all',
'#global_types' => TRUE,
'#token_types' => $token_types,
'#global_types' => FALSE,
);
}
......
......@@ -6,10 +6,8 @@
namespace Drupal\fillpdf\Service;
use Drupal\Core\Url;
use Drupal\fillpdf\FillPdfLinkManipulatorInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Exception\MissingMandatoryParametersException;
class FillPdfLinkManipulator implements FillPdfLinkManipulatorInterface {
......@@ -50,9 +48,6 @@ class FillPdfLinkManipulator implements FillPdfLinkManipulatorInterface {
$entity_type = $entity_id_parts[0];
$entity_id = $entity_id_parts[1];
}
elseif (!empty($request_context['entity_type'])) {
$entity_type = $request_context['entity_type'];
}
else {
$entity_type = 'node';
}
......@@ -75,28 +70,13 @@ class FillPdfLinkManipulator implements FillPdfLinkManipulatorInterface {
}
/**
* {@inheritdoc}
* @param array $parameters
* The array of parameters to be converted into a
* URL and query string.
* @return string
*/
public function generateLink(array $parameters) {
$query_options = array();
if (!isset($parameters['fid'])) {
throw new \InvalidArgumentException("The $parameters argument must contain the fid key (the FillPdfForm's ID).");
}
$query_options['fid'] = $parameters['fid'];
if (!empty($parameters['sample'])) {
$query_options['sample'] = 1;
}
// TODO: Implement rest of generateLink() method.
$fillpdf_link = Url::fromRoute('fillpdf.populate_pdf',
array(),
array('query' => $query_options));
return $fillpdf_link;
// TODO: Implement generateLink() method.
}
}
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