php 如何在TYPO3 v11中创建表单修整器?

gab6jxml  于 2023-03-21  发布在  PHP
关注(0)|答案(1)|浏览(131)

我正在尝试为我的TYPO 3添加EXT:form的完成器。我没有找到最新的示例。大多数都是关于TYPO 3 v8的。
我用这个“解释”https://docs.typo3.org/c/typo3/cms-form/main/en-us/I/Concepts/Finishers/Index.html#write-a-custom-finisher
这是我的状态:
/Configuration/Finishers/Smtp.yaml

TYPO3:
    CMS:
      Form:
        prototypes:
          standard:
            finishersDefinition:
              SmtpFinisher:
                implementationClassName: 'Vendor\personal\Domain\Finishers\SmtpFinisher'
                options:
                    yourCustomOption: 'Ralf'

/Classes/Domain/Finishers/SmtpFinisher.php

<?php declare(strict_types=1);

  namespace VENDOR\personal\Domain\Finishers;

  use PHPMailer\PHPMailer\PHPMailer;
  use TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher;

  final class SmtpFinisher extends AbstractFinisher
  {

    protected $shortFinisherIdentifier = 'smtp';

    public function executeInternal() : void{
      $senderOptoins = $this->parseOptions("sender");
      $mailer = new PHPMailer();

      $mailer->isSMTP();
      $mailer->SMTPAuth =true;
      $mailer->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;

      $mailer->Port = $senderOptoins["smtpPort"];
      $mailer->Host = $senderOptoins["smtpServer"];

      $mailer->Username = $senderOptoins["username"];
      $mailer->Password = $senderOptoins["password"];

      $mailer->setFrom($senderOptoins["senderAddress"]) ;

      foreach($this->parseOptions("recipents") as $recipent){
        $mailer->addAddress($recipent);
      }

      $mailer->isHTML();
      $mailer->Subject = "Hello, World!";
      $mailer->Body = "Hi Test Email";
      $mailer->AltBody = "Hi Test Email";

      $mailer->Send();
    }
  }

  ?>

/ext_localconf.php

if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('form')) {
      \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScriptSetup(trim('
          module.tx_form {
              settings {
                  yamlConfigurations {
                      311 = EXT:personal/Configuration/Finishers/Smtp.yaml
                  }
              }
          }
          plugin.tx_form {
              settings {
                  yamlConfigurations {                      
                      311 = EXT:personal/Configuration/Finishers/Smtp.yaml
                  }
              }
          }
      '));
  }

但我还没看到我的终结者:

此外,我不知道如何包含php库。我如何将它们“运送”到我的扩展名/TYPO 3?

mv1qrgav

mv1qrgav1#

您必须将新的完成程序包含到选项列表中。请参见此处:
https://docs.typo3.org/c/typo3/cms-form/11.5/en-us/I/Concepts/Finishers/Index.html#add-finisher-to-backend-ui
其次:
为了包含外部自定义PHP库,您可以在扩展中使用vendor文件夹。PHP库应该是具有命名空间的类。
如果您通过composer安装扩展,则还必须在扩展的composer.json中包含PSR4。然后在安装后可以使用类名。
在finisher中,您设置了一个包含类的构造函数(为此,扩展中必须存在service.yaml)。
示例:

- your_extension_key
   - Classes
      - Finishers
        - YourMailFinisher.php
   - Configuration
      - service.yaml
   - Vendor
      - YourPhpLibrary.php
   - composer.json

service.yaml

services:
  _defaults:
    autowire: true
    autoconfigure: true
    public: false

  YourVendor\YourExtensionKey\:
    resource: '../Classes/*'

  YourVendor\YourExtensionKey\Finisher\YourMailFinisher:
    public: true

composer.json

{
    "name": "yourVendor/your-extension-key",
    "type": "typo3-cms-extension",
    "description": "...",
    "authors": [
        {
            "name": "YOU",
            "role": "Developer"
        }
    ],
    "license": "GPL-2.0-or-later",
    "require": {
        "typo3/cms-core": "^11.5"
    },
    "require-dev": {
        "typo3/testing-framework": "^6.9.0"
    },
    "autoload": {
        "psr-4": {
            "YourVendor\\YourExtensionKey\\": "Classes"
        },
        "classmap": [
            "Vendor"
        ]
    },
    "autoload-dev": {},
    "replace": {
        "typo3-ter/your-extension-key": "self.version"
    },
    "extra": {
        "typo3/cms": {
            "extension-key": "your_extension_key"
        }
    }
}

YourMailFinisher.php

<?php
namespace YourVendor\YourExtensionKey\Finishers;

use TYPO3\CMS\Form\Domain\Finishers\AbstractFinisher;

class YourMailFinisher extends AbstractFinisher
{
   protected $yourLibrary;

   public function __construct(\Vendor\PhpLibrary $yourLibrary)
   {
       $this->yourLibrary = $yourLibrary;
   }

   protected function executeInternal()
   {
      // your code - for use Library: $this->yourLibrary->yourFunction()
   }
}

未经测试,只是一个快速的代码片段。

相关问题