简体   繁体   English

如何从 webform 处理程序中的 drupal webform url 字段获取 url

[英]How do i get the url from a drupal webform url field in a webform handler

I created a webform handler and it's creating the node and passing all the content appropriately EXCEPT the url in one of the webform fields (the field 'Apply').我创建了一个 webform 处理程序,它正在创建节点并适当地传递所有内容,除了 webform 字段之一(字段“应用”)中的 url。

Any idea what I am doing wrong?知道我做错了什么吗? Below is the code for the handler.下面是处理程序的代码。

class HRJobWebformHandler extends WebformHandlerBase {

  public function submitForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {

    $values = $webform_submission->getData();

    $pos_org = $values['position'] . "-" . $values['organization'];
    $node_args = [
      'type' => 'job_posting',
      'langcode' => 'en',
      'created' => time(),
      'changed' => time(),
      'uid' => 1,
      'title' => $pos_org,
      'field_salary_information' => $values['salary_information'],
      'field_apply' => [
            'uri' =>$values['apply']
            ],
      'field_more_information' => $values['more_information'],
      'field_position' => $values['position'],
      'field_organization' => $values['organization'],
      'field_area' => $values['area'],
      'field_job' => [
        'value' => $values['job_description'],
        'format' => 'full_html'
      ]
    ];

    $node = Node::create($node_args);
    $node->setPublished(false);
    $node->save();
  }
}

Problem solved: Webform was posting the Apply field data as an array (it's a URL field).问题已解决:Webform 将Apply字段数据作为数组发布(它是一个 URL 字段)。 Code change to UPDATE: Webform post was passing the Apply link as an array.代码更改为 UPDATE:Webform 帖子将Apply链接作为数组传递。 Code changed to:代码更改为:

'uri' =>$values['apply']['url']  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM