Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / form / simple.twig
index 63475c80838dc07c419299885d5677e5e02e99ec..396b3e2606f644dad989b1e52dee0544b0bbf4e5 100644 (file)
@@ -2,43 +2,14 @@
 
 namespace Drupal\{{ machine_name }}\Form;
 
-use Drupal\Component\Utility\Unicode;
 use Drupal\Core\Form\FormBase;
 use Drupal\Core\Form\FormStateInterface;
-use Drupal\Core\Logger\LoggerChannelFactoryInterface;
-use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
  * Provides a {{ name }} form.
  */
 class {{ class }} extends FormBase {
 
-  /**
-   * The logger factory.
-   *
-   * @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
-   */
-  protected $logger;
-
-  /**
-   * Constructs a {{ class }} object.
-   *
-   * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory
-   *   A logger instance.
-   */
-  public function __construct(LoggerChannelFactoryInterface $logger_factory) {
-    $this->loggerFactory = $logger_factory;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  public static function create(ContainerInterface $container) {
-    return new static(
-      $container->get('logger.factory')
-    );
-  }
-
   /**
    * {@inheritdoc}
    */
@@ -57,10 +28,12 @@ class {{ class }} extends FormBase {
       '#required' => TRUE,
     ];
 
-    $form['actions'] = ['#type' => 'actions'];
+    $form['actions'] = [
+      '#type' => 'actions',
+    ];
     $form['actions']['submit'] = [
       '#type' => 'submit',
-      '#value' => $this->t('Save'),
+      '#value' => $this->t('Send'),
     ];
 
     return $form;
@@ -70,7 +43,7 @@ class {{ class }} extends FormBase {
    * {@inheritdoc}
    */
   public function validateForm(array &$form, FormStateInterface $form_state) {
-    if (Unicode::strlen($form_state->getValue('message')) < 10) {
+    if (mb_strlen($form_state->getValue('message')) < 10) {
       $form_state->setErrorByName('name', $this->t('Message should be at least 10 characters.'));
     }
   }
@@ -79,11 +52,8 @@ class {{ class }} extends FormBase {
    * {@inheritdoc}
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
-    $this->loggerFactory->get('{{ machine_name }}')->debug(
-      $form_state->getValue('message')
-    );
-    drupal_set_message($this->t('The message has been sent.'));
-    $form_state->setRedirect('system.admin');
+    $this->messenger()->addStatus($this->t('The message has been sent.'));
+    $form_state->setRedirect('<front>');
   }
 
 }