You are here

function _button_field_callback_get_entity in Button Field 7

Gets the entity and its type from the form or form state during the ajax callback.

Parameters

array $form: The form to get the entity from.

array $form_state: The current state of the form.

string $field_name: Machine name of the field that triggered the callback.

string $language: The form's language

Return value

array Entity and entity type.

1 call to _button_field_callback_get_entity()
button_field_callback_ajax in ./button_field.module
Callback function for the FAPI ajax framework, used on edit forms.

File

./button_field.module, line 332
Defines a field, widget and formatter for the button field type.

Code

function _button_field_callback_get_entity($form, $form_state, $field_name, $language) {

  // If the field element is present in the form state (which should only occur
  // if the button is on a non-ediatable display) then we can get the entity and
  // its type directly from there. Otherwise, we need to get it from the field
  // on the form.
  if (!empty($form_state['#element'])) {
    $entity_type = $form_state['#element']['#entity_type'];
    $entity = $form_state['#element']['#entity'];
  }
  else {
    $entity_type = $form[$field_name][$language][0]['#entity_type'];
    $entity =& $form[$field_name][$language][0]['#entity'];
  }
  return array(
    $entity_type,
    &$entity,
  );
}