drupal - drupal_set_title not working in module form -


i´m trying learn drupal 8. now, i´m "building" forms. created module. inside mymodule\src\form have form1.php

namespace drupal\mymodule\form;  use drupal\core\form\formbase; use drupal\core\form\formstateinterface;  class form1 extends formbase {    public function getformid() {     return 'myform1';   }    public function buildform(array $form, formstateinterface $form_state) {      $form['name'] = array(     '#type' => 'textfield',     '#title' => t('your name'),     '#maxlength' => 30,     );     $form['lastname'] = array(     '#type' => 'textfield',     '#title' => t('your lastname'),     );     $form['submit'] = array(       '#type' => 'submit',       '#value' => t('submit'),     );     return $form;   } 

and works... when want put title page, in case , linked my_module.routing.yml, 127.0.0.1/form1 using

... public function buildform(array $form, formstateinterface $form_state) {  drupal_set_title(t('this title'));      $form['name'] = array(     '#type' => 'textfield',     '#title' => t('your name'),     '#maxlength' => 30,     ); ... 

i receive following error:

error: fatal error: call undefined function drupal\mymodule\form\drupal_set_title() in c:\xampp\htdocs\drupalwebsite\modules\custom\mymodule\src\form\form1.php on line 16

an line 16 is:

drupal_set_title(t('this title')); 

so problem title. tried resolve not. know why? lot

according https://www.drupal.org/node/2067859, drupal_set_title() removed in d8. have tried alternate method that's mentioned in link, this:

$form['#title'] = $this->t('this title');


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -