Question

I'm developing a custom module with an image field.

Where can I set the following HTML attribute to my custom field?

<input type=file
       accept="image/*"
       capture=environment>

I have created the image field and i'm able to process some OCR with an external library uploading the image but I need to use webcam instead and I can't find the way to set the "capture=enviroment" tag to my input form in the field widget file.

Thank you

Was it helpful?

Solution

Solved with formElement, at least form mobile devices. Just was I was looking for.

  /**
   * {@inheritdoc}
   */
  public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
    $element = parent::formElement($items, $delta, $element, $form, $form_state);

    $element['#accept'] = 'image/*;capture=camera';

    return $element;
  }

Thank you!

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top