diff --git a/fillpdf.routing.yml b/fillpdf.routing.yml index 7ab0a85ebba012b4e88348997eb62de9f5d10d24..ec34d9ba0208e3f7279fefceed13cf497763c35a 100644 --- a/fillpdf.routing.yml +++ b/fillpdf.routing.yml @@ -34,3 +34,23 @@ entity.fillpdf_form.edit_form: _permission: 'administer pdfs' # todo: do we have an administer own pdfs perm? options: _admin_route: TRUE + +entity.fillpdf_form.delete_form: + path: '/admin/structure/fillpdf/{fillpdf_form}/delete' + defaults: + _entity_form: fillpdf_form.delete + _title: 'Delete FillPDF form' + requirements: + _permission: 'administer pdfs' # todo: do we have an administer own pdfs perm? + options: + _admin_route: TRUE + +entity.fillpdf_form_field.edit_form: + path: '/admin/structure/fillpdf/{fillpdf_form}/{fillpdf_form_field}' + defaults: + _entity_form: fillpdf_form_field.edit + _title: 'Edit FillPDF form field' + requirements: + _permission: 'administer pdfs' # todo: do we have an administer own pdfs perm? + options: + _admin_route: TRUE diff --git a/src/Component/Utility/FillPdf.php b/src/Component/Utility/FillPdf.php index bf7d5888dea83f0db65f964cbda7d4d19eff699d..1e7fd3c45b756766b21609c4385731d91bae4180 100644 --- a/src/Component/Utility/FillPdf.php +++ b/src/Component/Utility/FillPdf.php @@ -4,6 +4,7 @@ * Contains \Drupal\fillpdf\Component\Utility\Fillpdf. */ namespace Drupal\fillpdf\Component\Utility; +use Drupal\views\Views; use \Symfony\Component\Process\Process; class FillPdf { @@ -21,4 +22,27 @@ class FillPdf { } return TRUE; } -} \ No newline at end of file + + /** + * Correctly embed a View with arguments. views_embed_view() does not + * zero-index. + * + * @param $view_name + * @param string $display_id + */ + public static function embedView($name, $display_id = 'default') { + $args = func_get_args(); + // Remove $name and $display_id from the arguments. + unset($args[0], $args[1]); + + $args = array_values($args); + + $view = Views::getView($name); + if (!$view || !$view->access($display_id)) { + return; + } + + return $view->preview($display_id, $args); + } + +} diff --git a/src/Entity/FillPdfForm.php b/src/Entity/FillPdfForm.php index 3cd5fb7bdb931d8ebaad049855bdd684bcd643f6..00a6f24c0d452b7cca8267dba312c29cb4b2195e 100644 --- a/src/Entity/FillPdfForm.php +++ b/src/Entity/FillPdfForm.php @@ -29,7 +29,8 @@ use Drupal\fillpdf\FillPdfFormInterface; * data_table = "fillpdf_forms_field_data", * entity_keys = { * "id" = "fid", - * "uuid" = "uuid" + * "label" = "title", + * "uuid" = "uuid", * }, * ) */ @@ -57,8 +58,6 @@ class FillPdfForm extends ContentEntityBase implements FillPdfFormInterface { ->setDescription(t('The associated managed 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? @@ -100,7 +99,7 @@ class FillPdfForm extends ContentEntityBase implements FillPdfFormInterface { 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, + 'weight' => 2, )); $fields['destination_redirect'] = BaseFieldDefinition::create('boolean') @@ -108,7 +107,7 @@ class FillPdfForm extends ContentEntityBase implements FillPdfFormInterface { ->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( 'type' => 'boolean_checkbox', - 'weight' => 4, + 'weight' => 3, 'settings' => array( 'display_label' => TRUE, ), diff --git a/src/Form/FillPdfFormDeleteForm.php b/src/Form/FillPdfFormDeleteForm.php index 71b362f9bcd3d9ab3bc2987c79b14a499c2806c4..7aaf6881036e946d9c377ac21544161f11d6ffe1 100644 --- a/src/Form/FillPdfFormDeleteForm.php +++ b/src/Form/FillPdfFormDeleteForm.php @@ -7,21 +7,38 @@ namespace Drupal\fillpdf\Form; use Drupal\Core\Entity\ContentEntityConfirmFormBase; +use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\Core\Url; class FillPdfFormDeleteForm extends ContentEntityConfirmFormBase { + use StringTranslationTrait; + /** * {@inheritdoc} */ public function getQuestion() { - // TODO: Implement getQuestion() method. + return $this->t('Are you sure you want to delete %name?', array('%name' => $this->entity->label())); } /** * {@inheritdoc} */ public function getCancelUrl() { - // TODO: Implement getCancelUrl() method. + return new Url('fillpdf.forms_admin'); + } + + public function getConfirmText() { + return $this->t('Delete'); + } + + public function submitForm(array &$form, FormStateInterface $form_state) { + $this->getEntity()->delete(); + + drupal_set_message($this->t('FillPDF form deleted.')); + + $form_state->setRedirect('fillpdf.forms_admin'); } } diff --git a/src/Form/FillPdfFormForm.php b/src/Form/FillPdfFormForm.php index cb9e6e4ff16444cbe55dd56808ec37902e4592fe..25781765ff0c04c6d88c39e6099fc4f90bf022a1 100644 --- a/src/Form/FillPdfFormForm.php +++ b/src/Form/FillPdfFormForm.php @@ -7,17 +7,24 @@ namespace Drupal\fillpdf\Form; use Drupal\Core\Entity\ContentEntityForm; use Drupal\Core\Form\FormStateInterface; +use Drupal\fillpdf\Component\Utility\FillPdf; class FillPdfFormForm extends ContentEntityForm { /** * {@inheritdoc} */ - public function buildForm(array $form, FormStateInterface $form_state) { - $form = parent::buildForm($form, $form_state); + public function form(array $form, FormStateInterface $form_state) { + $form = parent::form($form, $form_state); /** @var FillPdfForm $entity */ $entity = $this->entity; + $form['fillpdf_fields'] = FillPdf::embedView('fillpdf_form_fields', + 'block_1', + $entity->id()); + + $form['fillpdf_fields']['#weight'] = 100; + return $form; }