TestPdfEngine.php in Entity Print 8        
                          
                  
                        
  
  
  
  
  
File
  tests/modules/entity_print_test/src/Plugin/EntityPrint/PdfEngine/TestPdfEngine.php
  
    View source  
  <?php
namespace Drupal\entity_print_test\Plugin\EntityPrint\PdfEngine;
use Drupal\Core\Form\FormStateInterface;
use Drupal\entity_print\PdfEngineException;
use Drupal\entity_print\Plugin\PdfEngineBase;
class TestPdfEngine extends PdfEngineBase {
  
  protected $html;
  
  public function __construct(array $configuration, $plugin_id, $plugin_definition) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
  }
  
  public function send($filename = NULL) {
    
    echo 'Using testpdfengine - ' . $this->configuration['test_engine_suffix'];
    echo $this->html;
    flush();
  }
  
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildConfigurationForm($form, $form_state);
    $form['test_engine_setting'] = [
      '#title' => $this
        ->t('Test setting'),
      '#type' => 'textfield',
      '#default_value' => $this->configuration['test_engine_setting'],
      '#description' => $this
        ->t('Test setting'),
    ];
    $form['test_engine_suffix'] = [
      '#title' => $this
        ->t('Suffix'),
      '#type' => 'textfield',
      '#default_value' => $this->configuration['test_engine_suffix'],
      '#description' => $this
        ->t('Suffix'),
    ];
    return $form;
  }
  
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    $this->configuration['test_engine_setting'] = $form_state
      ->getValue('test_engine_setting');
    $this->configuration['test_engine_suffix'] = $form_state
      ->getValue('test_engine_suffix');
  }
  
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
    if ($form_state
      ->getValue('test_engine_setting') === 'rejected') {
      $form_state
        ->setErrorByName('test_engine_setting', 'Setting has an invalid value');
    }
  }
  
  public function defaultConfiguration() {
    return [
      'test_engine_setting' => '',
      'test_engine_suffix' => '',
    ];
  }
  
  public function getError() {
  }
  
  public function addPage($content) {
    $this->html = $content;
  }
  
  public static function dependenciesAvailable() {
    return TRUE;
  }
}
 
Classes
        
  
  
      
      
         
      
                  | Name   | Description | 
    
    
          
                  | TestPdfEngine | Plugin annotation
@PdfEngine(
  id = "testpdfengine",
  label= @Translation("Test PDF Engine")
) |