Drupal 8中的自定义表单元素未呈现

时间:2018-10-26 16:44:34

标签: custom-controls drupal-8

我试图在Drupal 8中创建一个自定义表单元素。我已经创建了如下模块:

/**
 * @Drupal\Core\Render\Element\FormElement("submit_button")
 */
class SubmitButton extends FormElement {
public function getInfo()
{


    $class = get_class($this);
    return [
       '#input' => FALSE
      ,'#theme' => 'input__submit_button'
      ,'#pre_render' => [
        [$class, 'preRenderSubmitButton'],
      ]
    ];
  }

public static function preRenderSubmitButton($element)
  {
    return $element;
  }
}

并在Submit_button.module中:

function submit_button_theme($existing,$type,$theme,$path)
{
  return [
    'submit_button' => [
       'render element' => 'element'
      ,'template' => 'form-element--submit-button'
    ]
  ];
}

在表单类中,我将调用以下内容:

public function buildForm(array $form, FormStateInterface $form_state)
{

 $form['submit'] = array(
       '#type' => 'submit_button'

      ,'#attributes' => [
       'class' => ['']
      ]
    );
}

但是看起来没有调用getInfo,我有什么遗漏吗?

0 个答案:

没有答案