You are here

function fillpdf_update_8111 in FillPDF 5.0.x

Same name and namespace in other branches
  1. 8.4 fillpdf.install \fillpdf_update_8111()

Add fields for PDFtk Security.

File

./fillpdf.install, line 224
Install functions for FillPDF.

Code

function fillpdf_update_8111() {
  $pdftk_encryption = BaseFieldDefinition::create('list_string')
    ->setLabel('PDFtk encryption strength')
    ->setDescription("Select the type of PDFtk encryption you'd like to use. You should choose 128-bit unless you know otherwise.")
    ->setCardinality(1)
    ->setSettings([
    'allowed_values_function' => [
      PdftkPdfBackend::class,
      'getEncryptionOptions',
    ],
  ])
    ->setDisplayOptions('form', [
    'type' => 'options_select',
    'weight' => 50,
  ]);
  $permissions = BaseFieldDefinition::create('list_string')
    ->setLabel('User permissions')
    ->setCardinality(-1)
    ->setDescription('Choose the permissions the user should have for the encrypted PDF. If they enter the Owner Password, they will be able to unlock it. <strong>If you do not specify any permissions, then none of these operations will be allowed.</strong>')
    ->setSettings([
    'allowed_values_function' => [
      PdftkPdfBackend::class,
      'getUserPermissionList',
    ],
  ])
    ->setDisplayOptions('form', [
    'type' => 'options_select',
    'weight' => 60,
  ]);
  $owner_password = BaseFieldDefinition::create('string')
    ->setLabel(t('Owner password'))
    ->setDescription(new TranslatableMarkup('Required for encryption. Enter the decryption password for the PDF. This password allows PDF security settings to be changed. If you configure encryption and permissions but leave this blank, then anyone will be able to change the security settings.'))
    ->setDisplayOptions('form', [
    'type' => 'string',
    'weight' => 70,
  ]);
  $user_password = BaseFieldDefinition::create('string')
    ->setLabel(t('Filename pattern'))
    ->setDescription(new TranslatableMarkup('Optional. If you want to restrict the opening of this PDF to those with a password, enter one here.'))
    ->setDisplayOptions('form', [
    'type' => 'string',
    'weight' => 80,
  ]);
  $edum = Drupal::entityDefinitionUpdateManager();
  $edum
    ->installFieldStorageDefinition('pdftk_encryption', 'fillpdf_form', 'fillpdf_form', $pdftk_encryption);
  $edum
    ->installFieldStorageDefinition('permissions', 'fillpdf_form', 'fillpdf_form', $permissions);
  $edum
    ->installFieldStorageDefinition('owner_password', 'fillpdf_form', 'fillpdf_form', $owner_password);
  $edum
    ->installFieldStorageDefinition('user_password', 'fillpdf_form', 'fillpdf_form', $user_password);
}