function dc_ajax_add_cart_form_entity_form_display_edit_form_alter in Commerce Ajax Add to Cart 8
Implements hook_form_FORM_ID_alter() for 'entity_form_display_edit_form'.
Hides irrelevant purchased_entity widgets on the dc_ajax_add_cart order item form display.
File
- ./
dc_ajax_add_cart.module, line 50 - Ajax add to cart module.
Code
function dc_ajax_add_cart_form_entity_form_display_edit_form_alter(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $entity */
$entity = $form_state
->getFormObject()
->getEntity();
if ($form['#entity_type'] == 'commerce_order_item' && $entity
->getMode() == 'dc_ajax_add_cart') {
$options =& $form['fields']['purchased_entity']['plugin']['type']['#options'];
unset($options['commerce_entity_select']);
unset($options['entity_reference_autocomplete_tags']);
unset($options['entity_reference_autocomplete']);
unset($options['inline_entity_form_complex']);
unset($options['options_buttons']);
unset($options['options_select']);
}
}