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

Issue #2359213: Fix some coding standard errors.

parent ae66af7a
No related branches found
No related tags found
No related merge requests found
Showing
with 83 additions and 332 deletions
name = FillPDF
description = Allows users to populate PDF forms from submitted node data.
package = Other
core = 7.x
dependencies[] = token
<?php <?php
/**
* @file
* Install functions for FillPDF.
*/
use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\fillpdf\Service\FillPdfAdminFormHelper; use Drupal\fillpdf\Service\FillPdfAdminFormHelper;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/** /**
* @file * @file
* Allows mappings of PDFs to site content * Allows mappings of PDFs to site content.
*/ */
/** /**
...@@ -11,17 +11,15 @@ ...@@ -11,17 +11,15 @@
function fillpdf_help($path, $arg) { function fillpdf_help($path, $arg) {
switch ($path) { switch ($path) {
case 'admin/help#fillpdf': case 'admin/help#fillpdf':
$content = t('See the <a href="!documentation">documentation on drupal.org</a> for a full description of and guide to this module.', array('!documentation' => \Drupal\Core\Url::fromUri('http://drupal.org/documentation/modules/fillpdf'))); $content = t('See the <a href="!documentation">documentation on drupal.org</a> for a full description of and guide to this module.', ['!documentation' => \Drupal\Core\Url::fromUri('http://drupal.org/documentation/modules/fillpdf')]);
return $content; return $content;
break;
case 'admin/structure/fillpdf': case 'admin/structure/fillpdf':
if (\Drupal::moduleHandler()->moduleExists('help')) { if (\Drupal::moduleHandler()->moduleExists('help')) {
return t('See the !link for an explanation on dowloading these forms to PDF', return t('See the !link for an explanation on dowloading these forms to PDF',
array('!link' => \Drupal::l(t('documentation'), \Drupal\Core\Url::fromUri('http://drupal.org/documentation/modules/fillpdf')))); ['!link' => \Drupal::l(t('documentation'), \Drupal\Core\Url::fromUri('http://drupal.org/documentation/modules/fillpdf'))]);
} }
else { else {
return t('Activate the help module if you need an ' . return t('Activate the help module if you need an explanation on downloading these forms to PDF.');
'explanation on downloading these forms to PDF.');
} }
break; break;
} }
......
<?php
/**
* @file fillpdf.rules.inc
*
* Come on, you know what this is for! It's in the name!
* (But if you don't - it's for Rules integration.)
*/
/**
* *************
* *Rules hooks*
* *************
*/
/**
* Implements hook_rules_data_info().
* @todo: Define the fillpdf data structure.
* See http://drupal.org/node/905632
*/
function fillpdf_rules_data_info() {
return array(
'fillpdf' => array(
'label' => t('FillPDF metadata'),
'group' => t('FillPDF'),
'property info' => _fillpdf_rules_metadata_info(),
),
);
}
/**
* Implements hook_rules_event_info().
* @todo: Define the "FillPDF has filled the PDF" event
* @todo: Define the following events:
* - FillPDF is about to prepare PDF-filling data (fillpdf_merge_pre_merge)
* - FillPDF is ready to fill the PDF (fillpdf_merge_fields_alter)
*/
function fillpdf_rules_event_info() {
$defaults = array(
'group' => t('FillPDF'),
'module' => 'fillpdf',
);
return array(
'fillpdf_merge_pre_handle' => $defaults + array(
'label' => t('Filled PDF is about to be handled'),
'variables' => array(
'fillpdf' => array('type' => 'fillpdf', 'label' => 'FillPDF metadata'),
),
)
);;
}
/**
* Implements hook_rules_action_info().
* @todo: Define the following actions:
* - Fill a PDF with data from content
* - Fill a PDF with data from Webform submissions
* - Send PDF to user's browser
* - Generate a FillPDF link (saves new variable - could be useful for e-mail
* templates and such)
*/
function fillpdf_rules_action_info() {
$defaults = array(
'group' => t('FillPDF'),
);
return array(
'fillpdf_load' => $defaults + array(
'label' => t('Load a FillPDF configuration'),
'base' => 'fillpdf_rules_action_load_fillpdf',
'provides' => array(
'fillpdf' => array(
'type' => 'fillpdf',
'label' => t('FillPDF metadata'),
),
),
'parameter' => array(
'fid' => array(
'type' => 'integer',
'label' => t('FillPDF Form ID'),
)
),
),
'fillpdf_merge_webform' => $defaults + array(
'label' => t('Fill a PDF with webform data'),
'base' => 'fillpdf_rules_action_merge_webform',
'description' => t('Populates the PDF with webform data and updates the
Rules variable with all information necessary to handle it.'),
'parameter' => array(
'fillpdf' => array(
'type' => 'fillpdf',
'label' => t('FillPDF metadata'),
),
'webform_nid' => array(
'type' => 'integer',
'label' => t('Webform Node ID'),
'optional' => TRUE,
'description' => t('If you leave this blank, the <em>Default Node ID</em> from the FillPDF configuration will be used.'),
),
'webform_sids' => array(
'type' => 'list<integer>',
'label' => t('Webform Submission ID(s)'),
'optional' => TRUE,
'description' => t('If you leave this blank, the most recent submission will be used. The last ID you specify will be checked first.'),
),
),
),
'fillpdf_handle_default' => $defaults + array(
'label' => t('Perform the default action on the PDF'),
'description' => t('Handle the PDF according to its FillPDF configuration.'),
'base' => 'fillpdf_rules_action_handle_default',
'parameter' => array(
'fillpdf' => array(
'type' => 'fillpdf',
'label' => t('FillPDF metadata'),
)
),
),
'fillpdf_save_to_file' => $defaults + array(
'label' => t('Save PDF to a file'),
'base' => 'fillpdf_rules_action_save_to_file',
'provides' => array(
'fillpdf_saved_file_path' => array(
'type' => 'text',
'label' => t('Path to saved PDF'),
),
),
'parameter' => array(
'fillpdf' => array(
'type' => 'fillpdf',
'label' => t('FillPDF metadata'),
)
),
),
'fillpdf_delete_saved_file' => $defaults + array(
'label' => t('Delete saved PDF'),
'base' => 'fillpdf_rules_action_delete_file',
'parameter' => array(
'filename' => array(
'type' => 'text',
'label' => t('Filename of PDF to delete'),
),
),
)
);
}
/**
* Implements hook_rules_condition_info().
* @todo: Define the following conditions:
* - A node is being filled
* - A Webform is being filled
*/
function fillpdf_rules_condition_info() {
}
/**
* *****************
* *Rules callbacks*
* *****************
*/
// Action callbacks //
function fillpdf_rules_action_load_fillpdf($fid) {
$fillpdf = new stdClass;
$fillpdf->info = fillpdf_load($fid);
return array(
'fillpdf' => $fillpdf,
);
}
/**
* Populates a loaded FillPDF configuration's PDF with data.
*/
function fillpdf_rules_action_merge_webform($fillpdf, $webform_nid = '', $webform_sids = array()) {
$skip_access_check = FALSE;
$flatten = TRUE;
$webforms = array();
foreach ($webform_sids as $sid) {
$webforms[] = array('nid' => $webform_nid,
'sid' => $sid,
);
}
if (empty($webforms) && empty($webform_nid) !== TRUE) {
$webforms[0]['nid'] = $webform_nid;
}
// @todo: Parameterize $skip_access_check and $flatten in Rules.
$fillpdf = fillpdf_merge_pdf($fillpdf->info->fid, NULL, $webforms, NULL, FALSE, $skip_access_check, $flatten, FALSE);
return array('fillpdf' => $fillpdf);
}
/**
* Save the PDF to a file and return the file path.
*/
function fillpdf_rules_action_save_to_file($fillpdf) {
$saved_file_path = fillpdf_save_to_file($fillpdf->info, $fillpdf->data, $fillpdf->token_objects, _fillpdf_process_filename($fillpdf->info->title, $fillpdf->token_objects), FALSE);
return array(
'fillpdf_saved_file_path' => $saved_file_path,
);
}
/**
* Perform the default action on the PDF. This always ends in a drupal_goto() or a drupal_exit().
*/
function fillpdf_rules_action_handle_default($fillpdf) {
fillpdf_merge_handle_pdf($fillpdf->info, $fillpdf->data, $fillpdf->token_objects, 'default');
}
function fillpdf_rules_action_delete_file($filename) {
file_unmanaged_delete($filename);
}
// Condition callbacks //
// Metadata callbacks //
function _fillpdf_rules_metadata_info() {
return array();
}
<?php
/**
* Implements hook_default_rules_configuration().
*/
function fillpdf_default_rules_configuration() {
$default_rules = array();
// Attach the filled PDF to an e-mail.
if (\Drupal::moduleHandler()->moduleExists('mimemail') && \Drupal::moduleHandler()->moduleExists('webform_rules') && \Drupal::moduleHandler()->moduleExists('webform')) {
$default_rules['rules_webform_fillpdf_attachment'] = rules_import('{ "rules_send_webform_submission_confirmation_with_filled_pdf_as_attachment" : {
"LABEL" : "Send Webform submission confirmation e-mail with filled PDF as attachment",
"PLUGIN" : "reaction rule",
"ACTIVE" : false,
"REQUIRES" : [ "rules", "fillpdf", "mimemail", "webform_rules" ],
"ON" : [ "webform_rules_submit" ],
"IF" : [ { "data_is" : { "data" : [ "node:nid" ], "value" : "2" } } ],
"DO" : [
{ "fillpdf_load" : {
"USING" : { "fid" : "6" },
"PROVIDE" : { "fillpdf" : { "fillpdf" : "FillPDF metadata" } }
}
},
{ "fillpdf_merge_webform" : {
"fillpdf" : [ "fillpdf" ],
"webform_nid" : "2",
"webform_sids" : { "value" : [] }
}
},
{ "fillpdf_save_to_file" : {
"USING" : { "fillpdf" : [ "fillpdf" ] },
"PROVIDE" : { "fillpdf_saved_file_path" : { "fillpdf_saved_file_path" : "Path to saved PDF" } }
}
},
{ "mimemail" : {
"to" : [ "site:mail" ],
"subject" : "Copy of completed PDF for your records",
"body" : "Thank you for filling out the form on our website. A copy of your completed PDF is attached.",
"plaintext" : " Thank you for filling out the form on our website. A copy of your completed PDF is attached.",
"attachments" : [ "fillpdf-saved-file-path" ]
}
},
{ "fillpdf_delete_saved_file" : { "filename" : [ "fillpdf-saved-file-path" ] } }
]
}
}');
}
return $default_rules;
}
<?php <?php
/** /**
* @file * @file
* Contains \Drupal\fillpdf\Component\Helper\FillPdfMappingHelper. * Contains \Drupal\fillpdf\Component\Helper\FillPdfMappingHelper.
*/ */
namespace Drupal\fillpdf\Component\Helper; namespace Drupal\fillpdf\Component\Helper;
/**
* Class FillPdfMappingHelper.
*
* @package Drupal\fillpdf\Component\Helper
*/
class FillPdfMappingHelper { class FillPdfMappingHelper {
public static function parseReplacements($replacements_string) { public static function parseReplacements($replacements_string) {
if (empty($replacements_string) !== TRUE) { if (empty($replacements_string) !== TRUE) {
$standardized_replacements = str_replace(array("\r\n", "\r"), "\n", $replacements_string); $standardized_replacements = str_replace([
"\r\n",
"\r",
], "\n", $replacements_string);
$lines = explode("\n", $standardized_replacements); $lines = explode("\n", $standardized_replacements);
$return = array(); $return = [];
foreach ($lines as $replacement) { foreach ($lines as $replacement) {
if (!empty($replacement)) { if (!empty($replacement)) {
$split = explode('|', $replacement); $split = explode('|', $replacement);
...@@ -25,7 +33,7 @@ class FillPdfMappingHelper { ...@@ -25,7 +33,7 @@ class FillPdfMappingHelper {
return $return; return $return;
} }
else { else {
return array(); return [];
} }
} }
......
<?php <?php
/** /**
* @file * @file
* Contains \Drupal\fillpdf\Component\Helper\FillPdfMappingHelperInterface. * Contains \Drupal\fillpdf\Component\Helper\FillPdfMappingHelperInterface.
*/ */
namespace Drupal\fillpdf\Component\Helper; namespace Drupal\fillpdf\Component\Helper;
/**
* Interface FillPdfMappingHelperInterface.
*
* @package Drupal\fillpdf\Component\Helper
*/
interface FillPdfMappingHelperInterface { interface FillPdfMappingHelperInterface {
} }
...@@ -3,10 +3,17 @@ ...@@ -3,10 +3,17 @@
* @file * @file
* Contains \Drupal\fillpdf\Component\Utility\FillPdf. * Contains \Drupal\fillpdf\Component\Utility\FillPdf.
*/ */
namespace Drupal\fillpdf\Component\Utility; namespace Drupal\fillpdf\Component\Utility;
use Drupal\views\Views; use Drupal\views\Views;
use \Symfony\Component\Process\Process; use \Symfony\Component\Process\Process;
/**
* Class FillPdf.
*
* @package Drupal\fillpdf\Component\Utility
*/
class FillPdf { class FillPdf {
public static function checkPdftkPath($pdftk_path = '') { public static function checkPdftkPath($pdftk_path = '') {
......
...@@ -12,10 +12,8 @@ use Drupal\Core\Entity\Annotation\ContentEntityType; ...@@ -12,10 +12,8 @@ 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;
use Drupal\Core\Entity\EntityChangedTrait;
use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\fillpdf\FillPdfFileContextInterface; use Drupal\fillpdf\FillPdfFileContextInterface;
use Drupal\user\UserInterface;
/** /**
* Defines the FillPDF file context entity. * Defines the FillPDF file context entity.
......
...@@ -6,9 +6,7 @@ ...@@ -6,9 +6,7 @@
namespace Drupal\fillpdf; namespace Drupal\fillpdf;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
namespace Drupal\fillpdf; namespace Drupal\fillpdf;
use Drupal\Core\Access\AccessResult; use Drupal\Core\Access\AccessResult;
use Drupal\Core\Access\AccessResultInterface;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url; use Drupal\Core\Url;
......
<?php <?php
/** /**
* @file * @file
* Contains \Drupal\fillpdf\FillPdfAdminFormHelperInterface. * Contains \Drupal\fillpdf\FillPdfAdminFormHelperInterface.
*/ */
namespace Drupal\fillpdf; namespace Drupal\fillpdf;
/**
* Interface FillPdfAdminFormHelperInterface
* @package Drupal\fillpdf
*/
interface FillPdfAdminFormHelperInterface { interface FillPdfAdminFormHelperInterface {
/** /**
* Returns the render array to show a token form with types supported by FillPDF. * Returns the render array to show a token form with types supported by
* FillPDF.
* *
* @return array * @return array
*/ */
......
<?php <?php
/** /**
* @file * @file
* Contains \Drupal\fillpdf\FillPdfBackendManager. * Contains \Drupal\fillpdf\FillPdfBackendManager.
*/ */
namespace Drupal\fillpdf; namespace Drupal\fillpdf;
......
<?php <?php
/** /**
* @file * @file
* Contains \Drupal\fillpdf\FillPdfBackendPluginInterface. * Contains \Drupal\fillpdf\FillPdfBackendPluginInterface.
*/ */
namespace Drupal\fillpdf; namespace Drupal\fillpdf;
...@@ -35,7 +35,7 @@ interface FillPdfBackendPluginInterface { ...@@ -35,7 +35,7 @@ interface FillPdfBackendPluginInterface {
* @param array $field_mapping An array of fields mapping PDF field keys to the * @param array $field_mapping An array of fields mapping PDF field keys to the
* values with which they should be replaced. Example array: * values with which they should be replaced. Example array:
* *
* @code * @code
* array( * array(
* 'values' => array( * 'values' => array(
* 'Field 1' => 'value', * 'Field 1' => 'value',
...@@ -48,7 +48,7 @@ interface FillPdfBackendPluginInterface { ...@@ -48,7 +48,7 @@ interface FillPdfBackendPluginInterface {
* ), * ),
* ), * ),
* ) * )
* @endcode * @endcode
* @param array $context @todo: Define * @param array $context @todo: Define
* @return string The raw file contents of the new PDF; the caller has to * @return string The raw file contents of the new PDF; the caller has to
* handle saving or serving the file accordingly. * handle saving or serving the file accordingly.
......
<?php <?php
/** /**
* @file * @file
* Contains \Drupal\fillpdf\FillPdfContextManagerInterface\FillPdfContextManagerInterface. * Contains \Drupal\fillpdf\FillPdfContextManagerInterface\FillPdfContextManagerInterface.
*/ */
namespace Drupal\fillpdf; namespace Drupal\fillpdf;
/** /**
* Load entities from a FillPDF $context.
*
* Provides a common interface for loading and serialization of the $context * Provides a common interface for loading and serialization of the $context
* array returned by FillPdfLinkManipulator::parseRequest(). * array returned by FillPdfLinkManipulator::parseRequest().
* *
......
...@@ -8,9 +8,6 @@ ...@@ -8,9 +8,6 @@
namespace Drupal\fillpdf; namespace Drupal\fillpdf;
use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityChangedInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\user\EntityOwnerInterface;
/** /**
* Provides an interface for defining FillPDF file context entities. * Provides an interface for defining FillPDF file context entities.
......
...@@ -8,12 +8,9 @@ ...@@ -8,12 +8,9 @@
namespace Drupal\fillpdf; namespace Drupal\fillpdf;
use Drupal\Core\Entity\EntityAccessControlHandler; use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityHandlerInterface;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult; use Drupal\Core\Access\AccessResult;
use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Access controller for the FillPDF form entity. * Access controller for the FillPDF form entity.
...@@ -31,10 +28,8 @@ class FillPdfFormAccessControlHandler extends EntityAccessControlHandler { ...@@ -31,10 +28,8 @@ class FillPdfFormAccessControlHandler extends EntityAccessControlHandler {
case 'update': case 'update':
case 'delete': case 'delete':
return AccessResult::allowedIfHasPermission($account, 'administer pdfs'); return AccessResult::allowedIfHasPermission($account, 'administer pdfs');
break;
default: default:
return AccessResult::neutral(); return AccessResult::neutral();
break;
} }
} }
......
<?php <?php
/** /**
* @file * @file
* Contains \Drupal\fillpdf\FillPdfFormFieldInterface. * Contains \Drupal\fillpdf\FillPdfFormFieldInterface.
*/ */
namespace Drupal\fillpdf; namespace Drupal\fillpdf;
use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\ContentEntityInterface;
/**
* Interface FillPdfFormFieldInterface.
*
* @package Drupal\fillpdf
*/
interface FillPdfFormFieldInterface extends ContentEntityInterface { interface FillPdfFormFieldInterface extends ContentEntityInterface {
} }
<?php <?php
/** /**
* @file * @file
* Contains \Drupal\fillpdf\FillPdfFormFieldViewsData. * Contains \Drupal\fillpdf\FillPdfFormFieldViewsData.
*/ */
namespace Drupal\fillpdf; namespace Drupal\fillpdf;
use Drupal\views\EntityViewsData; use Drupal\views\EntityViewsData;
/**
* Class FillPdfFormFieldViewsData.
*
* @package Drupal\fillpdf
*/
class FillPdfFormFieldViewsData extends EntityViewsData { class FillPdfFormFieldViewsData extends EntityViewsData {
/** /**
......
<?php <?php
/** /**
* @file * @file
* Contains Drupal\fillpdf\FillPdfFormInterface. * Contains Drupal\fillpdf\FillPdfFormInterface.
*/ */
namespace Drupal\fillpdf; namespace Drupal\fillpdf;
use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\user\EntityOwnerInterface;
/**
* Interface FillPdfFormInterface.
* @package Drupal\fillpdf
*/
interface FillPdfFormInterface extends ContentEntityInterface { interface FillPdfFormInterface extends ContentEntityInterface {
// @todo: Add functions that must be implemented to interface once I know what they are.
} }
\ No newline at end of file
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