If we process form programmly (use $form_state['programmed'] flag) there are no reasons to add triggering element to form_state:

function _form_builder_handle_input_element (form.inc)

  if ($process_input) {
    // Detect if the element triggered the submission via Ajax.
    if (_form_element_triggered_scripted_submission($element, $form_state)) {
      $form_state['triggering_element'] = $element;
    }

    // If the form was submitted by the browser rather than via Ajax, then it
    // can only have been triggered by a button, and we need to determine which
    // button within the constraints of how browsers provide this information.
    if (isset($element['#button_type'])) {
      // All buttons in the form need to be tracked for
      // form_state_values_clean() and for the form_builder() code that handles
      // a form submission containing no button information in $_POST.
      $form_state['buttons'][] = $element;
      if (_form_button_was_clicked($element, $form_state)) {
        $form_state['triggering_element'] = $element;
      }
    }
  }

So when we validate form after programmly processing we have dsm warrning:

Warning : end() expects parameter 1 to be array, null given dans file_managed_file_validate() (ligne 550 dans /home/i20/prj/culturebox/public/modules/file/file.module).

There are string that cause this :

/**
 * An #element_validate callback for the managed_file element.
 */
function file_managed_file_validate(&$element, &$form_state) {
  // If referencing an existing file, only allow if there are existing
  // references. This prevents unmanaged files from being deleted if this
  // item were to be deleted.
  $clicked_button = end($form_state['triggering_element']['#parents']);

Comments

pavel ruban’s picture

Status: Active » Needs review
StatusFileSize
new841 bytes

There are some resolve issue solution needs review

btopro’s picture

Version: 7.18 » 7.27

Just ran in circles tracking this down myself. This is still an issue with 7.27. To confirm OP; this happens when you submit a form using drupal_form_submit() and the form you are submitting has a managed file field in it. In my use case the file is optional and I wasn't submitting a file, causing the error since it is checking to see what button was pressed (which a CLI / function processing the form won't have processed).

Proposed patch passes automated testing and review looks reasonable. Without this patch all drupal_form_submit calls will need to have the following added to avoid the error:

$form_state['triggering_element']['#parents'][0] = 'submit';

Version: 7.27 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.