You are here

final class LegacyProviderPdfBackend in FillPDF 8.4

Legacy provider PdfBackend plugin.

Provides backwards compatibility with legacy FillPdfBackend plugins.

Plugin annotation


@PdfBackend(
  id = "legacy_provider",
)

Hierarchy

Expanded class hierarchy of LegacyProviderPdfBackend

Deprecated

in fillpdf:8.x-4.9 and is removed from fillpdf:8.x-5.0. This is only a BC wrapper. Once you turned your legacy FillPdfBackend plugins into new PdfBackend plugins, this wrapper will not be needed anymore.

See also

https://www.drupal.org/node/3059476

1 file declares its use of LegacyProviderPdfBackend
LegacyBackendTest.php in modules/fillpdf_legacy/tests/Kernel/LegacyBackendTest.php

File

modules/fillpdf_legacy/src/Plugin/PdfBackend/LegacyProviderPdfBackend.php, line 30

Namespace

Drupal\fillpdf_legacy\Plugin\PdfBackend
View source
final class LegacyProviderPdfBackend extends PdfBackendBase implements ContainerFactoryPluginInterface, FillPdfBackendPluginInterface {

  /**
   * The FillPDF legacy backend.
   *
   * @var \Drupal\fillpdf\FillPdfBackendPluginInterface
   */
  private $legacyBackend;

  /**
   * Constructs a LegacyProviderPdfBackend plugin object.
   *
   * @param array $configuration
   *   A configuration array containing information about the plugin instance.
   * @param string $plugin_id
   *   The plugin_id for the plugin instance.
   * @param array $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\fillpdf_legacy\Plugin\FillPdfBackendManager $legacy_backend_manager
   *   The FillPDF legacy backend manager.
   */
  public function __construct(array $configuration, $plugin_id, array $plugin_definition, FillPdfBackendManager $legacy_backend_manager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->legacyBackend = $legacy_backend_manager
      ->createInstance($configuration['backend'], $configuration);
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('plugin.manager.fillpdf_backend'));
  }

  /**
   * {@inheritdoc}
   */
  public function parse(FillPdfFormInterface $fillpdf_form) {
    return $this->legacyBackend
      ->parse($fillpdf_form);
  }

  /**
   * {@inheritdoc}
   */
  public function parseFile(FileInterface $template_file) {
    $fillpdf_form = FillPdfForm::create([
      'file' => $template_file,
    ]);
    return $this
      ->parse($fillpdf_form);
  }

  /**
   * {@inheritdoc}
   */
  public function parseStream($pdf_content) {
    $template_file = file_save_data($pdf_content);
    return $this
      ->parseFile($template_file);
  }

  /**
   * {@inheritdoc}
   */
  public function populateWithFieldData(FillPdfFormInterface $fillpdf_form, array $field_mapping, array $context) {
    return $this->legacyBackend
      ->populateWithFieldData($fillpdf_form, $field_mapping, $context);
  }

  /**
   * {@inheritdoc}
   */
  public function mergeFile(FileInterface $template_file, array $field_mappings, array $context) {
    $legacy_mapping = [];
    foreach ($field_mappings as $pdf_key => $mapping) {
      if ($mapping instanceof TextFieldMapping) {
        $legacy_mapping['fields'][$pdf_key] = (string) $mapping
          ->getData();
      }
      elseif ($mapping instanceof ImageFieldMapping) {
        $uri = (string) $mapping
          ->getUri();
        if ($uri) {
          $legacy_mapping['fields'][$pdf_key] = "{image}{$uri}";
          $image_path_info = pathinfo($uri);
          $legacy_mapping['images'][$pdf_key] = [
            'data' => base64_encode($mapping
              ->getData()),
            'filenamehash' => md5($image_path_info['filename']) . '.' . $image_path_info['extension'],
          ];
        }
      }
    }
    $fillpdf_form = FillPdfForm::create([
      'file' => $template_file,
    ]);
    return $this->legacyBackend
      ->populateWithFieldData($fillpdf_form, $legacy_mapping, $context);
  }

  /**
   * {@inheritdoc}
   */
  public function mergeStream($pdf_content, array $field_mappings, array $context) {
    $template_file = file_save_data($pdf_content);
    return $this
      ->mergeFile($template_file);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
LegacyProviderPdfBackend::$legacyBackend private property The FillPDF legacy backend.
LegacyProviderPdfBackend::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
LegacyProviderPdfBackend::mergeFile public function Populate a PDF file with field data. Overrides PdfBackendInterface::mergeFile
LegacyProviderPdfBackend::mergeStream public function Populate a PDF file with field data. Overrides PdfBackendInterface::mergeStream
LegacyProviderPdfBackend::parse public function Parse a PDF and return a list of its fields. Overrides FillPdfBackendPluginInterface::parse
LegacyProviderPdfBackend::parseFile public function Parse a PDF and return a list of its fields. Overrides PdfBackendInterface::parseFile
LegacyProviderPdfBackend::parseStream public function Parse a PDF and return a list of its fields. Overrides PdfBackendInterface::parseStream
LegacyProviderPdfBackend::populateWithFieldData public function Populate a FillPDF form with field data. Overrides FillPdfBackendPluginInterface::populateWithFieldData
LegacyProviderPdfBackend::__construct public function Constructs a LegacyProviderPdfBackend plugin object. Overrides PluginBase::__construct
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.