You are here

function button_field_callback_ajax in Button Field 8

Same name and namespace in other branches
  1. 7 button_field.module \button_field_callback_ajax()

Callback function for the FAPI ajax framework, used on edit forms.

2 string references to 'button_field_callback_ajax'
ButtonFieldBase::formElement in src/Plugin/Field/FieldWidget/ButtonFieldBase.php
@todo Add ajax callback.
ButtonFieldBase::viewElements in src/Plugin/Field/FieldFormatter/ButtonFieldBase.php
Builds a renderable array for a field value.

File

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

Code

function button_field_callback_ajax(&$form, &$form_state) {
  $entity = $form_state
    ->getTriggeringElement()['#entity'];
  $field_name = $form_state
    ->getTriggeringElement()['#field_name'];
  $field = $entity
    ->getFieldDefinition($field_name);
  $event = new ButtonFieldClickedEvent($entity, [
    'field' => $field,
    'entity' => $entity,
  ]);
  $event_dispatcher = \Drupal::service('event_dispatcher');
  $event_dispatcher
    ->dispatch(ButtonFieldClickedEvent::EVENT_NAME, $event);
  return _button_field_ajax_response();
}