core/modules/field/field.attach.inc | 47 ++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/core/modules/field/field.attach.inc b/core/modules/field/field.attach.inc index d267546..6d133e6 100644 --- a/core/modules/field/field.attach.inc +++ b/core/modules/field/field.attach.inc @@ -832,16 +832,19 @@ function _field_invoke_formatter_target($display) { * @param $langcode * The language the field values are going to be entered, if no language * is provided the default site language will be used. + * @param array $options + * An associative array of additional options. See field_invoke_method() for + * details. * * @see field_form_get_state() * @see field_form_set_state() */ -function field_attach_form($entity_type, EntityInterface $entity, &$form, &$form_state, $langcode = NULL) { +function field_attach_form($entity_type, EntityInterface $entity, &$form, &$form_state, $langcode = NULL, array $options = array()) { // Set #parents to 'top-level' by default. $form += array('#parents' => array()); // If no language is provided use the default site language. - $options = array('langcode' => field_valid_language($langcode)); + $options['langcode'] = field_valid_language($langcode); $form += (array) field_invoke_method('form', _field_invoke_widget_target(), $entity, $form, $form_state, $options); // Add custom weight handling. @@ -1041,13 +1044,16 @@ function field_attach_load_revision($entity_type, $entities, $options = array()) * If validation errors are found, a FieldValidationException is thrown. The * 'errors' property contains the array of errors, keyed by field name, * language and delta. + * @param array $options + * An associative array of additional options. See field_invoke_method() for + * details. */ -function field_attach_validate($entity_type, $entity) { +function field_attach_validate($entity_type, $entity, array $options = array()) { $errors = array(); // Check generic, field-type-agnostic errors first. - _field_invoke_default('validate', $entity_type, $entity, $errors); + _field_invoke_default('validate', $entity_type, $entity, $errors, $options); // Check field-type specific errors. - _field_invoke('validate', $entity_type, $entity, $errors); + _field_invoke('validate', $entity_type, $entity, $errors, $options); // Let other modules validate the entity. // Avoid module_invoke_all() to let $errors be taken by reference. @@ -1089,11 +1095,14 @@ function field_attach_validate($entity_type, $entity) { * full form structure, or a sub-element of a larger form. * @param $form_state * An associative array containing the current state of the form. + * @param array $options + * An associative array of additional options. See field_invoke_method() for + * details. */ -function field_attach_form_validate($entity_type, EntityInterface $entity, $form, &$form_state) { +function field_attach_form_validate($entity_type, EntityInterface $entity, $form, &$form_state, array $options = array()) { // Perform field_level validation. try { - field_attach_validate($entity_type, $entity); + field_attach_validate($entity_type, $entity, $options); } catch (FieldValidationException $e) { // Pass field-level validation errors back to widgets for accurate error @@ -1105,7 +1114,7 @@ function field_attach_form_validate($entity_type, EntityInterface $entity, $form field_form_set_state($form['#parents'], $field_name, $langcode, $form_state, $field_state); } } - field_invoke_method('flagErrors', _field_invoke_widget_target(), $entity, $form, $form_state); + field_invoke_method('flagErrors', _field_invoke_widget_target(), $entity, $form, $form_state, $options); } } @@ -1126,10 +1135,13 @@ function field_attach_form_validate($entity_type, EntityInterface $entity, $form * full form structure, or a sub-element of a larger form. * @param $form_state * An associative array containing the current state of the form. + * @param array $options + * An associative array of additional options. See field_invoke_method() for + * details. */ -function field_attach_submit($entity_type, EntityInterface $entity, $form, &$form_state) { +function field_attach_submit($entity_type, EntityInterface $entity, $form, &$form_state, array $options = array()) { // Extract field values from submitted values. - field_invoke_method('submit', _field_invoke_widget_target(), $entity, $form, $form_state); + field_invoke_method('submit', _field_invoke_widget_target(), $entity, $form, $form_state, $options); // Let other modules act on submitting the entity. // Avoid module_invoke_all() to let $form_state be taken by reference. @@ -1351,9 +1363,12 @@ function field_attach_delete_revision($entity_type, $entity) { * @param $langcode * (Optional) The language the field values are to be shown in. If no language * is provided the current language is used. + * @param array $options + * An associative array of additional options. See field_invoke_method() for + * details. */ -function field_attach_prepare_view($entity_type, $entities, $view_mode, $langcode = NULL) { - $options = array('langcode' => array()); +function field_attach_prepare_view($entity_type, $entities, $view_mode, $langcode = NULL, array $options = array()) { + $options['langcode'] = array(); // To ensure hooks are only run once per entity, only process items without // the _field_view_prepared flag. @@ -1422,14 +1437,16 @@ function field_attach_prepare_view($entity_type, $entities, $view_mode, $langcod * @param $langcode * The language the field values are to be shown in. If no language is * provided the current language is used. + * @param array $options + * An associative array of additional options. See field_invoke_method() for + * details. * @return * A renderable array for the field values. */ -function field_attach_view($entity_type, EntityInterface $entity, $view_mode, $langcode = NULL) { +function field_attach_view($entity_type, EntityInterface $entity, $view_mode, $langcode = NULL, array $options = array()) { // Determine the actual language code to display for each field, given the // language codes available in the field data. - $display_langcode = field_language($entity_type, $entity, NULL, $langcode); - $options = array('langcode' => $display_langcode); + $options['langcode'] = field_language($entity_type, $entity, NULL, $langcode); // Invoke field_default_view(). $null = NULL;