You are here

function hook_commerce_inline_form_alter in Commerce Core 8.2

Perform alterations before an inline form is rendered.

In addition to hook_commerce_inline_form_alter(), which is called for all inline forms, there is also hook_commerce_inline_form_PLUGIN_ID_alter() which allows targeting an inline form via plugin ID.

Generic alter hooks are called before the plugin-specific alter hooks.

Parameters

array $inline_form: The inline form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

array $complete_form: The complete form structure.

See also

hook_commerce_inline_form_PLUGIN_ID_alter()

File

./commerce.api.php, line 33
Hooks provided by the Commerce module.

Code

function hook_commerce_inline_form_alter(array &$inline_form, \Drupal\Core\Form\FormStateInterface $form_state, array &$complete_form) {

  /** @var \Drupal\commerce\Plugin\Commerce\InlineForm\InlineFormInterface $plugin */
  $plugin = $inline_form['#inline_form'];
  if ($plugin
    ->getPluginId() == 'customer_profile') {
    if ($inline_form['#profile_scope'] == 'billing' && !isset($inline_form['rendered'])) {

      // Modify the billing profile when in "form" mode.
      $inline_form['address']['widget'][0]['#type'] = 'fieldset';

      // Individual address elements (e.g. "address_line1") can only
      // be accessed from an #after_build callback.
      $inline_form['address']['widget'][0]['address']['#after_build'][] = 'your_callback';
    }
  }
}