在自定义字段小部件中的formElement中附加库

时间:2017-03-29 10:57:24

标签: drupal-8

大家好我被困在一个地方,我创建了一个自定义字段类型和字段小部件,在我的字段小部件中,我必须调用js作为图像选择按钮被选中。这是我的自定义字段小部件的代码

public function formElement(
FieldItemListInterface $items,
$delta,
Array $element,
Array &$form,
FormStateInterface $formState
) {
$s3FormDetailss = GetSignature::getSignature();// To get the policy

$element['s3_select_image'] = array(
 '#type' => 'managed_file',
 '#title' => t($element['#title']),
 '#description' => t('Upload to s3'),
 '#default_value' => isset($items[$delta]->s3_upload_bucket_name) ?
     $items[$delta]->s3_upload_bucket_name: null,
 $form['#attached']['#library'][]= 's3_file_uploader/s3_file_uploader-s3_file_uploader-styles',
 $form['#attached']['drupalSettings']['s3_file_uploader']['s3_file_uploader-s3_file_uploader-styles']['variable'] = $s3FormDetailss,

);

我想在这里附上图书馆,但我收到了错误 "您不能在#attached中使用#library。"

1 个答案:

答案 0 :(得分:3)

尝试删除#符号: $form['#attached']['library'][]= '';