Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support for file field Drupalgap #491

Open
geYdes opened this issue Mar 1, 2015 · 21 comments
Open

Implement support for file field Drupalgap #491

geYdes opened this issue Mar 1, 2015 · 21 comments

Comments

@geYdes
Copy link

geYdes commented Mar 1, 2015

Hi @signalpoint ,

I'm trying to create a module that supports the implementation of File module Drupal.

This is the code used, code that doesn't work.

function file_field_formatter_view(entity_type, entity, field, instance, langcode, items, display) {
  try {

    // Use this hook to render a field's content on an entity. Use dpm() to
    // inspect the incoming arguments. The arguments contain field display
    // settings from Drupal.

    /*dpm(entity_type);
    dpm(entity);
    dpm(field);
    dpm(instance);
    dpm(langcode);
    dpm(items);
    dpm(display);*/

    // Iterate over each item, and place a widget onto the render array.
    var content = {};
    $.each(items, function(delta, item) {
        content[delta] = {
          markup: 'empty($item['uri']) ? '' : file_create_url($item['uri'])'
        };
    });
    return content;
  }
  catch (error) { console.log('file_field_formatter_view - ' + error); }
}

/**
 * Implements hook_field_widget_form().
 * @param {Object} form
 * @param {Object} form_state
 * @param {Object} field
 * @param {Object} instance
 * @param {String} langcode
 * @param {Object} items
 * @param {Number} delta
 * @param {Object} element
 */
function file_field_widget_form(form, form_state, field, instance, langcode, items, delta, element) {
  try {
    // Use this hook to provide field widgets for form element items. This hook
    // is called for each delta value on the field. Make modifications to the
    // items collection using the provided delta value. The object contained
    // within is a standard DrupalGap Forms API object, so you may assemble the
    // field (and any children widgets) as needed.

    // Very simple example, make the widget for the field a text field.
    items[delta].type = 'file';
  }
  catch (error) { console.log('file_field_widget_form - ' + error); }
}

/**
 * Called after a form element is assembled. Use it to alter a form element.
 */
//function hook_form_element_alter(form, element, variables) { }

/**
 * Called after drupalgap_entity_render_field() assembles the field content
 * string. Use this to make modifications to the HTML output of the entity's
 * field before it is displayed. The field content will be inside of
 * reference.content, so to make modifications, change reference.content. For
 * more info: http://stackoverflow.com/questions/518000/is-javascript-a-pass-by-reference-or-pass-by-value-language
 */
function file_entity_post_render_field(entity, field_name, field, reference) {
  if (field_name == 'field_documento') {
    reference.content += '<h2>' + entity.title + '</h2>';
  }
}

Any help please?

Thanks.

@signalpoint
Copy link
Owner

Use item instead of $item.

@geYdes
Copy link
Author

geYdes commented Mar 3, 2015

No, @signalpoint , continues error loading the module.

@signalpoint
Copy link
Owner

@geYdes If it can't load the module, that means you have a syntax error in your code. For example, the following line has syntax errors all over the place:

markup: 'empty($item['uri']) ? '' : file_create_url($item['uri'])'

@clivesj
Copy link

clivesj commented Mar 7, 2015

@geYdes , Did you get it working. If not you want me to help out? I need this too.

@geYdes
Copy link
Author

geYdes commented Mar 11, 2015

No @clivesj , I don't find the way to solve it.

Any help will be good...

@signalpoint
Copy link
Owner

FYI, the code being developed here should live in this (empty) file in DrupalGap core (instead of in a contrib module): https://github.com/signalpoint/DrupalGap/blob/7.x-1.x/src/modules/file/file.js

Please make a fork of DrupalGap and paste the code above into it, fix any syntax errors, and that should be good progress. We can then look to someone submitting a pull request and getting this into core, thanks!

@clivesj
Copy link

clivesj commented Apr 3, 2015

I have added the code to src/modules/file/file.js but DrpalGap is not finding the function:

WARNING *** CLIVESJ DEBUG ***: _drupalgap_form_render_element() - file_field_widget_form() does not exist for the "file" form element!

So drupalgap_function_exists() doesn't return valid. Any suggestions? Thanks

@signalpoint
Copy link
Owner

@clivesj Did you use the makefile to recompile the bin/drupalgap.js file? Is your index.html file pointing to bin/drupalgap.js?

@clivesj
Copy link

clivesj commented Apr 3, 2015

Ah shoot, I am just noticing a comment about this in drupal.js.

That should be it. Thanks!

Van: Tyler Frankenstein [mailto:[email protected]]
Verzonden: Friday, 3 April, 2015 18:17
Aan: signalpoint/DrupalGap
CC: clivesj
Onderwerp: Re: [DrupalGap] Implement support for file field Drupalgap (#491)

@clivesj https://github.com/clivesj Did you use the makefile to recompile the bin/drupalgap.js file? Is your index.html file pointing to bin/drupalgap.js?


Reply to this email directly or view it on GitHub #491 (comment) . https://github.com/notifications/beacon/ADikM95d51cEl-Qq2Tf4hOOmQkZ40CP8ks5n7rRmgaJpZM4Dnunm.gif

@clivesj
Copy link

clivesj commented Apr 3, 2015

When I edit a node the file upload field widget is displayed neatly. However when I view the node the hook file_field_formatter_view() is not invoked. The file field is populated.

@signalpoint
Copy link
Owner

@clivesj What does the console.log() say? It should say the name of the function that is required to display the field.

@clivesj
Copy link

clivesj commented Apr 3, 2015

I expect a warning message in the console but it is not showing. Also for the other non-implemented fields (date) the warning doesn’t show.

I have been trying a couple of things… I will re-install the SDK tomorrow, maybe I broke something. I am not gona bother you too much, but you prefer to communicate this way or do want me to go on IRC?

Van: Tyler Frankenstein [mailto:[email protected]]
Verzonden: Friday, 3 April, 2015 22:20
Aan: signalpoint/DrupalGap
CC: clivesj
Onderwerp: Re: [DrupalGap] Implement support for file field Drupalgap (#491)

@clivesj https://github.com/clivesj What does the console.log() say? It should say the name of the function that is required to display the field.


Reply to this email directly or view it on GitHub #491 (comment) . https://github.com/notifications/beacon/ADikM_VQPkSp7uTsXGQmH-oTu5PV_kVmks5n7u16gaJpZM4Dnunm.gif

@lsancheztapia
Copy link

@clivesj can I get your last implementation of file.js ? , because I also need that module.

@clivesj
Copy link

clivesj commented May 14, 2015

hello, you can get it on
https://github.com/clivesj/DrupalGap Under src/modules/file
still need some testing but it basically works. Please raise issues as you find them.

@signalpoint
Copy link
Owner

@lsancheztapia
Copy link

I'm writing the code for video recording. I'm thinking to use standard Drupal file field, but that file is used to upload any kind of file like .mp3, .txt, etc.

Any suggestion of how can I see if that file field will be used to upload a video file? so a video-recording link will be added

@signalpoint
Copy link
Owner

@folovr You'll have to dig into the field' andinstanceobjects inhook_field_widget_form()` to detect the allowed file extensions, and then theme the widget accordingly.

@lsancheztapia
Copy link

I just see that image module can't handle multiple files, and if there is other image field a duplicated node will be created.

I think that issue is https://github.com/signalpoint/DrupalGap/blob/7.x-1.x/src/includes/form.submission.inc.js line 102, where form_validation() will be executed after sent every image field.

I think a file upload process should be created to upload all files in a node create form, so file and image uses that.

@signalpoint
Copy link
Owner

@folovr that may be true, please test it. Also, see if this Pull Request helps with your problem as well: https://github.com/signalpoint/DrupalGap/pull/406/files - FYI @chrisschaub

@luxio
Copy link

luxio commented Jul 8, 2016

@lsancheztapia I have managed to support video recording in DrupalGap. If you are still interested, please let me know.

record

@luxio
Copy link

luxio commented Jul 17, 2016

#825

Drupal Gap Video

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants