如何在Drupal 8中将状态为1的上载文件保存在file_managed表中?
每当我上传文件时,该文件就会以状态值0存储在file_managed表中。
我曾经File::load( $form_state->getValue('image'))
加载过该文件。接下来我需要做什么?
在Drupal 7中,我将使用$file->status = FILE_STATUS_PERMANENT
。Drupal 8的等效代码是什么?
class AddBannerForm extends FormBase {
public function getFormId()
{
return 'add_banner_form';
}
public function buildForm(array $form, FormStateInterface $form_state)
{
$form['image'] = array(
'#type' => 'managed_file',
'#title' => t('Choose Image File'),
'#upload_location' => 'public://images/',
'#default_value' => '',
'#description' => t('Specify an image(s) to display.'),
'#states' => array(
'visible' => array(
':input[name="image_type"]' => array('value' => t('Upload New Image(s)')),
),
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save image'),
);
return $form;
}
public function validateForm(array &$form, FormStateInterface $form_state)
{
File::load( $form_state->getValue('image') );
}
public function submitForm(array &$form, FormStateInterface $form_state)
{
}
}