public function Image::buildForm in SimpleAds 8
Return ad form to create an ad.
Return value
array form
Overrides SimpleAdsTypeBase::buildForm
File
- src/
Plugin/ SimpleAds/ Type/ Image.php, line 23
Class
- Image
- Image Ad type.
Namespace
Drupal\simpleads\Plugin\SimpleAds\TypeCode
public function buildForm(array $form, FormStateInterface $form_state, $type = NULL, $id = NULL) {
$ad = (new Ads())
->setId($id)
->load();
$options = $ad
->getOptions(TRUE);
$form['image'] = [
'#title' => $this
->t('Advertisement Creative'),
'#type' => 'managed_file',
'#description' => $this
->t('Please upload advertisement image. Allowed extensions: gif png jpg jpeg'),
'#upload_location' => 'public://simpleads/image/',
'#required' => TRUE,
'#multiple' => FALSE,
'#upload_validators' => [
'file_validate_extensions' => [
'gif png jpg jpeg',
],
],
'#default_value' => !empty($options['fid']) ? [
$options['fid'],
] : '',
];
return $form;
}