0

I've the next form.

$form['imagen'] = array(
        '#title' => t('Image'),
        '#type' => 'managed_file',
        '#upload_validators' => array('file_validate_extensions' => array('jpeg jpg png gif')),
        '#upload_location' => 'public://',
        '#progress_indicator' => 'throbber',
        '#status' => FILE_STATUS_PERMANENT,
        '#progress_message' => 'One moment while we save your file...',
    ); 

That generates something like this:

enter image description here

What I need is to give the user the option to see the image that he has upload, and resize the image. The functionality that I need, is the same that the ImageField_crop module gives.

I'm totally lost. I don't know how to add this functionality to the form. It's totally necessary for the project to insert this form in a custom module, because I have a multistep form.

Does anybody know how to do this??

Thank you very much.

3

2 Answers 2

0

Better you can go with implementing the field with "imagefield_crop" module instead of doing customization further.

0

Is it not possible by adding the #widget attribute to the form? Something like:

    $form['imagen'] = array(
    '#title' => t('Image'),
    '#type' => 'managed_file',
    '#upload_validators' => array('file_validate_extensions' => array('jpeg jpg png gif')),
    '#upload_location' => 'public://',
    '#progress_indicator' => 'throbber',
    '#status' => FILE_STATUS_PERMANENT,
    '#progress_message' => 'One moment while we save your file...',
    '#widget' => array(
     'type' => 'imagefield_crop_widget',
  ),
); 
5
  • I've never come across a #widget property, it's not listed in the API so I guess this is something a contrib/custom module provides? Could you give some more information about where this property comes from and how it can be used?
    – Clive
    Commented Oct 6, 2014 at 9:59
  • Field API uses widget, so it might be a good thing to look into it? api.drupal.org/api/drupal/modules!field!field.module/group/…
    – Kevin
    Commented Oct 6, 2014 at 10:48
  • Yep I'm (very) familiar with the field API - can you point me to the documentation for this #widget property? It doesn't occur in the form API docs, the docs you linked to, or the entire Drupal 7 codebase. I'm pretty positive it doesn't exist, but I'm curious as to where you've got the idea that it does from? Have you read something that says this exists or are you just literally guessing?
    – Clive
    Commented Oct 6, 2014 at 10:51
  • Clive, yes it's a guess since field api is using widget on fields. On the link I gave, it states "widget (array)" on the instance. So probably creating a custom field is the best solution for OP's problem?
    – Kevin
    Commented Oct 6, 2014 at 10:58
  • I've found the next definition of field and field instance: link. According to this both have widget option, but the code that kevin has show doesnt't work for me. It doesn't recognize "#widget" option. So, do I need to install any module??
    – more770
    Commented Oct 7, 2014 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.