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

Flesh out FillPdfForm entity forms more.

parent 4fffb861
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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);
}
}
......@@ -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,
),
......
......@@ -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');
}
}
......@@ -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;
}
......
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