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

Issue #2359213: Add FillPdfFileContext entity.

This is the same concept as the fillpdf_file_context table in D7. It
lets the module
store generation info for generated PDFs so that private storage access
checking
can work properly. I'll be simplifying this a lot in D8 and simply
storing a
URL that I can parse to get the entities whose access needs to be
checked. And
I might backport that to D7; it's much simpler.
parent 316ef1e8
No related branches found
No related tags found
No related merge requests found
...@@ -8,4 +8,4 @@ fillpdf.forms_admin: ...@@ -8,4 +8,4 @@ fillpdf.forms_admin:
title: FillPDF title: FillPDF
description: Manage your PDFs description: Manage your PDFs
route_name: fillpdf.forms_admin route_name: fillpdf.forms_admin
parent: system.admin_structure parent: system.admin_structure
\ No newline at end of file
...@@ -8,4 +8,5 @@ publish own pdfs: ...@@ -8,4 +8,5 @@ publish own pdfs:
publish all pdfs: publish all pdfs:
title: 'Publish all PDFs' title: 'Publish all PDFs'
description: 'Allows filling in and downloading PDFs with any site content.' description: 'Allows filling in and downloading PDFs with any site content.'add fillpdf file context entities:
\ No newline at end of file title: 'Create new FillPDF file context entities'
---
fillpdf.settings: fillpdf.settings:
path: '/admin/config/media/fillpdf' path: '/admin/config/media/fillpdf'
defaults: defaults:
_form: '\Drupal\fillpdf\Form\FillPdfSettingsForm' _form: '\Drupal\fillpdf\Form\FillPdfSettingsForm'
_title: 'FillPDF settings' _title: 'FillPDF settings'
requirements: requirements:
# TOOD: Use entity access instead
_permission: 'administer pdfs' _permission: 'administer pdfs'
options: options:
_admin_route: TRUE _admin_route: TRUE
...@@ -14,6 +16,8 @@ fillpdf.forms_admin: ...@@ -14,6 +16,8 @@ fillpdf.forms_admin:
_form: '\Drupal\fillpdf\Form\FillPdfOverviewForm' _form: '\Drupal\fillpdf\Form\FillPdfOverviewForm'
_title: 'FillPDF' _title: 'FillPDF'
requirements: requirements:
# TOOD: Use entity access instead
_permission: 'administer pdfs'
_permission: 'administer pdfs' _permission: 'administer pdfs'
options: options:
_admin_route: TRUE _admin_route: TRUE
...@@ -54,3 +58,11 @@ entity.fillpdf_form_field.edit_form: ...@@ -54,3 +58,11 @@ entity.fillpdf_form_field.edit_form:
_permission: 'administer pdfs' # todo: do we have an administer own pdfs perm? _permission: 'administer pdfs' # todo: do we have an administer own pdfs perm?
options: options:
_admin_route: TRUE _admin_route: TRUE
fillpdf_file_context.settings:
path: 'admin/structure/fillpdf_file_context'
defaults:
_form: '\Drupal\fillpdf\Entity\Form\FillPdfFileContextSettingsForm'
_title: 'FillPDF file context settings'
requirements:
_permission: 'administer fillpdf file context entities'
<?php
/**
* @file
* Contains Drupal\fillpdf\Entity\FillPdfFileContext.
*/
namespace Drupal\fillpdf\Entity;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Entity\Annotation\ContentEntityType;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityChangedTrait;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\fillpdf\FillPdfFileContextInterface;
use Drupal\user\UserInterface;
/**
* Defines the FillPDF file context entity.
*
* @ingroup fillpdf
*
* @ContentEntityType(
* id = "fillpdf_file_context",
* label = @Translation("FillPDF file context"),
* handlers = {
* "views_data" = "Drupal\fillpdf\Entity\FillPdfFileContextViewsData",
*
* "access" = "Drupal\fillpdf\FillPdfFileContextAccessControlHandler",
* },
* base_table = "fillpdf_file_context",
* entity_keys = {
* "id" = "id",
* "label" = "name",
* "uuid" = "uuid"
* },
* )
*/
class FillPdfFileContext extends ContentEntityBase implements FillPdfFileContextInterface {
/**
* {@inheritdoc}
*/
public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
parent::preCreate($storage_controller, $values);
$values += array(
'user_id' => \Drupal::currentUser()->id(),
);
}
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('ID'))
->setDescription(t('The ID of the FillPDF file context entity.'))
->setReadOnly(TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The UUID of the FillPDF file context entity.'))
->setReadOnly(TRUE);
$fields['context'] = BaseFieldDefinition::create('string_long')
->setLabel(t('Generation context'))
->setDescription(t('The normalized FillPDF Link (URL) that was used to generate the PDF.'))
->setRequired(TRUE);
return $fields;
}
}
<?php
/**
* @file
* Contains Drupal\fillpdf\Entity\FillPdfFileContext.
*/
namespace Drupal\fillpdf\Entity;
use Drupal\views\EntityViewsData;
use Drupal\views\EntityViewsDataInterface;
/**
* Provides Views data for FillPDF file context entities.
*/
class FillPdfFileContextViewsData extends EntityViewsData implements EntityViewsDataInterface {
/**
* {@inheritdoc}
*/
public function getViewsData() {
$data = parent::getViewsData();
$data['fillpdf_file_context']['table']['base'] = array(
'field' => 'id',
'title' => $this->t('FillPDF file context'),
'help' => $this->t('The FillPDF file context ID.'),
);
return $data;
}
}
<?php
/**
* @file
* Contains Drupal\fillpdf\FillPdfFileContextAccessControlHandler.
*/
namespace Drupal\fillpdf;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;
/**
* Access controller for the FillPDF file context entity.
*
* @see \Drupal\fillpdf\Entity\FillPdfFileContext.
*/
class FillPdfFileContextAccessControlHandler extends EntityAccessControlHandler {
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
switch ($operation) {
case 'view':
// TODO: allow access if user has permission to entities user used to fill in PDF
// return AccessResult::allowedIfHasPermission($account, 'view fillpdf file context entities');
case 'update':
return AccessResult::allowedIfHasPermission($account, 'edit fillpdf file context entities');
case 'delete':
return AccessResult::allowedIfHasPermission($account, 'delete fillpdf file context entities');
}
return AccessResult::allowed();
}
}
<?php
/**
* @file
* Contains Drupal\fillpdf\FillPdfFileContextInterface.
*/
namespace Drupal\fillpdf;
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.
*
* @ingroup fillpdf
*/
interface FillPdfFileContextInterface extends ContentEntityInterface {
}
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