I'm having 1 field in a taxonomy = 'features' of type image. Image storage location is set to s3.
I have written a
hook_form_alter for form_id = article (article is the content type) where I have created an image field like:
$form['image_dir'] = [ '#type' => 'managed_file', '#upload_location' => 's3://s3-bucket', '#multiple' => FALSE, '#description' => t('Allowed extensions: gif png jpg jpeg'), '#upload_validators' => [ 'file_validate_is_image' => array(), 'file_validate_extensions' => array('gif png jpg jpeg'), 'file_validate_size' => array(25600000) ], ];
Now in my form submission, I'm trying to save/map this image into my term image field (
field_vocab_image) . For this, I'm trying something like:
$term = Term::create([ 'name' => $term_name, 'vid' => 'my_vocab_name', 'field_vocab_image' => $img, ]); $inserted = $term->save();
$img = $form_state->getvalues()['image_dir']; this image is coming from the custom field created in
Above code is successfully saving term name but when I go to edit term , image field is empty. Image is not getting mapped.