Breaks when custom #attributes are specified

Created on 31 May 2017, over 7 years ago
Updated 15 May 2024, 9 months ago

This one got me for a bit.

plupload_element_info() specifies:

  $types = array();
  $module_path = drupal_get_path('module', 'plupload');
  $types['plupload'] = array(
    '#input' => TRUE,
    '#attributes' => array('class' => array('plupload-element')),
    // @todo
    // '#element_validate' => array('file_managed_file_validate'),
    '#theme_wrappers' => array('form_element'),
    '#theme' => 'container',
    '#value_callback' => 'plupload_element_value',
    '#attached' => array(
      'library' => array(array('plupload', 'plupload')),
      'js' => array($module_path . '/plupload.js'),
      'css' => array($module_path . '/plupload.css'),
    ),
    '#process' => array('plupload_element_process'),
    '#element_validate' => array('plupload_element_validate'),
    '#pre_render' => array('plupload_element_pre_render'),
  );
  return $types;

Note the #attributes key.

If the implementation ALSO specifies that key, e.g.:

          // Upload section.
          "upload" => array(
            '#type' => 'plupload',
            '#title' => t('Add Documents'),
            '#description' => t('Drag and drop files here'),
            '#plupload_settings' => array(
              'runtimes' => 'html5',
              'chunk_size' => '1mb',
            ),
            '#attributes' => array(
              'class' => array("js-my-class"),
            ),
          ),

then the JavaScript won't be able to find the form elements and will fail.

Workaround is easy β€” manually include the plupload-element class:

  '#attributes' => array('class' => array('js-my-class', 'pl-upload-element')),

But it would be nice if one of the element processing hooks took care of this, as most others do.

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡³πŸ‡΄Norway wizonesolutions Norway

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024