Skip to content

Commit

Permalink
Issue #1821906 followup by David_Rothstein: Validate that the new $op…
Browse files Browse the repository at this point in the history
…tions parameter in various Field API public API functions is actually an array, to prevent conflicts with contrib modules.
  • Loading branch information
DavidRothstein committed Apr 2, 2013
1 parent 025ad19 commit 9c52b71
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions modules/field/field.attach.inc
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,10 @@ function _field_invoke_get_instances($entity_type, $bundle, $options) {
* @see field_form_set_state()
*/
function field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode = NULL, $options = array()) {
// Validate $options since this is a new parameter added after Drupal 7 was
// released.
$options = is_array($options) ? $options : array();

// Set #parents to 'top-level' by default.
$form += array('#parents' => array());

Expand Down Expand Up @@ -775,6 +779,10 @@ function field_attach_load_revision($entity_type, $entities, $options = array())
* details.
*/
function field_attach_validate($entity_type, $entity, $options = array()) {
// Validate $options since this is a new parameter added after Drupal 7 was
// released.
$options = is_array($options) ? $options : array();

$errors = array();
// Check generic, field-type-agnostic errors first.
$null = NULL;
Expand Down Expand Up @@ -827,6 +835,10 @@ function field_attach_validate($entity_type, $entity, $options = array()) {
* details.
*/
function field_attach_form_validate($entity_type, $entity, $form, &$form_state, $options = array()) {
// Validate $options since this is a new parameter added after Drupal 7 was
// released.
$options = is_array($options) ? $options : array();

// Extract field values from submitted values.
_field_invoke_default('extract_form_values', $entity_type, $entity, $form, $form_state);

Expand Down Expand Up @@ -870,6 +882,10 @@ function field_attach_form_validate($entity_type, $entity, $form, &$form_state,
* details.
*/
function field_attach_submit($entity_type, $entity, $form, &$form_state, $options = array()) {
// Validate $options since this is a new parameter added after Drupal 7 was
// released.
$options = is_array($options) ? $options : array();

// Extract field values from submitted values.
_field_invoke_default('extract_form_values', $entity_type, $entity, $form, $form_state, $options);

Expand Down Expand Up @@ -1109,6 +1125,10 @@ function field_attach_delete_revision($entity_type, $entity) {
* details.
*/
function field_attach_prepare_view($entity_type, $entities, $view_mode, $langcode = NULL, $options = array()) {
// Validate $options since this is a new parameter added after Drupal 7 was
// released.
$options = is_array($options) ? $options : array();

$options['language'] = array();

// To ensure hooks are only run once per entity, only process items without
Expand Down Expand Up @@ -1188,6 +1208,10 @@ function field_attach_prepare_view($entity_type, $entities, $view_mode, $langcod
* A renderable array for the field values.
*/
function field_attach_view($entity_type, $entity, $view_mode, $langcode = NULL, $options = array()) {
// Validate $options since this is a new parameter added after Drupal 7 was
// released.
$options = is_array($options) ? $options : array();

// Determine the actual language to display for each field, given the
// languages available in the field data.
$display_language = field_language($entity_type, $entity, NULL, $langcode);
Expand Down

0 comments on commit 9c52b71

Please sign in to comment.